123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- /**
- * Created by Syusuke on 2017/3/17.
- */
- /*$(function(){
- let libNames = [];
- getCompilationList();
- getRationLibs(libNames);
- })
- function addEvent_Addressdirect(){
- $("tr:gt(0)").each(function() {
- var td, a, tdId = $("td:eq(3)",$(this));
- td = $("td:eq(0)", $(this));
- a = $('a', td);
- a.attr('href', "/rationRepository/ration" + "?repository=" + tdId.text());
- })
- }
- function addEvent_DeleteLib(){
- $("tr:gt(0)").each(function() {
- var td0, a1,td2,a2;
- td2 = $("td:eq(2)", $(this));
- td0 = $("td:eq(0)", $(this));
- a1 = $('a', td0);
- var str = a1.text();
- a2 = $("a:eq(1)",td2);
- a2.click(function(){
- $("#did").val(str)
- })
- // a.attr('href', "/ration/rationLib" + "?rationname=" + a.text());
- })
- }
- function addEvent_EditLib(){
- $("tr:gt(0)").each(function() {
- var td0, a1,td2,a2;
- td2 = $("td:eq(2)", $(this));
- td0 = $("td:eq(0)", $(this));
- a1 = $('a', td0);
- var str = a1.text();
- a2 = $("a:eq(0)",td2);
- a2.click(function(){
- $("#did").val(str)
- })
- })
- }
- $("#deleteLib").click(function(){
- var rationLibName = $("#did").val();
- let lastOperator = userAccount;
- $.ajax({
- type:"POST",
- url:"api/deleteRationLibs",
- dataType:"json",
- data:{"rationName": rationLibName, "lastOperator": lastOperator},
- cache:false,
- timeout:50000,
- success:function(result){
- getRationLibs();
- },
- error:function(iqXHR,textStatus,errorThrown){
- }
- })
- });
- function getCompilationList(){
- $.ajax({
- type: 'post',
- url: 'api/getCompilationList',
- dataType: 'json',
- success: function (result) {
- console.log(result);
- //addoptions
- for(let i = 0; i < result.data.compilation.length; i++){
- let $option = $("<option >"+ result.data.compilation[i].name +"</option>");
- $option.val( result.data.compilation[i]._id);
- $('#compilationSels').append($option);
- }
- //初始工料机库选项
- if(result.data.compilation.length > 0 && result.data.gljLibs.length > 0){
- let compilationId = result.data.compilation[0]._id;
- //console.log(compilationId);
- let gljLibOps = getGljLibOps(compilationId, result.data.gljLibs);
- console.log(gljLibOps);
- for(let i = 0; i < gljLibOps.length; i++){
- let $option = $("<option >"+ gljLibOps[i].dispName +"</option>");
- $option.val(gljLibOps[i].ID);
- $('#gljLibSels').append($option);
- }
- }
- $('#compilationSels').on("change", function () {
- //刷新工料机库选项
- $('#gljLibSels').children().remove();
- let newGljLibOps = getGljLibOps(this.selectedOptions[0].value, result.data.gljLibs);
- for(let i = 0; i < newGljLibOps.length; i++){
- let $option = $("<option >"+ newGljLibOps[i].dispName +"</option>");
- $option.val(newGljLibOps[i].ID);
- $('#gljLibSels').append($option);
- }
- });
- }
- });
- }
- function getGljLibOps(compilationId, gljLibs){
- let rst = [];
- for(let i = 0; i < gljLibs.length; i++){
- if(gljLibs[i]){
- if(compilationId === gljLibs[i].compilationId){
- rst.push(gljLibs[i]);
- }
- }
- }
- return rst;
- }
- function getRationLibs(libNames){
- $.ajax({
- type:"POST",
- url:"api/getRationDisplayNames",
- dataType:"json",
- cache:false,
- timeout:5000,
- success:function(result){
- $("tbody tr").html("");
- for(var i=0;i<result.data.length;i++){
- addLibTag(result.data[i].dispName, result.data[i].ID, result.data[i].createDate);
- storageUtil.setSessionCache("RationGrp","repositoryID_" + result.data[i].ID, result.data[i].dispName);
- libNames.push(result.data[i].dispName);
- }
- console.log(libNames);
- addEvent_Addressdirect();
- addEvent_DeleteLib();
- addEvent_EditLib();
- },
- error:function(iqXHR,textStatus,errorThrown){
- alert("error "+textStatus+" "+errorThrown);
- }
- })
- }
- function addLibTag(string, ID, date){
- var $tr = $('<tr><td><a href="#"></a></td><td></td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td><td style="display:none"></td></tr>')
- var $td0 = $("td:eq(0)",$tr);
- var $td1 = $("td:eq(1)",$tr);
- var $tdId = $("td:eq(3)",$tr);
- var a = $("a",$td0);
- var str = string;
- a.text(str);
- $tdId.text(ID);
- var newDate = date.split(' ')[0];
- $td1.text(newDate);
- $tr.appendTo("tbody");
- }
- function addRationRepository(rationObj, $tdId) {
- $.ajax({
- type:"POST",
- url:"api/addRationRepository",
- dataType:"json",
- data:{"rationRepObj": JSON.stringify(rationObj)},
- cache:false,
- timeout:5000,
- success:function(result){
- $tdId.text(result.data.ID);
- storageUtil.setSessionCache("RationGrp","repositoryID_" + result.data.ID, result.data.dispName);
- addEvent_Addressdirect();
- addEvent_DeleteLib();
- },
- error:function(iqXHR,textStatus,errorThrown){
- alert("error "+textStatus+" "+errorThrown);
- }
- })
- }
- $("#rationAdd").click(function(){
- var $tr = $('<tr><td><a href="#"></a></td><td></td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td><td style="display:none"></td></tr>')
- var $td0 = $("td:eq(0)",$tr);
- var $td1 = $("td:eq(1)",$tr);
- var $tdId = $("td:eq(3)",$tr);
- var a = $("a",$td0);
- var str = $("#addInput").val();
- a.text(str);
- var date = new Date().Format("yyyy-MM-dd");
- $td1.text(date);
- $tr.appendTo("tbody");
- var newRationRepObj = {};
- newRationRepObj.dispName = str;
- newRationRepObj.appType = "建筑";
- newRationRepObj.descr = "";
- newRationRepObj.creator = userAccount;
- newRationRepObj.lastOperator = userAccount;
- addRationRepository(newRationRepObj, $tdId);
- });
- $("#edtOK").click(function(){
- var str = $("#did").val();
- var newStr = $("#inputRation").val();
- let lastOperator = userAccount;
- $.ajax({
- type:"POST",
- url:"api/editRationLibs",
- dataType:"json",
- data:{"rationName": str,"newName":newStr, "lastOperator": lastOperator},
- cache:false,
- timeout:50000,
- success:function(result){
- getRationLibs();
- },
- error:function(jqXHR){
- var err = JSON.parse(jqXHR.responseText);
- alert(err.error);
- }
- })
- });
- autoFlashHeight();*/
- $(function () {
- let dispNameArr;
- getAllRationLib(function (dispNames) {
- dispNameArr = dispNames;
- //添加
- $('#addBtn').click(function () {
- let compilationName = $('#compilationSels option:selected').text();
- let compilationId = $('#compilationSels option:selected').val();
- let gljLibName = $('#gljLibSels option:selected').text();
- let gljLibId = $('#gljLibSels option:selected').val();
- let libName = $('#libNameTxt').val();
- if(libName.trim().length === 0){
- alert('名称不可为空!');
- $('#libNameTxt').val('')
- }
- else if(dispNames.indexOf(libName) !== -1){
- alert('此定额库已存在!');
- $('#libNameTxt').val('')
- }
- else if(compilationName.trim().length === 0){
- alert('编办不可为空!');
- }
- else if(gljLibName.trim().length === 0){
- alert("请选择工料机库!");
- }
- else{
- let newRationLib = {};
- newRationLib.dispName = libName;
- newRationLib.compilationId = compilationId;
- newRationLib.compilationName = compilationName;
- newRationLib.gljLib = gljLibId;
- newRationLib.creator = userAccount;
- newRationLib.appType = "建筑";
- $('#libNameTxt').val('');
- createRationLib(newRationLib, dispNameArr);
- }
- });
- //重命名
- $("#showArea").on("click", "[data-target = '#edit']", function(){
- let renameId = $(this).parent().parent().attr("id");
- $("#renameA").attr("renameId", renameId);
- });
- $("#renameA").click(function(){
- let newName = $("#renameText").val();
- let libId = $(this).attr("renameId");
- let jqSel = "#" + libId + " td:first" + " a";
- let orgName = $(jqSel).text();
- if(newName.trim().length === 0){
- alert("名称不可为空!");
- $("#renameText").val('');
- }
- else if(dispNameArr.indexOf(newName) !== -1){
- alert("该工料机库已存在!");
- $("#renameText").val('');
- }
- else{
- renameRationLib({ID: libId, newName: newName, orgName: orgName}, dispNameArr);
- }
- });
- //删除
- $("#showArea").on("click", "[data-target = '#del']", function(){
- let deleteId = $(this).parent().parent().attr("id");
- $("#deleteA").attr("deleteId", deleteId);
- });
- $("#deleteA").click(function(){
- let deleteId = $(this).attr("deleteId");
- let jqSel = "#" + deleteId + " td:first" + " a";
- let libName = $(jqSel).text();
- removeRationLib({libId: deleteId, libName: libName}, dispNameArr);
- });
- });
- getCompilationList();
- });
- function getAllRationLib(callback){
- $.ajax({
- type: 'post',
- url: 'api/getRationDisplayNames',
- dataType: 'json',
- success: function (result) {
- let dispNames = [];
- if(result.data.length > 0){
- for(let i = 0; i < result.data.length; i++){
- storageUtil.setSessionCache("RationGrp","repositoryID_" + result.data[i].ID, result.data[i].dispName);
- if(result.data[i].gljLib){
- storageUtil.setSessionCache("gljLib","repositoryID_" + result.data[i].ID, result.data[i].gljLib);
- }
- let id = result.data[i].ID;
- let libName = result.data[i].dispName;
- let createDate = result.data[i].createDate.split(' ')[0];
- dispNames.push(result.data[i].dispName);
- $("#showArea").append(
- "<tr id='tempId'>" +
- "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
- "<td>"+createDate+" </td>" +
- "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
- "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
- "<i class='fa fa-remove'></i></a></td></tr>");
- var newHref = "/rationRepository/ration?repository="+id;
- $("#tempId td:first a").attr("href", newHref);
- $("#tempId").attr("id", id);
- }
- }
- callback(dispNames);
- }
- });
- }
- function getCompilationList(){
- $.ajax({
- type: 'post',
- url: 'api/getCompilationList',
- dataType: 'json',
- success: function (result) {
- console.log(result);
- //addoptions
- for(let i = 0; i < result.data.compilation.length; i++){
- let $option = $("<option >"+ result.data.compilation[i].name +"</option>");
- $option.val( result.data.compilation[i]._id);
- $('#compilationSels').append($option);
- }
- //初始工料机库选项
- if(result.data.compilation.length > 0 && result.data.gljLibs.length > 0){
- let compilationId = result.data.compilation[0]._id;
- //console.log(compilationId);
- let gljLibOps = getGljLibOps(compilationId, result.data.gljLibs);
- console.log(gljLibOps);
- for(let i = 0; i < gljLibOps.length; i++){
- let $option = $("<option >"+ gljLibOps[i].dispName +"</option>");
- $option.val(gljLibOps[i].ID);
- $('#gljLibSels').append($option);
- }
- }
- $('#compilationSels').on("change", function () {
- //刷新工料机库选项
- $('#gljLibSels').children().remove();
- let newGljLibOps = getGljLibOps(this.selectedOptions[0].value, result.data.gljLibs);
- for(let i = 0; i < newGljLibOps.length; i++){
- let $option = $("<option >"+ newGljLibOps[i].dispName +"</option>");
- $option.val(newGljLibOps[i].ID);
- $('#gljLibSels').append($option);
- }
- });
- }
- });
- }
- function getGljLibOps(compilationId, gljLibs){
- let rst = [];
- for(let i = 0; i < gljLibs.length; i++){
- if(gljLibs[i]){
- if(compilationId === gljLibs[i].compilationId){
- rst.push(gljLibs[i]);
- }
- }
- }
- return rst;
- }
- function createRationLib(rationObj, dispNamesArr){
- $.ajax({
- type: 'post',
- url: 'api/addRationRepository',
- data: {rationRepObj: JSON.stringify(rationObj)},
- dataType: 'json',
- success: function (result) {
- if(result.data){
- storageUtil.setSessionCache("RationGrp","repositoryID_" + result.data.ID, result.data.dispName);
- if(result.data.gljLib){
- storageUtil.setSessionCache("gljLib","repositoryID_" + result.data.ID, result.data.gljLib);
- }
- let id = result.data.ID;
- let libName = result.data.dispName;
- let createDate = result.data.createDate.split(' ')[0];
- let compilationName = result.data.compilationName;
- dispNamesArr.push(libName);
- $("#showArea").append(
- "<tr id='tempId'>" +
- "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
- "<td>"+createDate+" </td>" +
- "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
- "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
- "<i class='fa fa-remove'></i></a></td></tr>");
- var newHref = "/rationRepository/ration?repository="+id;
- $("#tempId td:first a").attr("href", newHref);
- $("#tempId").attr("id", id);
- }
- $('#cancelBtn').click();
- }
- })
- }
- function renameRationLib(renameObj, dispNames){
- $.ajax({
- type: 'post',
- url: 'api/editRationLibs',
- data: {oprtor: userAccount, renameObj: JSON.stringify(renameObj)},
- dataType: 'json',
- success: function (result) {
- if(!result.error){
- let jqSel = "#" + renameObj.ID + " td:first" + " a";
- $(jqSel).text(renameObj.newName);
- let index = dispNames.indexOf(renameObj.orgName);
- dispNames.splice(index, 1);
- dispNames.splice(index, 0, renameObj.newName);
- }
- $('#editCancelBtn').click();
- $('#renameText').val('');
- }
- })
- }
- function removeRationLib(delObj, dispNames){
- $.ajax({
- type: 'post',
- url: 'api/deleteRationLibs',
- data: {oprtor: userAccount, libId: delObj.libId},
- dataType: 'json',
- success: function (result) {
- if(!result.error){
- var jqSel = "#"+ delObj.libId;
- $(jqSel).remove();
- let index = dispNames.indexOf(delObj.libName);
- dispNames.splice(index, 1);
- $('#delCancelBtn').click();
- }
- }
- })
- }
|