/** * 主数据引擎在流程中显示的内容 * @author weidy * @date 2022-2-23 */ layui.define(['layer','element','form','table','dynamicCondition' ,'tree','mdm/MdmEngineForm'],function(exports){ var webUtil = $webUtil; var Class = function() { this.MODELNAME = "mdm/MdmEngineInProcess"; this.moduleKey = "MdmEngineInProcess"; this.id = "MdmEngineInProcess"; this.backPath = configData.compatibility ? path : configData.mdmService; this.url = { controller: 'mdmEngineController/', tableUI: 'getUIInfoByClassifyOid', formUI: 'getFormDefineByClassifyOid', tableData: 'gridTableDataByClassifyOid', getDataByOid: 'getDataByOid', getPhaseByClassifyOid: 'listPhaseAttrByClassifyOid', markpass:'markPass' }; this.sourceData = {}; this.config={} this.getContent = function () { var that = this; return '
'; }; this.showContent = function () { var html = ""; var that = this; html = [ '
', '
', '
', '
      ', '
', '
', '
', '
', that.getToolbarHtml(), '
', '
', '
', '
', '
', '
', '
    ', '
  • 相似项查询
  • ', '
', '
    ', '
  • ', '
    ', '
  • ', '
', '
', '
', '
' , '
', '
', '
', ].join(""); $("#UIContent_" + that.id).html(html); }; this.init = function () { var that = this; this.config[that.id] = { id:that.id, sourceData:that.sourceData }; if(that.config[that.id].sourceData.maxHeight && that.config[that.id].sourceData.maxHeight<250){ that.config[that.id].sourceData.maxHeight=250 }else { that.config[that.id].sourceData.maxHeight=$('#portal_body').height() - 102 } var dateStore = that.sourceData['dataStore']; that.config[that.id].codeClassifyOid = dateStore[0]['codeclsfid']; webUtil.copyConfig(that, that.moduleKey); if ($webUtil.isNull(that.config[that.id].codeClassifyOid)) { $webUtil.showErrorMsg("数据中没有主题库分类主键"); return false; } that.MdmEngineForm = layui['mdm/MdmEngineForm']; that.config[that.id].componentVO = null; setTimeout(function () { that.showContent(); var easyuiLayout = $('#easyuiLayout_' + that.id) easyuiLayout.css({height:that.config[that.id].sourceData.maxHeight-10, width: $('#portal_body').width() - 360}) easyuiLayout.layout(); var easyuiLayoutCenter = $('#easyuiLayoutCenter_' + that.id) easyuiLayoutCenter.css({ height: $("#border_" + that.id).height() - 68, width: $("#border_" + that.id).width() - 20 }) easyuiLayoutCenter.layout(); that.showForm(that.id); that.initTree(dateStore); }, 1); }; this.getToolbarHtml = function () { var that = this; return ['
', that.sourceData.noEdit?'':(''), '', '
'].join(''); }; this.refresh = function (configId){ var that= this; that.setValueForForm(configId); }; this.initTree = function (dateStore) { var that = this; var tree = layui.tree; var scrollHeight = that.config[that.id].sourceData.maxHeight || (window.innerHeight-210); var treeUL = $('[layui-filter="tree_' + that.id + '"]'); var treeHeight = scrollHeight-100; treeUL.parent().height(treeHeight); $webUtil.post("processDefineController/getVariableByKey", { executionId: that.config[that.id].sourceData['executionid'], keys: 'processUse' }, function (result) { if (result.success) { var processUse = result.obj['processUse']; webUtil.get('mdmEngineController/getFieldByProcessTemplate', {templateOid: dateStore[0].codetemplateoid,executionId:that.config[that.id].sourceData['executionid'],processUse:processUse}, function (result) { if (!result.success) { $webUtil.showErrorMsg(result.msg); } else { var treeData = []; layui.each(dateStore,function(_index,_item){ var text=[] if(result.obj && result.obj.length>0){ for (var i=0;i' + d.name + '' + ' ' }if (d.attributes.passing === true || d.attributes.passing === 'true') { return '' + d.name + '' + ' ' } else { return d.name + '' } }, click: function (item, elem, options,event) { that.config[options.configId].currentItemOid = item.oid; that.config[options.configId].currentItemAttributes = item.attributes; that.setValueForForm(options.configId); if (event.target.className == 'layui-icon layui-icon-ok') { that.setMarkPass(options.configId,item.oid,item.attributes.btmname,true) return false; } if (event.target.className == 'layui-icon layui-icon-edit') { that.setMarkPass(options.configId,item.oid,item.attributes.btmname,false) return false; } }, done:function (filter,children,elem){ var currentelem=layui.tree.getElemByItem(filter, children[0].oid); if(currentelem.length>0){ currentelem.children('a').trigger('click') } } }); } }, function (xhr, err) { }, that.backPath,true); }else{ var treeData = []; layui.each(dateStore,function (_index,_item){ var tree = { oid: _item.oid, text: (_item.name || ('第' + (_index + 1) + "行数据")), leaf: true, attributes: _item } treeData.push(tree); }); tree.init("tree_" + that.id, treeUL, { data: treeData, showSearch: true, configId:that.id, templet:function (d) { if (d.attributes.passing === false || d.attributes.passing === 'false') { return '' + d.name + '' + ' ' }if (d.attributes.passing === true || d.attributes.passing === 'true') { return '' + d.name + '' + ' ' } else { return d.name + '' } }, click: function (item, elem, options,event) { that.config[options.configId].currentItemOid = item.oid; that.config[options.configId].currentItemAttributes = item.attributes; that.setValueForForm(options.configId); if (event.target.className == 'layui-icon layui-icon-ok') { that.setMarkPass(options.configId,item.oid,item.attributes.btmname,true) return false; } if (event.target.className == 'layui-icon layui-icon-edit') { that.setMarkPass(options.configId,item.oid,item.attributes.btmname,false) return false; } }, done:function (filter,children,elem){ var currentelem=layui.tree.getElemByItem(filter, children[0].oid); if(currentelem.length>0){ currentelem.children('a').trigger('click') } } }); } },function (error,xhr){ $webUtil.showErrorMsg("获取可编辑项出错") },that.backPath,true); }; this.setMarkPass = function (configId,oid,btmname,pass){ var that=this webUtil.ajax('post', that.url.controller+that.url.markpass, {oid:oid,btmName:btmname,pass:pass}, function (result) { if (result.success) { webUtil.showMsgFromResult(result, "标记成功"); var options=layui.tree.getOptions("tree_" +configId) layui.each(options.data,function (i,item){ if(item.oid==oid){ options.data[i].attributes.passing=pass; } }) layui.tree.setOptions("tree_" +configId,options) layui.tree.reload("tree_" +configId,options) } else { webUtil.showErrorMsg(result.msg); } }, function (xhr, err) { webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启"); }, that.backPath); } this.setValueForForm = function (configId) { var that = this; //只传递了数据的主键,所以我们需要从后台获取一下 var filter = "form_" + that.config[configId].id; //先从 var lables = $("#form_" + that.config[configId].id + " label"); if(lables && lables.length>0){ layui.each(lables,function (_index,_item){ var itemEL = $(_item); if(itemEL.attr("class").indexOf("label-name-" + filter + "-")>-1) { itemEL.css("color", "#000"); } }); } if(that.config[configId].currentItemOid && that.config[configId].componentVO) { $webUtil.get(that.url.controller + that.url.getDataByOid, { oid: that.config[configId].currentItemOid, templateOid: that.config[configId].componentVO.templateVO.oid }, function (result) { if (result.success) { layui.form.setValues(result.obj, filter); if (result.data && result.data.length > 0) { var difFields = result.data[0]; if (difFields) { for (var key in difFields) { var nameEl = $("#form_" + that.config[configId].id + " .label-name-" + filter + "-" + key); if (nameEl) { nameEl.css("color", "red"); } } } } } else { $webUtil.showErrorMsg(result.msg); } }, function (err, xhr) { $webUtil.showErrorMsg("获取数据出错了,请稍后再试"); }, that.backPath); } }; this.showForm = function (configId) { //我们需要先获取变量里记录的阶段是什么 var that = this; //移除以前的内容 $("#form_" + that.config[configId].id).html(''); $webUtil.post("processDefineController/getVariableByKey", { executionId: that.config[configId].sourceData['executionid'], keys: 'phase,processUse' }, function (result) { if (result.success) { var phase = result.obj['phase']; //根据阶段获取本次可以编辑的字段 $webUtil.get(that.url.controller + that.url.getPhaseByClassifyOid, { codeClassifyOid: that.config[configId].codeClassifyOid, phase: phase }, function (pharseResult) { that.getFormDefine(configId,function (componentVO) { that.config[configId].componentVO = componentVO; var formDefineVO = componentVO.formDefineVO; if (formDefineVO) { var filter = "form_" + that.config[configId].id; var form = layui.form; var colCount = that.MdmEngineForm.getFormCol(formDefineVO,{width:$('#border_'+that.config[configId].id).width()}); var items = that.getFormItemsByVO(formDefineVO, pharseResult.obj,phase,colCount); form.addItems(filter, items, function () { that.setValueForForm(configId); if((pharseResult.obj && pharseResult.obj.length>0) || phase == 'all'){ var saveBtn = $("#toolbar_" + that.config[configId].id +"_SAVEDATA"); saveBtn.show(); saveBtn.unbind('click').click(function (){ //执行保存 that.saveData(configId); }); } var hasResemble = (componentVO.resembleTableVO && componentVO.resembleTableVO.cols && componentVO.resembleTableVO.cols.length > 0); if(!hasResemble){ $('#easyuiLayoutCenter_' + that.config[configId].id).layout('remove','south'); return; }else { $('#easyuiLayoutCenter_' + that.config[configId].id).layout('expand','south'); that.MdmEngineForm.initResembleTable(componentVO, that.config[configId].id); var resembleBtn = $("#toolbar_" + that.config[configId].id + "_resembleDATA"); resembleBtn.show(); resembleBtn.unbind('click').click(function () { if (form.validata(filter)) { webUtil.get('mdmEngineController/getCodeRuleByClassifyOid', {codeClassifyOid: that.config[configId].codeClassifyOid}, function (result) { if (!result.success) { $webUtil.showErrorMsg(result.msg); } else { var values = form.getDefaultValues(filter, true); that.config[configId].codeRuleOid = result.obj.oid; var datas = { codeClassifyOid: that.config[configId].codeClassifyOid, templateOid: componentVO.templateVO.oid, codeRuleOid: result.obj.oid, data: values.otherValue } $.extend(datas, values.defaultValues); webUtil.manualAjax('post', 'mdmEngineController/resembleQuery', JSON.stringify(datas), function (res) { if (res.success) { layui.table.reload("resemble_" + that.config[configId].id, { data: res.data }); } else { webUtil.showErrorMsg(res.msg); } }, function (xhr, err) { webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启"); }, that.backPath); } }); } }); } }, {}, {defaultColumnOneRow: colCount, labelWidth: 160,useLabelFlag:true}); } }); }, function (error, xhr) { $webUtil.showErrorMsg("主数据服务可能没有启动") }, that.backPath,true); } else { $webUtil.showErrorMsg(result.msg); } }, function (error, xhr) { $webUtil.showErrorMsg("流程的服务可能没有启动"); }, configData.compatibility ? path : configData.processServicePath,true) }; this.saveData = function (configId){ var that = this; if(!that.config[configId].currentItemOid){ $webUtil.showErrorMsg("请选择编码"); return false; } var form = layui.form; var filter = "form_" + that.config[configId].id; if (form.validata(filter)) { var values = form.getDefaultValues(filter, true); var datas = { codeClassifyOid:that.config[configId].codeClassifyOid, templateOid:that.config[configId].componentVO.templateVO.oid, editInProcess:true, oid:that.config[configId].currentItemOid, data: values.otherValue } $.extend(datas, values.defaultValues); webUtil.manualAjax('put', that.url.controller+'editSaveCode', JSON.stringify(datas), function (result) { if (result.success) { webUtil.showMsgFromResult(result, "修改成功"); that.refresh(configId) } else { webUtil.showErrorMsg(result.msg); } }, function (xhr, err) { webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启"); }, that.backPath); } }; this.getFormDefine = function (configId,callback) { var that = this; webUtil.get(that.url.controller + that.url.formUI, {codeClassifyOid: that.config[configId].codeClassifyOid}, function (result) { if (!result.success) { $webUtil.showErrorMsg(result.msg); } else { if (callback) { callback(result.obj); } } }, function (xhr, err) { webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启"); }, that.backPath,true); }; this.getFormItemsByVO = function (formDefineVO, showFields,phase,colCount) { layui.each(formDefineVO.items, function (_index, _item) { //因为表单上的字段上已经设置了readOnly,在默认上设置的readOnly不会生效,我们需要自行转换一下 if (_item.field == 'id' || _item.field == 'lcstatus' ) { _item.readOnly = true; } else { if(showFields && showFields.length>0) { var finded = false; layui.each(showFields, function (fieldIndex, field) { if (_item.field == field) { finded = true; return true; } }); _item.readOnly = !finded; }else{ if(phase!='all'){ _item.readOnly = true; } } } _item.inputWidth = 250; if(_item.type=="textarea"){ _item.useAllWidth=true; _item.inputWidth = 415 * colCount - 160; } }); return formDefineVO.items; }; }; var cs = new Class(); exports(cs.MODELNAME,cs); });