田源
2024-04-07 2ac55ce0edf4870a29691b56bfad59f4830a11a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
/**
 * 主数据引擎在流程中显示的内容
 * @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 '<div id="UIContent_' + that.id + '" style="overflow: auto;padding:0 5px"></div>';
        };
        this.showContent = function () {
            var html = "";
            var that = this;
            html = [
                '<div class="layui-layout easyui-layout UIContentLayout" id="easyuiLayout_', that.id, '" data-options="fit:true" style="display:block;overflow-y: hidden">',
                    '<div data-options="region:\'west\',split:true" title="编码" style="width:210px;padding: 5px;">',
                        '<div class="layui-vci-tree" style="overflow: auto">',
                            '<ul layui-filter="tree_', that.id, '"><ul>',
                        '</div>',
                    '</div>',
                    '<div data-options="region:\'center\'" title="编码详细信息" style="" id="border_', that.id, '">',
                        '<div class="layui-center">',
                            that.getToolbarHtml(),
                            '<div class="easyui-layout"  id="easyuiLayoutCenter_', that.id, '" data-options="fit:true" style="display:block;overflow-y: hidden;">',
                                '<div data-options="region:\'center\'" style="padding: 5px;border: 0;">',
                                    '<form id="form_' + that.id + '" lay-filter="form_' + that.id + '" class="layui-form " style="margin-top:5px" ></form>',
                                '</div>',
                                '<div data-options="region:\'south\',split:true,collapsed:true" style="height:270px;padding-left: 5px;padding-right: 5px;border-left: 0;border-right: 0;border-bottom: 0;" id="border_center_', that.id, '">',
                                    '<div class="layui-layout-border layui-tab" lay-filter="tab_',that.id ,'" style="display:block;margin:5px;">',
                                        '<ul class="layui-tab-title tabTitle tab_center_', that.id, '" lay-allowClose="false">',
                                            '<li class="layui-this" lay-id="resemble">相似项查询</li>',
                                        '</ul>',
                                        '<ul class="layui-tab-content tabContent">',
                                            '<li class="layui-tab-item layui-show"  lay-id="resemble">',
                                                '<table id="resemble_', that.id , '" lay-filter="resemble_',that.id , '" style="overflow-x:auto;"></table>',
                                            '</li>',
                                        '</ul>',
                                    '</div>',
                                '</div>',
                            '</div>'
                            ,
                        '</div>',
                    '</div>',
                '</div>',
            ].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 ['<div layui-filter="toolbar_',that.id,'" class="layui-btn-container layui-buttons" style="margin:0 5px">',
                        that.sourceData.noEdit?'':('<button class="layui-btn layui-btn-sm" id="toolbar_'+that.id+'_SAVEDATA" style="display:none;"><i class="layui-icon layui-icon-star"></i>保存</button>'),
                        '<button class="layui-btn layui-btn-sm" id="toolbar_',that.id,'_resembleDATA" style="display:none;"><i class="layui-icon layui-icon-star"></i>相似项查询</button>',
                    '</div>'].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<result.obj.length;i++){
                                        var record = result.obj[i];
                                        text.push(_item[record] || '');
                                    }
                                }else{
                                    text.push(_item['name'] || ('第' + (_index + 1) + "行数据"));
                                }
 
                                var tree = {
                                    oid: _item.oid,
                                    text: text.join(' '),
                                    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 '<span style="color: red;">' + d.name + '</span>' + '<i class="layui-icon layui-icon-ok" style="margin-left:10px;font-size:14px;display: inline-block;padding: 0 5px 0 10px;color: red"></i> '
                                    }if (d.attributes.passing === true || d.attributes.passing === 'true') {
                                        return '<span style="color: green;">' + d.name + '</span>' + '<i class="layui-icon layui-icon-edit" style="margin-left:10px;font-size:14px;display: inline-block;padding: 0 5px 0 10px;color: green"></i> '
                                    } else {
                                        return d.name + '<i class="layui-icon layui-icon-edit" style="margin-left:10px;font-size:14px;display: inline-block;padding: 0 5px 0 10px;"></i>'
                                    }
                                },
                                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 '<span style="color: red;">' + d.name + '</span>' + '<i class="layui-icon layui-icon-ok" style="margin-left:10px;font-size:14px;display: inline-block;padding: 0 5px 0 10px;color: red"></i> '
                            }if (d.attributes.passing === true || d.attributes.passing === 'true') {
                                return '<span style="color: green;">' + d.name + '</span>' + '<i class="layui-icon layui-icon-edit" style="margin-left:10px;font-size:14px;display: inline-block;padding: 0 5px 0 10px;color: green"></i> '
                            } else {
                                return d.name + '<i class="layui-icon layui-icon-edit" style="margin-left:10px;font-size:14px;display: inline-block;padding: 0 5px 0 10px;"></i>'
                            }
                        },
                        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);
});