田源
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
/**
 * 模板属性枚举注入
 * @author wangting
 * @date 2022-2-21
 */
layui.define(['layer','element','form','table','dynamicCondition'],function(exports){
    var webUtil = $webUtil;
    var Class = function(){
        this.MODELNAME = "mdm/CodeClassifyEnumUse";
        this.moduleKey = "CodeClassifyEnumUse";
        this.id = "CodeClassifyEnumUse";
        this.backPath =  configData.compatibility? path:configData.mdmService;
        this.url = {
            controller:'codeClassifyController/'
        };
        this.getContent=function(){
            var that = this;
            var filter = "enumuse_" + that.id;
            var html=[
                '<div style="margin: 5px">',
                    '<button class="layui-btn layui-btn-sm toolbar_',filter,'_add"> 添加 </button>',
                    '<button class="layui-btn layui-btn-sm toolbar_',filter,'_del"> 删除 </button>',
                    '<table class="layui-table" lay-size="sm" lay-filter="table_' + filter + '" id="table_' + filter + '" ></table>',
                '</div>'
            ]
            return html.join('');
        };
        this.init=function(){
        };
 
        this.showReferDialog=function (options){
            var that=this;
            if(!options){
                options={}
            }
            if(options.id){
                that.id=options.id
            }
            that.fristButtonLoad=false;
            var target = options.target;
            var table = layui.table;
            var filter = "enumuse_" + that.id;
            var tableData=[];
            if(webUtil.isNotNull(options.value)){
                tableData=JSON.parse(options.value)
            }else if(options.formValues && options.formValues.enumFlag) {
                $.each(options.formValues.enumItemMap, function (i, item) {
                    tableData.push({key: i, value: item})
                })
            }
 
            var classifyuseIndex = webUtil.dialog({
                title: '枚举注入',
                btn: ['保存', '取消'],
                content: that.getContent(),
                area:['600px','450px'],
                resizing: function (layero) {
                },
                success: function (layero, layerIndex, classP) {
                    table.render({
                        elem: '#table_' + filter,
                        id: 'table_' + filter,
                        limit: -1,
                        cols: [[table.getIndexColumn(),table.getCheckColumn(),{
                            field: 'key',
                            title: '选项值',
                            edit:'text',
                            width: 150
                        }, {
                            field: 'value',
                            title: '选项中文标签',
                            edit:'text',
                            width: 240
                        }, {
                            field: 'options',
                            title: '操作',
                            width: 80,
                            templet: function (d) {
                                return '<a class="layui-btn layui-btn-intable" lay-event="REM">移除</a>';
                            }
                        }]],
                        data: tableData,
                        done: function (res, cur, total) {
                            if (!that.fristButtonLoad) {
                                table.on('tool(table_' + filter + ')', function (obj) {
                                    var data = obj.data;//当前选择行的数据
                                    var layEvent = obj.event;//点的是什么按钮
                                    if (layEvent == 'REM') {
                                        table.removeData('table_' + filter, data);
                                    }
                                });
                            }
                            that.fristButtonLoad = true;
                        }
                    });
                    $('.toolbar_'+filter+'_add').click(function (){
                        table.addData('table_' + filter, {key:'',value:''});
                    })
                    $('.toolbar_'+filter+'_del').click(function (){
                        var checkData = layui.table.checkStatus("table_" + filter).data;
                        layui.each(checkData,function (i,item){
                            table.removeData('table_' + filter, item);
                        })
                    })
                },
                yes: function (layero) {
                    var datas = table.getData('table_' + filter,true);
                    for (var i=0;i<datas.length;i++){
                        if(webUtil.isNull(datas[i].key)){
                            webUtil.showErrorMsg("请输入选项值");
                            return false;
                        }
                        if(webUtil.isNull(datas[i].value)){
                            webUtil.showErrorMsg("请输入选项中文标签");
                            return false;
                        }
                    }
                    var values=''
                    if(datas.length>0){
                        values=JSON.stringify(datas);
                    }
                    target.setValue(options.filter,options.name,values,values,true);
                    layer.close(classifyuseIndex);
                },
                btn2: function (layero) {
                    layer.close(classifyuseIndex);
                }
            });
        }
        this.refresh = function (buttonid,ele) {
        };
        this.ADVQUERY = function () {
            var that = this;
        };
    };
    var cs = new Class();
    exports(cs.MODELNAME,cs);
});