Ldc
2024-04-07 0652600959e5e3b5796fb6e8da129704ca95347a
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
/**
 * 主数据编码表单
 * @author wangting
 * @date 2022-4-12
 */
layui.define(['layer','element','form','table','dynamicCondition' ,'tree','transfer'],function(exports){
    var webUtil = $webUtil;
    var Class = function(){
        this.MODELNAME = "mdm/MdmEngineForm";
        this.moduleKey = "MdmEngineForm";
        this.backPath =  configData.compatibility? path:configData.mdmService;
        this.url = {
            classifyController: 'codeClassifyController/',
            classifyTree:'referTree',
            controller:'mdmEngineController/',
            tableUI:'getUIInfoByClassifyOid',
            formUI:'getFormDefineByTemplateOid',
            tableData:'gridTableDataByClassifyOid',
            getDataByOid:'getDataByOid'
        };
        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 = "";
            $("#UIContent_" + this.id).html(html);
        };
        this.init = function(){
            var that = this;
            webUtil.copyConfig(that,that.moduleKey);
            this.config[that.id] = {
                sourceData:that.sourceData
            };
        };
        this.getFormDefine = function (codetemplateoid,codeClassifyOid,callback){
            var that = this;
            webUtil.get(that.url.controller + that.url.formUI,{templateOid: codetemplateoid,codeClassifyOid:codeClassifyOid},function (result){
                if(!result.success) {
                    $webUtil.showErrorMsg(result.msg);
                }else{
                    if(callback){
                        callback(result.obj);
                    }
                }
            });
        };
        this.getFormCol = function (formDefineVO,options) {
            var screenWidth = webUtil.getDialogScreenWidth(options||{fullScreen:true});
            var hasPrefix = false;
            var hasSuffix = false;
            layui.each(formDefineVO.items, function (_index, _item) {
                if ($webUtil.isNotNull(_item.prefix)) {
                    hasPrefix = true;
                }
                if ($webUtil.isNotNull(_item.suffix)) {
                    hasSuffix = true;
                }
            });
            var preWidth = 430;
            if (hasPrefix) {
                preWidth += 40;
            }
            if (hasSuffix) {
                preWidth += 40;
            }
            //忘记form里面为啥要减去1了,不敢改
            return (screenWidth - screenWidth % preWidth) / preWidth  ;
        };
        this.getFormItemsByVO = function (formDefineVO,readOnly,colCount,add){
            var that=this;
            layui.each(formDefineVO.items, function (_index, _item) {
                //因为表单上的字段上已经设置了readOnly,在默认上设置的readOnly不会生效,我们需要自行转换一下
                if(_item.field == 'id' || _item.field == 'lcstatus'){
                    if(!add &&_item.field == 'id' && _item.hidden ){
                        _item.hidden= false;
                    }
                    _item.readOnly = true;
                }else {
                    _item.readOnly = readOnly?readOnly:_item.readOnly;
                    if(_item.field=='lcstatus' && _item.readOnly){
                        _item.field='lcstatus_text';
                        _item.type='text';
                    }
                }
                _item.inputWidth = 250;
                if(_item.type=="textarea"){
                    _item.useAllWidth=true;
                    _item.inputWidth = 415 * colCount - 160;
                }
                if(_item.type=="combox"){
                    _item.search = true;
                }
                if(webUtil.isNotNull(_item.selectLibFlag)) {
                    _item.type = 'combox';
                    _item.comboxTextField=_item.field;
                    _item.field= _item.comboxTextField+'Select';
                    _item.comboxKey = formDefineVO.oid+'_'+_item.field;
                    _item.editable = true;
                    _item.search = true;
                    _item.url = "bdSelectInputController/listByFlag";
                    _item.backPath = that.backPath;
                    _item.extraParams = {
                        namespace: formDefineVO.btmType,
                        flag: _item.field
                    }
                }
            });
            return formDefineVO.items;
        };
        //码值表单项
        this.getCodeValueItems=function (data,formfilter) {
            var that=this;
            var items = [];
            layui.each(data, function (i, item) {
                if(item.sectype=="codefixedsec"){
                    //固定码段
                    var fixedValueVOList=[];
                    layui.each(item.fixedValueVOList,function (valueIndex,valueItem){
                        fixedValueVOList.push({key:valueItem.id,value: valueItem.id})
                    })
                    items.push({
                        field: item.oid,
                        title: item.name,
                        required: item.nullableFlag!='true',
                        type: 'combox',
                        data:fixedValueVOList,
                        search:true
                    })
                }else if(item.sectype=="codeclassifysec") {
                    //分类码段
                    var classifyitem = {
                        field: item.oid,
                        title: item.name,
                        required: item.nullableFlag != 'true',
                        type: 'refer',
                        showField: item.name,
                        readOnly:webUtil.isNull(item.parentClassifySecOid)?false:true,
                        parentClassifySecOid:item.parentClassifySecOid,
                        referConfig: {
                            backPath: that.backPath,
                            isMuti: false,
                            type: 'grid',
                            width: 680,
                            tableConfig: {
                                limit:-1,
                                cols: [layui.table.getIndexColumn(), layui.table.getCheckColumn(), {
                                    field: 'id',
                                    title: '英文名称',
                                    sort: true,
                                    width: 150
                                }, {
                                    field: 'name',
                                    title: '中文名称',
                                    sort: true,
                                    width: 150
                                }, {
                                    field: 'description',
                                    title: '描述',
                                    width: 250
                                }],
                                queryColumns: [
                                    {
                                        field: 'id',
                                        title: '英文名称'
                                    }, {
                                        field: 'name',
                                        title: '中文名称'
                                    }
                                ]
                            },
                            url: that.url.controller + '/listCodeClassifyValueBySecOid',
                            extraParams: {
                                classifySecOid: item.oid,
                                parentClassifyValueOid: ''
                            }
                        }
                    }
                    items.push(classifyitem);
                    if(item.parentClassifySecOid){
                        layui.form.on('select('+formfilter+')',function (data){
                            if(data.name==item.parentClassifySecOid){
                                var parentClassifyValueOid=data.value;
                                var allItems=layui.form.getFormItems(formfilter);
                                var childItems=[];
                                layui.each(allItems,function (i,item){
                                    if(item.parentClassifySecOid==data.name){
                                        item.readOnly=false;
                                        item.referConfig.extraParams.parentClassifyValueOid=parentClassifyValueOid
                                        childItems.push(item)
                                    }
                                })
                                layui.form.changeItems(formfilter,childItems)
                            }
                        })
                    }
 
                }else if(item.sectype=="codevariablesec"){
                    //可变码段
                    items.push({
                        field: item.oid,
                        title: item.name,
                        required: item.nullableFlag!='true'
                    })
                }else if(item.sectype=="coderefersec"){
                    //引用码段
                    var referConfig=JSON.parse(item.referValueInfo)
                    if(referConfig && referConfig.tableConfig && referConfig.tableConfig.cols.length>0){
                        referConfig.tableConfig.cols.unshift(layui.table.getIndexColumn(), layui.table.getCheckColumn());
                        layui.each(referConfig.tableConfig.cols,function (i,item){
                            if(item.templet!=''){
                                referConfig.tableConfig.cols[i].templet=eval("(" + item.templet + ")")
                            }
                        })
                    }
                    items.push({
                        field: item.oid,
                        title: item.name,
                        required: item.nullableFlag!='true',
                        type: 'refer',
                        showField: item.name,
                        referConfig: referConfig
                    })
                }
            })
            return items;
        }
 
        //相似项
        this.initResembleTable = function (componentVO,filter){
            var that = this;
            var table = layui.table;
            if(componentVO.resembleTableVO && componentVO.resembleTableVO.cols && componentVO.resembleTableVO.cols.length>0){
                //处理列表
                var cols = [];
                var eventMap = {};
                for (var i = 0; i < componentVO.resembleTableVO.cols.length; i++) {
                    if (i == 0) {
                        componentVO.resembleTableVO.cols[i].unshift({
                            field: table.config.indexName,
                            type: 'numbers',
                            title: '序号',
                            rowspan: componentVO.resembleTableVO.cols.length,
                            width: 40
                        }, {
                            field: table.config.checkName,
                            type: 'checkbox',
                            rowspan: componentVO.resembleTableVO.cols.length,
                            width: 30
                        })
                    }
                    //每个字段都需要扫描一下是否有事件
                    for (var j = 0; j < componentVO.resembleTableVO.cols[i].length; j++) {
                        var record =  componentVO.resembleTableVO.cols[i][j];
                        if(record.optionJsMap){
                            for(var key in record.optionJsMap){
                                eventMap[key] =  record.optionJsMap[key];
                            }
                        }
                        if(record.field == 'id' && $webUtil.isNull(record.templet)){
                            //企业编码的默认添加超链接
                            record.templet = '<div><a name="code" href="javascript:;" dataIndex="{{d.LAY_INDEX}}" lay-event="VIEWDETAIL" data-oid="{{d.oid}}" data-template="{{d.codetemplateoid}}" style="text-decoration:underline;color:blue;" >{{d.id}}</a></div>';
                        }
                    }
 
                    cols.push(componentVO.resembleTableVO.cols[i]);
                }
                table.render({
                    elem: '#resemble_' + filter,
                    id: "resemble_" + filter,
                    data:[],
                    limits: -1,
                    selectMode: table.selectMode.muti,
                    cols: cols,
                    done: function (res, cur, total) {
                        table.on('tool(resemble_' + filter + ')', function (obj) {
                            var data = obj.data;//当前选择行的数据
                            var layEvent = obj.event;//点的是什么按钮
 
                            if (layEvent == 'VIEWDETAIL') {
                                that.VIEWDETAIL(data.oid,data.codetemplateoid);
                            } else {
                                if (layEvent in eventMap) {
                                    that.callEvent(eventMap[layEvent], data);
                                }
                            }
                        });
                    }
                });
            }else{
                layui.element.tabDelete("tab_" + filter, "resemble");
            }
        };
 
        this.callEvent = function (jsPath,data){
            var that = this;
            if(jsPath && data){
                if($webUtil.startWith(jsPath.toLowerCase(),"usejs:")||$webUtil.startWith(jsPath.toLowerCase(),"js:")){
                    //是执行js
                    if($webUtil.startWith(jsPath.toLowerCase(),"usejs:")){
                        jsPath = jsPath.substr(6);
                    }else {
                        jsPath = jsPath.substr(3);
                    }
                    layui.use(jsPath,function (){
                        layui[jsPath].doEvent(data,that);
                    });
                }else if($webUtil.startWith(jsPath.toLowerCase(),"https://") || $webUtil.startWith(jsPath.toLowerCase(),"http://")){
                    var tabId = (data.oid || jsPath) + "_link";
                    portal.showTabByMenu(data.oid || jsPath,{
                        id:data.oid || jsPath,
                        text:'查看链接',
                        url:jsPath
                    });
                }else if(that[jsPath]){
                    that[jsPath](data);
                }else{
                    //直接是js的暂时还不支持
                }
            }
        };
        this.VIEWDETAIL = function (oid,codetemplateoid,codeClassifyOid){
            //表单详情
            var that = this;
            if(!oid){
                return false;
            }
            if(!codetemplateoid){
                return false;
            }
            that.getFormDefine(codetemplateoid,codeClassifyOid,function (componentVO){
                var formDefineVO= componentVO.formDefineVO;
                if(formDefineVO){
                    var filter=oid + "_detail_form";
                    var form = layui.form;
                    var colCount = that.getFormCol(formDefineVO);
                    var items = that.getFormItemsByVO(formDefineVO,true,colCount,false);
                    webUtil.dialog({
                        title: '查看详细信息',
                        fullScreen:true,
                        content: '<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form " style="margin-top:5px" ></form>',
                        resizing: function (layero) {
                            form.doResize(filter);
                        },
                        success: function (layero) {
                            form.addItems(filter, items,
                                function () {
                                    //只传递了数据的主键,所以我们需要从后台获取一下
                                    form.load(filter,{
                                        backPath:that.backPath,
                                        url:that.url.controller + that.url.getDataByOid,
                                        method:'get',
                                        params:{
                                            oid:oid,
                                            templateOid:codetemplateoid
                                        }
                                    });
                                }, {}, {defaultColumnOneRow:colCount,labelWidth:150});
                        }
                    });
                }
            });
        };
    };
    var cs = new Class();
    exports(cs.MODELNAME,cs);
});