田源
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
/**
 * 库房管理/仓库基本信息
 * @author weidy@2020/2/24
 * @constructor
 */
layui.define(['layer','element','form','table','tree','transfer'],function(exports){
    var Class = function(){
        this.MODELNAME = "platform/basedoc/BdWarehouse";
        this.moduleKey = "BdWarehouse";
        this.id='BdWarehouse';
        this.sourceData={};
        this.backPath = configData.compatibility?path:configData.frameworkPath;
        this.buttonIconMap = {};
        this.url={
            controller: 'warehouseController/',
            tree:'warehouseClassifyController/treeAllEnabledWarehouseClassify',
            referClassifyTree:'warehouseClassifyController/referTree',
            listWarehouseByClass:'gridWarehouseByClassify',
            listAdmin:'getAdminByWareHouseOid',
            referWarehouse:'refTree',
            add:'addWarehouse',
            edit:'editWarehouse',
            deleteUrl:'delWarehouse',
            enabled:'enableWarehouse',
            disabled:'disableWarehouse',
            unLinkUser:'userQueryController/refDataGrid',
            linkUser:'addWarehouseAdmin',
            removeLinkUser:'delWarehouseAdmin'
        };
        this.controllerSecret = configData.controllerSecret;
        this.columns = [];
        this.getContent=function(){//返回这个组件的基础html
            var that = this;
            var html = "";
            html = [
                    '<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;">',
                                that.getToolbarHtml(),
                                '<table id="table_',that.id ,'" lay-filter="', that.id ,'"></table>',
                            '</div>',
                            '<div class="layui-south" >',
                                that.getDetailToolbarHtml(),
                                '<table id="detail_table_',that.id ,'" lay-filter="detail_table_', that.id ,'"></table>',
                                '<div id="toolbar_column_',that.id ,'" style="display:none;"></div>',
                            '</div>',
                        '</div>',
                    '</div>'
            ].join("");
            return html;
        };
        this.getToolbarHtml = function(){
            var that =this;
            return ['<div layui-filter="toolbar_button_',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.getDetailToolbarHtml = function () {
            var that =this;
            return ['<div layui-filter="toolbar_detail_table_',that.id,'" class="layui-btn-container">',
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_detail_table_',that.id,'_LINKUSER"><i class="layui-icon layui-icon-add-1"></i>添加管理员</button>',
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_detail_table_',that.id,'_REMOVEUSER"><i class="layui-icon layui-icon-edit"></i>移除管理员</button>',
                '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_detail_table_',that.id,'_refreshUser"><i class="layui-icon layui-icon-refresh"></i>刷新</button>',
                '</div>'].join("");
        };
        this.init=function(){
            //基础的html被添加后,再执行初始化
            var that = this;
            that.firstTreeLoad =false;
            that.firstGridLoad = false;
            $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
                },
                loadType:layui.tree.loadType.all,
                showSearch:true,
                click: function (item, elem, options) {
                    that.currentItemOid = item.oid;
                    that.currentItemAttributes = item.attributes;
                    that.loadListByClassify();
                },
                done: function (thisFilter,result) {
                    that.currentItemOid = "";
                    if(result && result.length > 0){
                        that.currentItemOid = result[0].oid;
                    }
                    if(!that.firstTreeLoad) {
                        that.initMainTable();
                        that.firstTreeLoad = true;
                    }
                }
            });
        };
        this.initMainTable = function(callback){
            //加载主列表
            var that = this;
            var table = layui.table;
            that.checkColumns();//主列表中列。
            table.render({
                elem: '#table_' + that.id,
                id: 'table_' + that.id,
                url: that.backPath + that.url.controller + that.url.listWarehouseByClass,
                page: {
                    limit: 20,
                    page: 1
                },
                where:{
                    pkWarehouseClassify:that.currentItemOid
                },
                selectMode:table.selectMode.muti,
                cols: [that.columns],
                rowClick:function(filter,data){
                    if(data){
                        that.loadLinkAdmin(data.oid);
                    }
                },
                done:function(res, cur, count){
                    if(!that.firstGridLoad) {
                        that.initDetailTable((res && res.data) ? res.data[0] : "");
                        that.firstGridLoad = true;
                    }
                }
            });
            $webUtil.createSearchHtml({
                id:'库房编号',
                name:'库房名称'
            },$("[layui-filter='toolbar_button_" + that.id + "']"),'table_' + that.id);
            $webUtil.bindDefultButtonLisenter(that, "table_" + that.id);
        };
        this.loadListByClassify = function(){
            //加载右侧的表
            var that = this;
            if($webUtil.isNull(that.currentItemOid)){
                return;
            }
            layui.table.reload("table_" + that.id,{
                where:{
                    pkWarehouseClassify: that.currentItemOid
                }
            });
        };
        this.checkColumns = function(){
            var that = this;
            var table = layui.table;
            if(that.columns==null || that.columns.length==0){//如果其他地方想使用这个组件的时候,可以自定义列
                that.columns = [table.getIndexColumn(),table.getCheckColumn(),{
                    field:'id',
                    title:'库房编号',
                    width:150
                },{
                    field:'name',
                    title:'库房名称',
                    width:200
                },{
                    field:'address',
                    title:'库房地址',
                    width:150
                },{
                    field:'hearder',
                    title:'负责人',
                    width:80
                },{
                    field:'tel',
                    title:'联系电话',
                    width:120
                },{
                    field:'parentWarehouseText',
                    title:'上级库房',
                    width:150
                },{
                    field:'pkDepartmentName',
                    title:'管理部门',
                    width:150
                },{
                    field:'secretGradeText',
                    title:'密级',
                    width:90,
                    hidden:!that.controllerSecret
                },{
                    field:'lcStatusText',
                    title:'状态',
                    width:90
                }];
            }
        };
        this.checkDetailColumns = function () {
            var that = this;
            var table = layui.table;
            if(that.detailColumns==null || that.detailColumns.length==0){//如果其他地方想使用这个组件的时候,可以自定义列
                that.detailColumns = [table.getIndexColumn(),table.getCheckColumn(),{
                    field:'userId',
                    title:'用户名',
                    width:150
                },{
                    field:'userName',
                    title:'管理员姓名',
                    width:200
                },{
                    field:'options',
                    title:'操作',
                    toolbar: '#toolbar_column_' + that.id
                }];
            }
        };
        this.initDetailTable = function(wareHouseOid){
            var that = this;
            var table = layui.table;
            that.checkDetailColumns();//主列表中列。
            table.render({
                elem: '#detail_table_' + that.id,
                id: 'detail_table_' + that.id,
                url: that.backPath + that.url.controller +  that.url.listAdmin,
                where:{
                    wareHouseOid:wareHouseOid
                },
                width:550,
                selectMode:table.selectMode.muti,
                cols: [that.detailColumns],
                done:function (res,curr,count) {
                    table.on('tool(detail_table_' + that.id + ')',function(obj){
                        var data = obj.data;//当前选择行的数据
                        var layEvent = obj.event;//点的是什么按钮
                        if(layEvent == 'removeLinkPerson'){
                            that.doRemoveLinkPerson([data]);
                        }
                    });
                }
            });
            document.getElementById("toolbar_column_" + that.id).innerHTML = '<a class="layui-btn layui-btn-intable" lay-event="removeLinkPerson">移除</a>';
            $webUtil.bindDefultButtonLisenter(that, "detail_table_" + that.id);
        };
        this.loadLinkAdmin = function (warehouseOid) {
            var that = this;
            layui.table.reload('detail_table_' + that.id,{
                where:{
                    wareHouseOid:warehouseOid
                }
            });
        };
        this.ADD=function(){
            var that = this;
            that.addOrEdit(false);
        };
        this.EDIT = function () {
            var that = this;
            that.addOrEdit(true);
        };
        this.addOrEdit = function(edit){
            var that = this;
            var filter ="addForm_" + that.id;
            var form = layui.form;
            var oid;
            if(edit){
                //先获取数据
                 oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
                if(!oid){
                    return false;
                }
            }
            var selectRowData = layui.table.checkStatus("table_" + that.id);
            var addSaveIndex = layer.open({
                type:1,
                title:edit?'修改库房档案':'添加库房档案',
                btn:['保存','取消'],//,'保存新增'],
                skin:'layui-layer-lan',
                content:'<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
                area:['850px','510px'],
                closeBtn:2,
                shade:true,
                shadeClose:true,
                resize:true,
                resizing:function(layero){
                    form.doResize(filter);
                },
                success:function(layero){
                    form.addItems(filter,that.getFormItems(), function(){
                        //新增的时候,把左侧选择的节点需要添加在库房类别上
                        if(!edit) {
                            var values = {};
                            if($webUtil.isNotNull(that.currentItemOid) && that.currentItemAttributes){
                                values = {
                                    pkWarehouseClassify:that.currentItemAttributes.oid,
                                    pkWarehouseClassifyText:that.currentItemAttributes.name,
                                    warehouseClassifyId:that.currentItemAttributes.id
                                }
                            }
                            values['pkDepartment'] = $webUtil.getSystemVar($webUtil.systemValueKey.deptOid);
                            values['pkDepartmentName'] = $webUtil.getSystemVar($webUtil.systemValueKey.deptName);
                            form.setValues(values, filter);
                        }else{
                            //修改的时候就需要把整个数据添加进去
                            form.setValues(selectRowData.data[0], filter);
                        }
                    },{},{defaultColumnOneRow:2,inDialog:true});
                },
                yes:function(layero){
                    if(form.validata(filter)){
                        var values = form.getValues(filter,true);
                        $webUtil.ajax(edit?'put':'post',that.url.controller + (edit?that.url.edit:that.url.add),values,function(result){
                            if(result.success){
                                if($webUtil.isNull(result.msg)){
                                    result.msg = edit?"修改库房成功":'添加库房成功';
                                }
                                $webUtil.showMsg(result.msg);
                                layer.close(addSaveIndex);
                                that.refresh(that.currentItemOid);
                            }else{
                                $webUtil.showErrorMsg(result.msg);
                            }
                        },function (xhr,error) {
                            $webUtil.showErrorMsg("维护库房的信息的时候出现了错误");
                        },that.backPath);
                    }
                },
                btn2:function(layero){
                    layer.close(addSaveIndex);
                    that.refresh(that.currentItemOid);
                }
            });
        };
        this.DEL = function(){
            var that = this;
            var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
            if(!oid){
                return false;
            }
            $webUtil.showConfirmMsg("您确定要删除这个库房吗,如果库房中已经存在业务数据将不能被删除",function () {
                that.doOperaData(oid,that.url.controller + that.url.deleteUrl,'删除成功',true,true);
            });
        };
        this.ENABLE = function(){
            var that = this;
            var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
            if(!oid){
                return false;
            }
            $webUtil.showConfirmMsg("是否同时启用下级库房", function () {
                that.doOperaData(oid,that.url.controller + that.url.enabled,'启用成功', false, true);
            }, function () {
                that.doOperaData(oid,that.url.controller + that.url.enabled,'启用成功', false, false);
            });
        };
        this.DISABLE = function(){
            var that = this;
            var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
            if(!oid){
                return false;
            }
            $webUtil.showConfirmMsg("是否同时停用下级库房", function () {
                that.doOperaData(oid,that.url.controller + that.url.disabled,'停用成功', false, true);
            }, function () {
                that.doOperaData(oid,that.url.controller + that.url.disabled,'停用成功', false, false);
            });
        };
        this.doOperaData = function (oid,url,msg,deleteFlag,cascade) {
            var that = this;
            $webUtil.ajax(deleteFlag?'delete':'post',url,{
                oid:oid,
                cascade:cascade
            },function(result){
                if(result.success){
                    if($webUtil.isNull(result.msg)){
                        result.msg = msg;
                    }
                    $webUtil.showMsg(msg);
                    that.refresh(that.currentItemOid);
                }else{
                    $webUtil.showErrorMsg(result.msg);
                }
            },function(xhr,error){
                $webUtil.showErrorMsg("请求服务出现了错误,可能是因为服务器被关闭,网络连接失败或者程序错误");
            },that.backPath);
        };
        this.refresh = function(classifyOid,warehouseOid){
            var that = this;
            if($webUtil.isNull(classifyOid) && $webUtil.isNull(warehouseOid)){
                layui.tree.reload("tree_" + that.id);
                that.currentItemOid = null;
                that.currentItemAttributes = null;
            }
            if($webUtil.isNotNull(classifyOid)){
                layui.table.reload("table_" + that.id);
            }
            if($webUtil.isNotNull(warehouseOid)) {
                layui.table.reload("detail_table_" + that.id);
            }
        };
        this.getFormItems = function(){
            var that = this;
            return [{
                field: 'id',
                text: '库房编号',
                required:true
            }, {
                field: 'name',
                text: '库房名称',
                required:true
            },{
                field:'pkWarehouseClassify',
                text:'所属库房类别',
                type:'refer',
                required:true,
                showField:'pkWarehouseClassifyText',
                referConfig:{
                    type:'tree',
                    url: that.url.referClassifyTree,
                    backPath:that.backPath,
                    textField:'name',
                    valueField:'oid',
                    isMuti:false
                }
            }, {
                field: 'address',
                text: '库房地址'
            },{
                field:'hearder',
                text:'库房负责人'
            }, {
                field: 'tel',
                text: '联系电话'
            },{
                field: 'parentWarehouse',
                text: '上级库房',
                type:'refer',
                showField:'parentWarehouseText',
                referConfig:{
                    type:'tree',
                    url:that.url.controller + that.url.referWarehouse,
                    backPath:that.backPath,
                    textField:'id,name',
                    valueField:'oid',
                    extraParams: {
                        pkWarehouseClassify:that.currentItemOid
                    },
                    useFormKey:'pkWarehouseClassify',
                    isMuti:false
                }
            }, {
                field: 'pkDepartment',
                text: '管理部门',
                type:'refer',
                showField:'pkDepartmentName',
                referConfig:{
                    type:layui.vciAlias.referRegister.departmentRefer
                }
            },layui.vciWebComboxStore.getSecretObject(that.controlSecret)];
        };
        this.LINKUSER = function() {
            var that = this;
            //设置管理员
            var table = layui.table;
            var oid = $webUtil.getOidFromGrid("table_" +that.id,true,true);
            if(!oid){
                return false;
            }
            var sendPerIndex = layer.open({
                type:1,
                title:'选择管理员添加到库房',
                btn:['确定','取消'],
                skin:'layui-layer-lan',
                content:'<div id="inkperson_'+that.id+'" class="demo-transfer"></div>',
                area:['500px','610px'],
                closeBtn:2,
                shade:true,
                shadeClose:true,
                resize:false,
                yes:function(layero){
                    var getData = layui.transfer.getData('linkuser_'+that.id);
                    var userOids = [];
                    if(getData && getData.length > 0){
                        for(var i = 0 ; i < getData.length ; i ++){
                            var value = getData[i]["value"];
                            if(!value || value == "undefined"){
                                value = "";
                            }
                            userOids.push(value);
                        }
                    }
                    if(userOids.length == 0){
                        $webUtil.showAutoMsg("请先选择管理员后再点击【确定】按钮");
                        return false;
                    }
                    var submitValues = {
                        f_oid:oid
                    };
                    for(var i = 0 ; i < userOids.length ; i ++){
                        submitValues['t_oid[' + i + ']'] = userOids[i];
                    }
                    $webUtil.post(that.url.controller + that.url.linkUser,submitValues,function(result){
                        if(result.success){
                            if($webUtil.isNull(result.msg)){
                                result.msg = "添加管理员成功";
                            }
                            $webUtil.showMsg("添加管理员成功");
                            layer.close(sendPerIndex);
                            that.refresh(null,oid);
                        }else{
                            $webUtil.showErrorMsg(result.msg);
                        }
                    },function(xhr,err){
                        $webUtil.showErrorMsg("执行保存管理员的时候出现了错误");
                    },that.backPath);
                },
                btn2:function(index,layero){
                    layer.close(sendPerIndex);
                },
                success:function(layero){
                    //从后台获取到用户的信息,然后添加到穿梭框中
                    var linkedUsers = table.checkStatus("detail_table_" + that.id);
                    var queryMap = {
                        limit:-1
                    };
                    if(linkedUsers && linkedUsers.data && linkedUsers.data.length >0){
                        var linkedUserOids = [];
                        layui.each(linkedUsers.data,function(_index,_item){
                            linkedUserOids.push("'" + _item.toid + "'");
                        });
                        queryMap['conditionMap["oid"]'] = "\\NOTIN(" + linkedUserOids.join(",") + ")";
                    }
                    $webUtil.get( that.url.unLinkUser,queryMap,function(result){//获取穿梭框的管理员
                        if(result.success){
                            layui.transfer.render({
                                elem: '#inkperson_'+that.id
                                ,data: result.data
                                ,width:200
                                ,height:500
                                ,id:'linkuser_'+that.id//索引
                                ,parseData: function(res){
                                    return {
                                        "value": res.oid //数据值
                                        ,"title": (res.id + " " + res.name)//数据标题
                                    }
                                }
                                ,title: ['未选管理员', '已选管理员']
                                ,showSearch: true
                            })
                        }else{
                            $webUtil.showErrorMsg(result.msg);
                        }
                    },function(xhr,err){
                        $webUtil.showErrorMsg("执行保存管理员的时候出现了错误");
                    },that.backPath,true);
 
                }
            });
        };
        this.REMOVEUSER = function () {
            var that = this;
            var oid = $webUtil.getOidFromGrid("detail_table_" +that.id,true,false);
            if(!oid){
                return false;
            }
            var selectData = layui.table.checkStatus("detail_table_" +that.id);
            that.doRemoveLinkPerson(selectData.data);
        };
        this.doRemoveLinkPerson = function(records){
            var that = this;
            //执行移除,和最后一列显示的一样
            if(!records){
                return false;
            }
            if(!$webUtil.isArray(records)){
                records = [records];
            }
            var oids = "";
            layui.each(records,function(_index,_item){
                oids += _item.oid + ",";
            });
            oids = layui.util.removeComma(oids);
            $webUtil.showConfirmMsg("您是否确定移除这" + records.length + "个管理员?",function(){
                $webUtil.deleteRequest(that.url.controller +that.url.removeLinkUser,{warehouseAdminOids:oids},function(result){
                    if(result.success){
                        if($webUtil.isNull(result.msg)){
                            result.msg = "移除成功";
                        }
                        $webUtil.showMsg(result.msg);
                        that.refreshUser();
                    }else{
                        $webUtil.showErrorMsg(result.msg);
                    }
                },function(xhr,error){
                    $webUtil.showErrorMsg("移除管理员出错,可能是服务器无法连接")
                },that.backPath);
            });
        };
        this.refreshUser = function(){
            var that = this;
            layui.table.reload("detail_table_" + that.id);
        };
    };
    var c = new Class();
    exports(c.MODELNAME,c);
});