/** * Created by Syusuke on 2017/3/17. */ $(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(); // 导入原始数据按钮 let rationRepId = 0; $("#showArea").on("click", ".import-source", function () { let id = $(this).data("id"); id = parseInt(id); if (isNaN(id) || id <= 0) { return false; } rationRepId = id; $("#import").modal("show"); }); // 导入内部数据 $("#showArea").on("click", ".import-data", function () { let id = $(this).data("id"); id = parseInt(id); if (isNaN(id) || id <= 0) { return false; } rationRepId = id; $("#import2").modal("show"); }); // 导入原始数据确认 $("#source-import,#data-import").click(function() { const self = $(this); const type = self.is("#source-import") ? 'source_file' : 'import_data'; const dialog = type === 'source_file' ? $("#import") : $("#import2"); try { let formData = new FormData(); let file = $("input[name='"+ type +"']")[0]; if (file.files.length <= 0) { throw '请选择文件!'; } formData.append('file', file.files[0]); // 获取定额库id if (rationRepId <= 0) { return false; } formData.append('rationRepId', rationRepId); formData.append('type', type); $.ajax({ url: '/rationRepository/api/upload', type: 'POST', data: formData, cache: false, contentType: false, processData: false, beforeSend: function() { self.attr('disabled', 'disabled'); self.text('上传中...'); }, success: function(response){ self.removeAttr('disabled'); self.text('确定导入'); if (response.err === 0) { const message = response.msg !== undefined ? response.msg : ''; if (message !== '') { alert(message); } // 成功则关闭窗体 dialog.modal("hide"); } else { const message = response.msg !== undefined ? response.msg : '上传失败!'; alert(message); } }, error: function(){ alert("与服务器通信发生错误"); self.removeAttr('disabled'); self.text('确定导入'); } }); } catch(error) { alert(error); } }); // 导出数据 $("#showArea").on("click", ".export", function () { let id = $(this).data("id"); id = parseInt(id); if (isNaN(id) || id <= 0) { return false; } window.location.href = '/rationRepository/api/export?rationRepId=' + id; }); }); 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]; let compilationName = result.data[i].compilationName; dispNames.push(result.data[i].dispName); $("#showArea").append( "