田源
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
/**
 * 客户基本分类
 * @author weidy@2020/3/13
 */
layui.define(['layer','element','form','table','util'],function(exports){
    var Class = function(){
        this.MODELNAME = "platform/basedoc/BdCustomerClassify";
        this.moduleKey = "BdCustomerClassify";
        this.id = 'BdCustomerClassify';
        this.sourceData = {};
        this.columns = [];
        this.backPath =  configData.compatibility?path:configData.frameworkPath;
        this.url={
            dataGrid:'smButtonController/dataGrid',//列表数据和查询
            add:'smButtonController/addSave',
            edit:'smButtonController/editSave',
            deleteUrl:'smButtonController/delete'
        };
        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.getContent=function(){//返回这个组件的基础html
            var that = this;
            var html = "";
            html = [
                that.getToolbarHtml(),
                '<div class="layui-layout" style="display:block;overflow-y: hidden">',
                '<div class="layui-vci-tree" style="width:250px;float: left;background-color:#ffffff;overflow-y: auto;">',
                '<label class="layui-icon layui-icon-tree" style="line-height: 20px;color:red;font-size:20px;">客户基本分类</label>',
                '<ul layui-filter="tree_',that.id,'"><ul>',
                '</div>',
                '<div class="layui-layout-border" style="display:block;margin-top:0px;margin-left:255px;">',
                '<div class="layui-center" style="overflow-y:auto;">',
                '<form class="layui-form" lay-filter="form_',that.id,'"></form>',
                '</div>',
                '</div>',
                '</div>'
            ].join("");
            return html;
        };
        this.getToolbarHtml =function(){
            var that = this;
            return ['<div layui-filter="toolbar_',that.id, '" class="layui-btn-container">',//主列表的按钮
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_ADD"><i class="layui-icon layui-icon-add-1"></i>添加</button>',
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_EDIT"><i class="layui-icon layui-icon-edit"></i>修改</button>',
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_DEL"><i class="layui-icon layui-icon-delete"></i>删除</button>',
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_enable"><i class="layui-icon layui-icon-ok-circle"></i>启用</button>',
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_disable"><i class="layui-icon layui-icon-404"></i>停用</button>',
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_refresh"><i class="layui-icon layui-icon-refresh"></i>刷新</button>',
                '</div>'].join("");
        };
        this.init=function(){
            //基础的html被添加后,再执行初始化
            var that = this;
            $webUtil.copyConfig(that,that.moduleKey);
            $webUtil.bindDefultButtonLisenter(that, that.id);
            var tree = layui.tree;
            var scrollHeight =  window.innerHeight;
            var treeUL = $('[layui-filter="tree_' + that.id + '"]');
            var treeHeight = scrollHeight - 200;
            treeUL.parent().height(treeHeight);
            tree.init("tree_" + that.id, treeUL, {
                url: that.url.tree,
                backPath: that.backPath,
                extraParams: {
                    isMuti: false,
                    isQueryAllColumn: true
                },
                showSearch:true,
                click: function (item, elem, options) {
                    that.setFormValues(item.attributes);
                },
                done: function (thisFilter) {
                    that.initForm();
                }
            });
        };
        this.initForm = function(){
            var that = this;
            var form = layui.form;
            form.addItems("form_" + that.id, that.getFormItems(true), function () {
            }, {}, {
                defaultColumnOneRow: 2,
                labelWidth:200
            });
        };
        this.getFormItems = function(onlyShow){
            var that = this;
            return [{
                field: 'id',
                text: '客户基本分类编号',
                required:true,
                readOnly: onlyShow
            }, {
                field: 'name',
                text: '客户基本分类名称',
                required:true,
                readOnly: onlyShow
            },{
                field:'description',
                text:'描述',
                readOnly: onlyShow
            },{
                field: 'lcStatusText',
                text: '状态',
                readOnly: true
            }];
        };
        this.ADD = function(){//保存
            var that = this;
            layui.use('form',function(){
                var form = layui.form;
                var filter ="form_" + that.id;
                var addSaveIndex = layer.open({
                    type:1,
                    title:'添加按钮',
                    btn:['保存','取消'],
                    skin:'layui-layer-lan',
                    content:'<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
                    area:['800px','270px'],
                    closeBtn:2,
                    shade:true,
                    shadeClose:true,
                    resize:true,
                    resizing:function(layero){
                        form.doResize(filter);
                    },
                    success:function(layero) {
                        form.addItems(filter,that.getFormItems(false),
                            function () {}, {}, {defaultColumnOneRow: 2});
                    },
                    yes:function(layero){
                        if(form.validata(filter)){
                            var values = form.getValues(filter);
                            $webUtil.post(that.url.add,values,function(result){
                                if(result.success){
                                    $webUtil.showMsg("添加按钮成功");
                                    layer.close(addSaveIndex);
                                    that.refresh();
                                }else{
                                    $webUtil.showErrorMsg(result.msg);
                                }
                            },function (xhr,error) {
 
                            },that.backPath);
                        }
                    },
                    btn2:function(layero){
                        layer.close(addSaveIndex);
                        that.refresh();
                    }
                });
            });
        };
        this.EDIT = function(){
            var that = this;
            var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
            if(!oid){
                return false;
            }
            var selectRowData = layui.table.checkStatus("table_" + that.id);
            layui.use('form',function(){
                var form = layui.form;
                var filter ="form_" + that.id;
                var addSaveIndex = layer.open({
                    type: 1,
                    title: '修改按钮',
                    btn: ['保存', '取消'],
                    url: that.backPath + that.url.edit,
                    skin: 'layui-layer-lan',
                    content: '<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
                    area: ['800px', '270px'],
                    closeBtn: 2,
                    shade: true,
                    shadeClose: true,
                    resize: true,
                    resizing: function (layero) {
                        form.doResize(filter);
                    },
                    success: function (layero) {
                        form.addItems(filter,that.getFormItems(true),
                            function () {
                                form.setValues(selectRowData.data[0],filter);
                            }
                            , {}
                            , {
                                defaultColumnOneRow: 2
                            });
                    },
                    yes:function(layero){
                        if(form.validata(filter)){
                            var formValues = form.getValues(filter,true);
                            formValues['oid'] = selectRowData.data[0].oid;
                            formValues['ts'] = selectRowData.data[0].ts;
                            $webUtil.put(that.url.edit,formValues,function (result) {
                                if(result.success){
                                    $webUtil.showMsg("修改按钮成功");
                                    that.refresh();
                                    layer.close(addSaveIndex);
                                }else{
                                    $webUtil.showErrorMsg(result.msg);
                                }
                            },function (error) {
 
                            },that.backPath);
                        }
                    },
                    btn2:function(layero){
                        that.refresh();
                        layer.close()
                    }
                });
            });
        };
 
        this.DEL= function(){
            var that = this;
            var oid = $webUtil.getOidFromGrid("table_" +that.id,true,true);
            if(!oid){
                return false;
            }
            var ts =  $webUtil.getOidFromGrid("table_" +that.id,false,false,"ts");
            $webUtil.showConfirmMsg("是否删除这个按钮,对应的功能菜单中的按钮不会自动删除",function () {
                $webUtil.deleteRequest(that.url.deleteUrl,{oid:oid,ts:ts},function(result){
                    if(result.success){
                        $webUtil.showMsg("删除按钮成功");
                        that.refresh();
                    }else{
                        $webUtil.showErrorMsg(result.msg);
                    }
                },function (xhr,error) {
 
                },that.backPath);
            });
        };
        this.refresh = function(parentNodeOid){
            var that = this;
            var tree = layui.tree;
            if(parentNodeOid){
                tree.reloadNode("tree_" + that.id,parentNodeOid);
            }else {
                that.selectTreeOid = null;
                that.selectTreeAttribute = null;
                tree.reload("tree_" + that.id);
            }
        };
    };
    var cs = new Class();
    exports(cs.MODELNAME,cs);
});