/** * Created by weidy on 2020/2/25. from dengbk * * 物料基本信息 */ layui.define(['layer','element','form','table','upload','platform/basedoc/BdMaterialClassifyExtendAttr'],function(exports){ var Class = function(){ this.MODULE_NAME = "platform/basedoc/BdMaterial"; this.moduleKey = "BdMaterial"; this.id='BdMaterial'; this.sourceData={}; this.columns = []; this.detailcolumns = []; this.backPath = configData.compatibility?path:configData.frameworkPath;//默认流程和项目的路径是一样的 this.accountPath = configData.compatibility?path:configData.invmPath; this.controlSecret = true;//是否控制密级 this.url={ classifyTree:'materialClassifyController/referTree', referClassifyTree: 'materialClassifyController/referTree', controller:'materialController/', dataGrid:'gridMaterial',//列表数据和查询 add:'addMaterial', edit:'editMaterial', del:'delMaterial', upRevision:'upRevisionMaterial', referOldRevision:'referOldRevision', release:'releaseForMaterial', getObjectByOid:'getObjectByOid', accountGrid:'materialAccountController/gridMaterAccountByMaterialOid', referUnit:'unitOfMeasurementController/referGridData', listCheckRule:'bdMaterialCheckController/gridBdMaterialCheck', addSave:'bdMaterialCheckController/addSave', editSave:'bdMaterialCheckController/editSave', deleteData:'bdMaterialCheckController/deleteData', download:'bdMaterialCheckController/downloadImportTemplate', // 导入定检规则下载文件 importData:'bdMaterialCheckController/importData', // 导入定检规则下载文件 exportData:'bdMaterialCheckController/exportData' //导出定检规则 }; this.buttonIconMap = { SEARCH:'layui-icon-refresh-2', SENIORSEARCH:'layui-icon-query', ADD:'layui-icon-add-1', EDIT:'layui-icon-edit', DELETE:'layui-icon-delete' }; this.checkRuleTypeMap = { CHECK_HOUR:'check_hour', CHECK_COUNT:'check_count', CHECK_STORE_TIME:'check_store_time', CHECK_REACH_COUNT:'check_reach_cunt', CHECK_REACH_TIME:'check_reach_time', CHECK_DAY:'check_day', CHECK_MONTH:'check_month', CHECK_YEAR:'check_year', NONE:'check_none' }; this.getContent=function(){ //返回这个组件的基础html var that = this; var html = [ '
', '
', that.getClassifyToolbarHtml(), '', '', '
', '
', that.getToolbarHtml(), '
',//主列表 '', '
', '
', '
', '
    ', '
  • 定检规则
  • ', ($webUtil.isNotNull(that.accountPath)?'
  • 包含台账清单
  • ':''), '
', '
', '
', that.getCheckToolbarHtml(), '
', '', '
', ($webUtil.isNotNull(that.accountPath)?('
'):''), '
', '
', '
']; html.push('
'); return html.join(""); }; this.getToolbarHtml =function(){ var that = this; var html = [ '
',//主列表的按钮 IMPORTTEMPLATE '', '', '', '', '', '', '', '', '', '', '
', '', '', '
', '
', '
' ].join(""); return html; }; this.getCheckToolbarHtml = function () { var that = this; var html = [ '
', '', '', '', '', '
' ].join(""); return html; }; this.getClassifyToolbarHtml = function(){ var that = this; var html = [ '
', '', '
' ].join(""); return html; }; this.init=function(){//基础的html被添加后,再执行初始化 var that = this; $webUtil.copyConfig(that,that.moduleKey); $webUtil.bindDefultButtonLisenter(that, that.id); $webUtil.bindDefultButtonLisenter(that, "classify_" + that.id); $webUtil.bindDefultButtonLisenter(that, "check_" + that.id); var table = layui.table; that.materialExtendAttr = layui['platform/basedoc/BdMaterialClassifyExtendAttr']; //初始化 that.classifyTreeInit(function () { that.initMainTable( function () { $webUtil.createSearchHtml({ id: '编号', code:'图号', name:'名称', specification:'规格', brand:'品牌', material:'材质', applyProduct:'适用产品', supplier:'常用制造/供应商', "useDept.name":'使用部门名称', revisionValue:'版本号' }, $('[layui-filter="toolbar_' + that.id + '"]'), that.id); // that.initCheckTable(); if($webUtil.isNotNull(that.accountPath)) { that.detailTableInit(); } } ); }); $("#switch_" + that.id).unbind('click').click(function (e) { var thisObject = $(this); if(thisObject.hasClass("layui-form-onswitch")){ //说明现在点的是,需要修改为否 thisObject.removeClass("layui-form-onswitch"); thisObject.find("em").html("否"); table.reload("table_"+that.id,{ where:{ "conditionMap['${queryAllRevision}']":false } }); }else{ thisObject.addClass("layui-form-onswitch"); thisObject.find("em").html("是"); table.reload("table_"+that.id,{ where:{ "conditionMap['${queryAllRevision}']":true } }); } layui.stope(e); }); }; this.classifyTreeInit = function(callback){ //初始化分类树 var that = this; var tree = layui.tree; that.fristTreeLoad = false; tree.init("tree_" + that.id, $('[layui-filter="tree_' + that.id + '"]'), { url: that.url.classifyTree, backPath: that.backPath, extraParams: { isMuti: false, isQueryAllColumn: true }, treeFilter: that.id, treeName: 'materialClassify', click: function (item, elem, options) { that.currentItemOid = item.oid; that.currentItemAttributes = item.attributes; that.showMaterialByClassify(item.attributes); }, done:function (filter,children) { if(!that.fristTreeLoad &&callback){ callback(); } that.fristTreeLoad = true; } }); }; this.showMaterialByClassify = function (classifyAttributes) { var that =this; var table = layui.table; that.materialExtendAttr.initExtendAttr(classifyAttributes.id,function(){ table.reload("table_"+that.id,{ where:{ materialClassify:classifyAttributes.oid } }); }); }; this.initMainTable = function (callback) { var that = this; that.checkColumns(); var table = layui.table; that.fristMainLoad = false; //主列表中列。 var tableWidth = $("#border_" + that.id).width()-225; table.render({ elem: '#table_' + that.id, id: 'table_' + that.id, url: that.backPath + that.url.controller + that.url.dataGrid, page: { limit: 20, page: 1 }, height:400, cols: [that.columns], width:tableWidth, done:function(res,cur,total){ if(!that.fristMainLoad ){ if(callback) { callback(); } table.on('tool(' + that.id + ')',function(obj){ var data = obj.data;//当前选择行的数据 var layEvent = obj.event;//点的是什么按钮 if(layEvent == 'viewInfo'){ that.showMaterialByOid(data.oid); } }); } that.fristMainLoad = true; }, rowClick:function(thisTableFilter,record){ that.initCheckTable(record.oid); that.addRuleOid = record.oid if($webUtil.isNotNull(that.accountPath)) { table.reload("detail_" + that.id, { extraParams: { pkMaterial: record.oid } }); } table.reload("check_" + that.id, { extraParams: { pkMaterial: record.oid } }); } }); document.getElementById("toolbar_column_" + that.id).innerHTML = '查看'; }; this.initCheckTable = function (oid) { //初始化定检规则的表格 var that = this; that.checkCheckRuleColumns(); var table = layui.table; //主列表中列。 var tableWidth = $("#border_" + that.id).width()-225; var requestData = {}; if(oid != undefined) { requestData["conditionMap['pkMaterial']"] = oid; }; table.render({ elem: '#table_check_' + that.id, id: 'table_check_' + that.id, url: that.backPath + that.url.listCheckRule, page: { limit: 20, page: 1 }, where: requestData, cols: [that.checkRuleColumns], width:tableWidth, done:function(res,cur,total){ // if(!that.fristMainLoadCheck ){ // if(callback) { // callback(); // } table.on('tool(check_' + that.id + ')',function(obj){ console.log(obj) var data = obj.data;//当前选择行的数据 var layEvent = obj.event;//点的是什么按钮 if(layEvent == 'viewInfo'){ that.showRuleByOid(data); } }); // } // that.fristMainLoadCheck = true; } }); document.getElementById("toolbar_column_check_" + that.id).innerHTML = '查看';; }; this.detailTableInit = function(){ //初始化明细的列表 var that = this,table = layui.table; that.detailCheckColumns(); var tableWidth = $("#border_" + that.id).width()-225; table.render({ elem: '#detail_' + that.id, id: 'detail_' + that.id, height:230, width:tableWidth, url:that.accountPath + that.url.accountGrid, extraParams:{ pkMaterial: '' }, page: { limit: 5, page: 1 }, cols: [that.detailcolumns] }); }; this.checkLength = function(str){ var reg = str.replace(/[\u4e00-\u9fa5]/g,''); if((str.length-reg.length)*2+reg.length<=127){ return str }else{ return str.substring(0,127) } }; this.advancedQuery = function(){ var that = this; var dynamicCondition = layui.dynamicCondition; $('[layui-filter="toolbar_' + that.id + '"]').append('
'); var dataFields = that.columns; that.serinorQueryInstance = dynamicCondition.create({ fields : dataFields//查询字段 ,tableId:"table_"+that.id//需要查询的表格 ,type:"complex" //type:"simple"/"complex" 查询的方法 暂时写死为 complex ,conditionTextId:"#toolbar"+that.id//高级查询 按钮所在的div ,popupShowQueryBtn: true//显示高级查询按钮 ,queryCallBack:function(requestData){//查询之后的callback //console.log(JSON.stringify(requestData)) } }); }; this.ADD = function(){ var that = this; if(!that.currentItemOid){ $webUtil.showErrorMsg("请先选择分类节点后再操作"); return false; } that.addOrEdit(true); }; this.EDIT = function(oid){ var that = this; if(!oid) { oid = $webUtil.getOidFromGrid("table_" + that.id, true, true); } if(!oid){ return false; } var lcStatus = $webUtil.getOidFromGrid("table_" + that.id,false,false,'lcStatus'); if('Editing' != lcStatus){ $webUtil.showErrorMsg("只有状态为【编辑中】时才能修改"); return false; } that.addOrEdit(false); }; this.addOrEdit = function (add) { var that = this; var filter = "addOrEdit_" + that.id; if(!add){ var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true); if(!oid){ return false; } } var form = layui.form; var addSaveIndex = layer.open({ type:1, title: add?'新增物料/工具基本信息':'修改物料/工具基本信息', btn: ['保存', '取消'], skin: 'layui-layer-lan', content: '
', fullScreen:true, resizing: function (layero) { form.doResize(filter); }, success: function (layero) { form.addItems(filter,that.getFormItems(false), function () { if(add){ //添加的时候,如果选择树节点,则设置为物料基本分类 if($webUtil.isNotNull(that.currentItemOid)){ form.setValues({ materialClassify:that.currentItemOid, materialClassifyText:(that.currentItemAttributes.id + " " + that.currentItemAttributes.name), materialClassifyId:that.currentItemAttributes.id },filter); }else{ form.setValues({},filter); } }else{ var selectRowData = layui.table.checkStatus("table_" + that.id).data[0]; that.materialExtendAttr.loadMaterialForForm(filter,selectRowData.oid,that.currentItemAttributes.id); } //监控事件 form.on("select(" + filter + ")",function(data){ //我们需要在这里处理扩展属性 //获取新的分类的值,获取对应的业务类型的字段内容 //然后设置新的内容 }); } , {} , { defaultColumnOneRow: 3 }); }, yes:function(layero){ if(form.validata(filter)){ var formValues = form.getValues(filter,true); delete formValues['extendAttrData']; for(var key in formValues){ if($webUtil.startWith(key,"extendAttrData[")){ delete formValues[key]; } } //处理扩展属性 for(var key in formValues){ if($webUtil.startWith(key,"ext_")){ var fieldName = key.replace("ext_",""); formValues['extendAttrData[' + fieldName + ']'] = formValues[key]; } } $webUtil.ajax(add?'post':'put',that.url.controller + (add?that.url.add:that.url.edit),formValues,function (result) { if(result.success){ $webUtil.showMsgFromResult(result,add?"新增物料/工具基本信息成功":"修改物料/工具基本信息成功"); that.refresh(); layer.close(addSaveIndex); }else{ $webUtil.showErrorMsg(result.msg); } },function (xhr,error) { $webUtil.showErrorMsg("访问服务器出现了错误,可能服务器没有开启,或者连接失败"); },that.backPath); } }, btn2:function(layero){ that.refresh(); layer.close() } }); }; this.ADDRULE = function () { var that = this; //添加规则 var oid = $webUtil.getOidFromGrid("table_" + that.id, true, true); if(!oid){ return false; } var lcStatus = $webUtil.getOidFromGrid("table_" + that.id,false,false,'lcStatus'); if('Editing' != lcStatus){ $webUtil.showErrorMsg("只有基本信息的状态为【编辑中】时才能添加定检规则"); return false; } that.addOrEditRule(true); }; this.EDITRULE = function (oid) { var that = this; var materialOid = $webUtil.getOidFromGrid("table_" + that.id, true, true); if(!materialOid){ return false; } var lcStatus = $webUtil.getOidFromGrid("table_" + that.id,false,false,'lcStatus'); if('Editing' != lcStatus){ $webUtil.showErrorMsg("只有基本信息的状态为【编辑中】时才能添加定检规则"); return false; } if(!oid) { oid = $webUtil.getOidFromGrid("table_check_" + that.id, true, true); } if(!oid){ return false; } that.addOrEditRule(false,oid); }; this.DELRULE = function(){//删除 var that = this; var oid = $webUtil.getOidFromGrid("table_check_" +that.id,true,true); if(!oid){ return false; } var ts = $webUtil.getOidFromGrid("table_check_" +that.id,false,false,"ts"); $webUtil.showConfirmMsg("是否删除?如果物料/工具已经有台账内容,则不能删除",function () { $webUtil.deleteRequest(that.url.deleteData,{oid:oid,ts:ts},function (result) { if(result.success){ $webUtil.showMsgFromResult(result,"删除成功"); that.refreshRule(); }else{ $webUtil.showErrorMsg(result.msg); } },function (xhr,error) { $webUtil.showErrorMsg("访问服务器出现了错误,可能服务器没有开启,或者连接失败"); },that.backPath) }); }; this.IMPORT = function () { var that = this; var filter =that.id + "_uploadAccount"; var uploadIndex = layer.open({ type:1, title:'导入物料基本信息', skin:'layui-layer-lan', btn:['下载导入模板','取消'], content:'
', closeBtn:2, shade:true, area:['250px','180px'], shadeClose:true, resize:false, success:function(layero){ }, yes:function(){ var iframeId = MD5("downloadImportTemplate" +$webUtil.getSystemVar($webUtil.systemValueKey.currentDateTimeSSS) +$webUtil.getSystemVar($webUtil.systemValueKey.userOid)); $webUtil.fileDownload(that.backPath + that.url.controller + that.url.downloadImportTemplate+ "?" + TOKEN_KEY + "=" + $webUtil.getToken() + "&downloadUUID=" + iframeId + "&materialClassifyId=" + that.currentItemAttributes.id); } }); }; this.IMPORTRULE = function () { //导入定检规则 var that = this; var selectData = layui.table.checkStatus("table_" + that.id).data[0]; if(selectData == undefined){ $webUtil.showErrorMsg('请选择一条数据!'); return false; } var form = layui.form; var filter = that.id + "_uploadAccount"; var uploadIndex = layer.open({ type:1, title:'导入定检规则', skin:'layui-layer-lan', btn:['下载导入模板','取消'], content:'
', closeBtn:2, shade:true, area:['500px','300px'], shadeClose:true, resize:false, success:function(layero){ form.addItems(filter,[{ type:'label', name:'uploadTwoDimensions', labelWidth:140, }],function(){ $("#importAccount_" + filter).append('
选择文件后自动上传
'); $("#importAccount_" + filter).append(''); var upload = layui.upload; //执行实例 var uploadInst = upload.render({ elem: '#upload_button_' + filter //绑定元素 ,accept:'file' ,acceptMime:'file/*' ,exts:'xls|xlsx' ,url: that.backPath+ that.url.importData//上传接口 ,auto:true ,before:function(obj){ obj.setData({pkMaterial:selectData.oid}); return true; } ,done: function(result){//不需要输入内容,因此没有before if(result.success){ layer.close(uploadIndex); $webUtil.showMsg("上传定检规则成功!"); that.refresh(); that.refreshRule(); }else{ $webUtil.showErrorMsg(result.msg); } } ,error: function(){ //请求异常回调 $webUtil.showErrorMsg("上传异常,服务端出错了"); } }); },{},{ defaultColumnOneRow:1, inDialog:true }); }, yes:function(){ // var iframeId = MD5("downloadImportTemplate" +$webUtil.getSystemVar($webUtil.systemValueKey.currentDateTimeSSS) +$webUtil.getSystemVar($webUtil.systemValueKey.userOid)); // $webUtil.fileDownload(that.backPath + that.url.download+ "?" + TOKEN_KEY + "=" + $webUtil.getToken() + "&downloadUUID=" + iframeId + "&materialClassifyId=" + that.currentItemAttributes.id); var oid = "&" + "conditionMap['pkMaterial']=" + selectData.oid var downIframe = $("