田源
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
/**
 * 部门管理
 * @author weidy@2018-06-04
 * @constructor
 */
layui.define(['layer','element','form','table','tree'],function(exports){
    var Dept = function(){
        this.MODELNAME = "platform/orgs/orgsDepartment";
        this.moduleKey = "orgDept";
        this.id='orgDept';
        this.sourceData={};
        this.deptTree = null;
        this.deptForm = null;
        this.backPath = configData.compatibility?path:configData.frameworkPath;
        this.buttonIconMap = {};
        this.url={
            controller:'departmentController/',
            tree:'deptTree',
            add:'add',
            edit:'edit',
            checkIsDelete:'checkIsCanDelete',
            deleteUrl:'delete',
            disableUrl:'disable',
            enableUrl:"enable",
            referUser:'userQueryController/refDataGrid'
        };
        this.getContent=function(){
            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:280px;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,'" style="overflow-x: auto;"><ul>',
                '</div>',
                '<div class="layui-layout-border" style="display:block;margin-top:0px;margin-left:285px;">',
                '<div class="layui-center" style="overflow-y:auto;">',
                '<form class="layui-form" lay-filter="form_inPanel',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,'_STAR"><i class="layui-icon layui-icon-ok-circle"></i>启用</button>',
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_STOP"><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.controller + that.url.tree,
                backPath: that.backPath,
                extraParams: {
                    isMuti: false,
                    isQueryAllColumn: true
                },
                showSearch:true,
                click: function (item, elem, options) {
                    that.currentItemOid = item.oid;
                    that.currentItemAttributes = item.attributes;
                    that.setFormValues(that.currentItemAttributes);
                },
                done: function (thisFilter) {
                    that.initForm();
                }
            });
 
        };
        this.initForm = function(){
            var that = this;
            var form = layui.form;
            form.addItems("form_inPanel" + that.id, that.getFormItems(true), function () {
            }, {}, {
                defaultColumnOneRow: 1,
                labelWidth: 150,
                textWidth:240
            });
        };
        this.setFormValues = function (attributes) {
            var that = this;
            if(attributes){
                try{
                    var form = layui.form;
                    form.clear("form_inPanel" + that.id,true);
                    form.setValues(attributes,"form_inPanel" + that.id);//不需要转换对象,因为attributes已经是对象格式了
                }catch (e){
                    $webUtil.showDebugMsg(e);
                }
            }
        };
        this.getFormItems = function(onlyShow){
            var that = this;
            return [{
                field: 'id',
                text: '部门编号',
                required:true,
                readOnly: onlyShow
            }, {
                field: 'name',
                text: '部门名称',
                required:true,
                readOnly: onlyShow
            },{
                name:'departmentLevel',
                text:'部门级别',
                type:'combox',
                data:[{key:1,value:"业务单元/分厂"},{key:2,value:"部门"}]
            },{
                name:'pkLeader',
                text:'部门主管领导',
                type:'refer',
                showField:'pkLeaderName',
                readOnly: onlyShow,
                referConfig:{
                    type:layui.vciAlias.referRegister.userRefer
                }
            },{
                field:'pkFatherDepartment',
                text:'上级部门',
                type:'refer',
                showField: 'pkFatherDepartmentName',
                readOnly: onlyShow,
                referConfig:{
                    type:layui.vciAlias.referRegister.departmentRefer
                }
            },{
                name:'address',
                text:'部门位置',
                readOnly: onlyShow
            },{
                name:'tel',
                readOnly: onlyShow,
                text:'电话'
            },{
                name:'description',
                readOnly: onlyShow,
                text:'备注'
            },{
                field: 'lcStatusText',
                text: '状态',
                readOnly: true,
                hidden:!onlyShow
            }];
        };
        this.getUserReferColumns = function(){
            var table = layui.table;
           return [table.getIndexColumn(),table.getCheckColumn(),{
               field:'id',
               title:'用户名',
               width:120
           },{
               field:'name',
               title:'姓名',
               width:120
           },{
               field:'secretGradeText',
               title:'密级',
               width:90
           }];
        };
        this.ADD = function(){//保存
            var that = this;
            that.addOrEdit(true);
        };
        this.EDIT = function(){
            var that = this;
            that.addOrEdit(false);
        };
        this.addOrEdit = function (add) {
            var that = this;
 
            if(!add && $webUtil.isNull(that.currentItemOid)){
                $webUtil.showErrorMsg("请先选择一个部门");
                return false;
            }
            var filter = "addOrEdit_" + that.id;
            var form = layui.form;
            var addSaveIndex = layer.open({
                type: 1,
                title: add?'新增部门':'修改部门',
                btn: ['保存', '取消'],
                skin: 'layui-layer-lan',
                content: '<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
                area: ['900px', '500px'],
                closeBtn: 2,
                shade: true,
                shadeClose: true,
                resize: true,
                resizing: function (layero) {
                    form.doResize(filter);
                },
                success: function (layero) {
                    form.addItems(filter,that.getFormItems(false),
                        function () {
                            if(add){
                                //添加的时候,如果选择了节点,那么选择的节点就是当前的上级节点
                                if($webUtil.isNotNull(that.currentItemOid)){
                                    form.setValues({
                                        pkFatherDepartment:that.currentItemOid,
                                        pkFatherDepartmentName:(that.currentItemAttributes.id + " " + that.currentItemAttributes.name)
                                    },filter);
                                }else{
                                    form.setValues({},filter);
                                }
                            }else{
                                form.setValues(that.currentItemAttributes,filter);
                            }
                        }
                        , {}
                        , {
                            defaultColumnOneRow: 2,
                            labelWidth: 150,
                            textWidth:240
                        });
                },
                yes:function(layero){
                    if(form.validata(filter)){
                        var formValues = form.getValues(filter,true);
                        $webUtil.ajax(add?'post':'put',that.url.controller + (add?that.url.add:that.url.edit),formValues,function (result) {
                            if(result.success){
                                $webUtil.showMsgFromResult(result,add?"新增部门":"修改部门");
                                that.refresh(that.currentItemOid);
                                layer.close(addSaveIndex);
                            }else{
                                $webUtil.showErrorMsg(result.msg);
                            }
                        },function (xhr,error) {
                            $webUtil.showErrorMsg("访问服务器出现了错误,可能服务器没有开启,或者连接失败");
                        },that.backPath);
                    }
                },
                btn2:function(layero){
                    that.refresh();
                    layer.close()
                }
            });
        };
        this.DEL= function(){
            var that = this;
            if($webUtil.isNull(that.currentItemOid)){
                $webUtil.showErrorMsg("请先选择一个部门");
                return false;
            }
            var ts =  that.currentItemAttributes.ts;
            $webUtil.showConfirmMsg("是否删除这个部门?如果被用户等信息引用将不能被删除!",function () {
                var submitValue = {oid:that.currentItemOid,ts:ts};
                $webUtil.post(that.url.controller + that.url.checkIsDelete,submitValue,function(result){
                    if(result.success){
                        if('true' == result.obj || true == result.obj){
                            $webUtil.showConfirmMsg("当前分类包含有下级部门,要删除的话会和下级部门一起删除,你确认继续?",function () {
                                that.doDelete(submitValue);
                            });
                        }else{
                            //说明可以删除
                            that.doDelete(submitValue);
                        }
                    }else{
                        $webUtil.showErrorMsg(result.msg);
                    }
                },function (xhr,error) {
                    $webUtil.showErrorMsg("校验删除出现了错误,可能是服务器未启动")
                },that.backPath);
            });
        };
        this.doDelete = function (submitValue) {
            var that = this;
            $webUtil.deleteRequest(that.url.controller + that.url.deleteUrl,submitValue,function(result){
                if(result.success){
                    $webUtil.showMsgFromResult(result,"删除成功");
                    that.refresh();
                }else{
                    $webUtil.showErrorMsg(result.msg);
                }
            },function (xhr,err) {
                $webUtil.showErrorMsg("执行删除的时候出错了错误,可能是服务器暂时无法访问");
            },that.backPath);
        };
 
        this.STAR = function(){
            var that = this;
            if($webUtil.isNull(that.currentItemOid)){
                $webUtil.showErrorMsg("请先选择一个部门");
                return false;
            }
            that.operaData(that.url.controller +that.url.enableUrl,{oid:that.currentItemOid,ts:that.currentItemAttributes.ts},'启用成功')
        };
        this.STOP = function(){
            var that = this;
            if($webUtil.isNull(that.currentItemOid)){
                $webUtil.showErrorMsg("请先选择一个部门");
                return false;
            }
            that.operaData(that.url.controller +that.url.disableUrl,{oid:that.currentItemOid,ts:that.currentItemAttributes.ts},'停用成功')
        };
        this.operaData = function(url,submitValue,msg){
            var that = this;
            if($webUtil.isNull(that.currentItemOid)){
                return false;
            }
            that.showConfirmMsg("子节点是否一起操作?",function(){
                submitValue['cascade'] = true;
                $webUtil.post(url,submitValue,function(result){
                    if(result.success){
                        $webUtil.showMsgFromResult(result,msg);
                        that.refresh();
                    }else{
                        $webUtil.showErrorMsg(result.msg);
                    }
                },function (xhr,err) {
                    $webUtil.showErrorMsg("执行的时候出错了错误,可能是服务器暂时无法访问");
                },that.backPath)
            },function(){
                $webUtil.post(url,submitValue,function(result){
                    if(result.success){
                        $webUtil.showMsgFromResult(result,msg);
                        that.refresh();
                    }else{
                        $webUtil.showErrorMsg(result.msg);
                    }
                },function (xhr,err) {
                    $webUtil.showErrorMsg("执行的时候出错了错误,可能是服务器暂时无法访问");
                },that.backPath);
            });
        };
        this.showConfirmMsg = function (title,yes,cancel){
            layer.open($.extend({
                content: title,
                btn: ['是','否'],
                yes: yes,
                btn2: cancel
            }, {icon:3,title:'需要您确认'}));
        };
 
        this.refresh = function(parentNodeOid){
            var that = this;
            var tree = layui.tree;
            if($webUtil.isNotNull(parentNodeOid)){
                tree.reloadNode("tree_" + that.id,parentNodeOid);
            }else {
                tree.reload("tree_" + that.id);
            }
        };
    };
    var dept = new Dept();
    exports(dept.MODELNAME,dept);
});