田源
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
/**
 * 货位管理
 * @author weidy@2020/2/24
 * @constructor
 */
layui.define(['layer','element','form','table','tree'],function(exports){
    var Class = function(){
        this.MODELNAME = "platform/basedoc/BdGoodsLocation";
        this.moduleKey = "BdGoodsLocation";
        this.id='BdGoodsLocation';
        this.sourceData={};//来源数据,需要至少包含type,如果没有则默认为批产
        this.columns = [];
        this.personColumns = [];
        this.backPath = configData.compatibility?path:configData.frameworkPath;//默认流程和项目的路径是一样的
        this.url={
            controller:"goodsLocationController/",
            referWarehouse:'warehouseController/refTree',//参照库房
            dataGrid:'getGoodsLocationByWarehouseOid',//列表数据和查询
            add:'addGoodsLocation',//添加货位
            edit:'editGoodsLocation',//编辑货位
            checkIsDelete:'checkIsCanDelete',//是否可以删除
            deleteUrl:'delGoodsLocation',//删除库房
            disable:'disableGoodsLocation',//停用
            enable:'enableGoodsLocation',//启用
            referUser:'userQueryController/refDataGrid'
        };
        this.getContent=function(){//返回这个组件的基础html
            var that = this;
            var html = "";
            html = [
                '<div class="layui-layout-border">',
                '<div style="width:250px;float: left;background-color:#ffffff">',
                '<label class="layui-icon layui-icon-tree" style="line-height: 20px;color:red;font-size:20px;">库房</label>',
                '<ul layui-filter="tree_',that.id,'" style="border:1px solid #6886ff;overflow-x:auto"><ul>',
                '</div>',
                '<div class="layui-layout" style="margin-left:255px;">',
                '<div class="layui-center">',
                that.getToolbarHtml(),
                '<table id="table_', that.id , '" lay-filter="',that.id , '" style="overflow-x:auto;"></table>',//主列表
                '</div>',
                '</div>',
                '</div>'
            ].join("");
            return html;
        };
        this.getToolbarHtml =function(){
            var that = this;
            var html = [
                '<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+ '_DELETE"><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("");
            return html;
        };
        this.init=function(){//基础的html被添加后,再执行初始化
            var that = this;
            that.firstTreeLoad =false;
            $webUtil.copyConfig(that,that.moduleKey);
            $webUtil.bindDefultButtonLisenter(that, that.id);
            //初始化树界面
            var filter= that.id;
            var scrollHeight =  window.innerHeight;
            var treeUL = $('[layui-filter="tree_' + filter + '"]');
            var treeHeight = scrollHeight - 200;
            treeUL.parent().height(treeHeight);
            layui.tree.init("tree_" + filter,$('[layui-filter="tree_' + filter + '"]'),{
                url:that.url.referWarehouse,
                backPath:that.backPath,
                showSearch:true,
                loadType:layui.tree.loadType.all,
                treeFilter:that.id,
                treeName:'goodLocations',
                click:function(item,elem,options){
                    that.currentItemOid = item.oid;
                    that.currentItemAttributes = item.attributes;
                    layui.table.reload("table_" + that.id,{
                        where:{
                            warehouseOid:that.currentItemOid
                        }
                    });
                },
                done:function (thisFilter,result) {
                    //loadType为all的时候才能用这个事件
                    that.currentItemOid = "";
                    if(result && result.length > 0){
                        that.currentItemOid = result[0].oid;
                    }
                    if(!that.firstTreeLoad) {
                        that.initMainTable();
                        that.firstTreeLoad = true;
                    }
                }
            });
        };
        this.initMainTable = function () {
            //初始化主列表
            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.dataGrid,
                page: {
                    limit: 30,
                    page: 1
                },
                where:{
                    warehouseOid:that.currentItemOid
                },
                cols: [that.columns],
                done: function (res, cur, count) {
                    if(res && res.data && res.data.length>0){
                        table.selectRecord('table_' + that.id,res.data[0]);
                    }
                }
            });
            $webUtil.createSearchHtml({
                id: '货位编号',
                name: '货位名称'
            }, $('[layui-filter="toolbar_' + that.id + '"]'), 'table_' + that.id);
        };
        this.ADD = function(){//保存
            var that = this;
            that.dealData(true);
        };
        this.EDIT = function(){
            var that = this;
            var oid = $webUtil.getOidFromGrid("table_" + that.id,true,true);
            if(!oid){
                return false;
            }
            that.dealData(false);
        };
        this.getFormItems = function(isEdit){
            var that = this;
            var table = layui.table;
            return [{
                type: 'text',
                name: 'id',
                text: '货位/货架编号',
                required: true
            }, {
                type: 'text',
                name: 'name',
                text: '货位/货架名称',
                required: true
            }, {
                type: 'refer',
                name: 'curators',
                text: '保管员',
                showField:'curators',
                referConfig:{
                    textField:'id,name',
                    valueField:'id,name',
                    type:'grid',
                    url: that.url.referUser,
                    backPath:that.backPath,
                    tableConfig:{
                        page:{
                            limit:15,
                            page:1
                        },
                        cols:[table.getIndexColumn(),table.getCheckColumn(),{
                            field:'id',
                            title:'用户名(账号)',
                            width:150
                        },{
                            field:'name',
                            title:'姓名',
                            width:150
                        },{
                            field:'usersecurity',
                            title:'密级',
                            width:80,
                            templet:function (d) {
                                return $webUtil.formateUserSecret(d.usersecurity);
                            }
                        }],
                        queryColumns:[{
                            field:'id',
                            title:'用户名(账号)'
                        },{
                            field:'name',
                            title:'姓名'
                        }]
                    }
                }
            },{
                type: 'text',
                name: 'outboundpriority',
                text: '出库优先级',
                verify:'number',
                minValue:1,
                maxValue:10,
                defaultValue:1,
                required: true
            }, {
                type: 'text',
                name: 'inboundpriority',
                text: '入库优先级',
                verify:'number',
                minValue:1,
                maxValue:10,
                defaultValue:1,
                required: true
            },{
                type:'text',
                name:'volume',
                text:'容积'
            },{
                name:'description',
                text:'描述',
                useAllWidth:true,
                width:570
            }];
        };
 
        this.dealData = function(add){
            var that = this;
            if($webUtil.isNull(that.currentItemOid)){
                $webUtil.showErrorMsg("请先选择库房节点");
                return false;
            }
            var form = layui.form;
            var filter ="form_" + that.id;
            var locationOids = $webUtil.getOidFromGrid("table_" + that.id,false,true);
            if(locationOids){
                var pkFatherGoodsLocation = $webUtil.getOidFromGrid("table_" + that.id,false,false,'pkFatherGoodsLocation');
                if(add && $webUtil.isNotNull(pkFatherGoodsLocation)){
                    $webUtil.showErrorMsg("货位上不能再添加下级货位;第一级为货架,货架的下级为货位");
                    return false;
                }
            }
            var title = "货架";
            if($webUtil.isNotNull(locationOids)){
                title = "货位";
            }
            var addSaveIndex = layer.open({
                type:1,
                title:add?('添加' + title):('修改' + title),
                btn:['保存','取消'],
                skin:'layui-layer-lan',
                content:'<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:5px" ></form>',
                area:['800px','500px'],
                closeBtn:2,
                shade:true,
                shadeClose:true,
                resize:true,
                resizing:function(layero){
                    form.doResize(filter);
                },
                success:function(layero) {
                    form.addItems(filter,that.getFormItems(),
                        function () {
                            if(!add){
                                //修改时直接设置值
                                var selectRowData = layui.table.checkStatus("table_" + that.id);
                                form.setValues(selectRowData.data[0],filter);
                            }else{
                                form.setValues({pkFatherGoodsLocation:locationOids},filter);
                            }
                        }, {}, {defaultColumnOneRow: 2});
                },
                yes:function(layero){
                    if(form.validata(filter)){
                        var values = form.getValues(filter,true);
                        values['pkWarehouse'] = that.currentItemOid;
                        var url = that.url.controller + (add?that.url.add:that.url.edit);
                        $webUtil.ajax(add?'post':'put',url,values,function(result){
                            if(result.success){
                                if($webUtil.isNull(result.msg)){
                                    result.msg = add?"添加成功":"修改成功";
                                }
                                $webUtil.showMsg(result.msg);
                                layer.close(addSaveIndex);
                                that.refresh();
                            }else{
                                $webUtil.showErrorMsg(result.msg);
                            }
                        },function(xhr,error){},that.backPath);
                    }
                },
                btn2:function(layero){
                    layer.close(addSaveIndex);
                    that.refresh();
                }
            });
        };
        this.DELETE = 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");
            var submitValues = {oid:oid,ts:ts};
            $webUtil.showConfirmMsg("是否删除这个货架/货位",function () {
                $webUtil.post(that.url.controller + that.url.checkIsDelete,submitValues,function(result){
                    if(result.success){
                        if('true' == result.obj || result.obj == true ){
                            $webUtil.showConfirmMsg("当前货架包含有下级货位,将会把下级货位一起删除,你确定要继续?",function () {
                                that.doDelete(submitValues);
                            });
                        }else{
                            that.doDelete(submitValues);
                        }
                    }else{
                        $webUtil.showErrorMsg(result.msg);
                    }
                },function (xhr,err) {
                    $webUtil.showErrorMsg("校验是否删除的时候出错了错误,可能是服务器暂时无法访问");
                },that.backPath);
            });
        };
        this.doDelete = function(submitValues) {
            var that = this;
            $webUtil.deleteRequest(that.url.controller + that.url.deleteUrl,submitValues,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;
            that.operaData(that.url.controller +that.url.enable,'启用成功')
        };
        this.STOP = function(){
            var that = this;
            that.operaData(that.url.controller +that.url.disable,'停用成功')
        };
        this.operaData = function(url,msg){
            var that = this;
            var oid = $webUtil.getOidFromGrid("table_" +that.id,true,true);
            if(!oid){
                return false;
            }
            $webUtil.showConfirmMsg("子节点是否一起操作?",function(){
                $webUtil.post(url,{
                    oid:oid,
                    children:true
                },function(result){
                    if(result.success){
                        $webUtil.showMsg(msg);
                        that.refresh();
                    }else{
                        $webUtil.showErrorMsg(result.msg);
                    }
                },function (xhr,err) {
                    $webUtil.showErrorMsg("执行的时候出错了错误,可能是服务器暂时无法访问");
                },that.backPath)
            },function(){
                $webUtil.post(url,{
                    oid:oid,
                    children:false
                },function(result){
                    if(result.success){
                        $webUtil.showMsg(msg);
                        that.refresh();
                    }else{
                        $webUtil.showErrorMsg(result.msg);
                    }
                },function (xhr,err) {
                    $webUtil.showErrorMsg("执行的时候出错了错误,可能是服务器暂时无法访问");
                },that.backPath);
            });
        };
        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:120
                },{
                    field:'name',
                    title:'货位/货架名称',
                    width:200
                },{
                    field:'curators',
                    title:'保管员',
                    width:100
                },{
                    field:'outboundpriority',
                    title:'出库优先级',
                    width:100
                },{
                    field:'inboundpriority',
                    title:'入库优先级',
                    width:100
                },{
                    field:'volume',
                    title:'容积',
                    width:100
                },{
                    field:'lcStatusText',
                    title:"状态",
                    width:100
                }];
            }
        };
        this.refresh = function(){
            var that = this;
            layui.table.reload("table_" + that.id);
        };
    };
    var c = new Class();
    exports(c.MODELNAME,c);
});