bklLiudl
2024-07-23 277bbae216debe7e6c04e8cc6ee6e1ba9763e14b
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
var DepotsLocation = {
    InTable: undefined,
    // 查询
    PageClick: function (PageIndex, PageSize) {
        $.jBox.tip("正在努力加载数据...", "loading");
        var search = DepotsLocation.GetSearch();
        search["PageIndex"] = PageIndex;
        search["PageSize"] = PageSize;
 
        $.gitAjax({
            async: false,
            url: "/DLocationAjax/GetDLocationItems",
            data: { ajaxdata: JSON.stringify(search) },
            type: "post",
            dataType: "json",
            success: function (result) {
                $.jBox.closeTip();
                if (result != null) {
                    if (result.Code == 1) {
                        // 查询成功,绑定Table
                        DepotsLocation.SetTable(result);
                    }
                    else {
                        // 查询失败,提示操作员
                        $.jBox.tip(result.Message, "warn");
                    }
                }
            }
        });
    },
 
    // 加载Table表格
    SetTable: function (result) {
        // 定义Table列
        var cols = [
            {
                title: '库位编码', name: 'LocationCode', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '所属库区', name: 'DepotsAreaName', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '库排', name: 'LRow', width: 90, hidden:'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '库列', name: 'LColumn', width: 90, hidden: 'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '库层', name: 'LLayer', width: 90, hidden: 'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '库位属性', name: 'Property', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '库位状态', name: 'TurnoverDemand', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '库位类型', name: 'Type', width: 110, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '重量限制', name: 'Weight', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '体积限制', name: 'Volume', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '长', name: 'Long', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '宽', name: 'Width', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '高', name: 'Height', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '层数', name: 'NumPlies', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '混放产品', name: 'IsProduct', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    var html = "";
                    if (data == 0) {
                        html += '<input type="checkbox" checked="checked"/>';
                    }
                    else {
                        html += '<input type="checkbox" />';
                    }
 
                    return html;
                }
            },
            {
                title: '混放批次', name: 'IsBatch', width: 90, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    var html = "";
                    if (data == 0) {
                        html += '<input type="checkbox" checked="checked"/>';
                    }
                    else {
                        html += '<input type="checkbox" />';
                    }
 
                    return html;
                }
            },
            {
                title: '备注', name: 'Demo', width: 120, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '创建日期', name: 'CreatTime', width: 130, hidden: 'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
 
                    return git.JsonToDateTimeto(data);
                }
            },
            {
                title: '创建人', name: 'CreatUser', width: 80, hidden: 'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '修改日期', name: 'UpdateTime', width: 130, hidden: 'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return git.JsonToDateTimeto(data);
                }
            },
            {
                title: '修改人', name: 'UpdateUser', width: 80, hidden: 'true', align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '操作', name: 'Guid', width: 80, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    var html = "";
                    html += '<a class="edit dis" href="javascript:void(0)">编辑</a>&nbsp;&nbsp;';
                    return html;
                }
            },
        ];
 
        // 设置Table
        if (this.InTable == undefined) {
            var ht = masterUI.MMGridHeight();
            this.InTable = $("#tabList").mmGrid({
                cols: cols,
                sortName: 'CreateTime',
                sortStatus: 'desc',
                fullWidthRows: true,
                multiSelect: true,
                //indexCol: true,
                items: result.Result.List,
                checkCol: true,
                nowrap: true,
                height: ht
            });
 
            //绑定事件
            DepotsLocation.BindEvent();
        }
        else {
            this.InTable.load(result.Result.List);
        }
 
        // 绑定分页信息,切换分页调用查询方法
        var pageInfo = result.PageInfo;
        if (pageInfo != undefined) {
            $("#mypager").pager({ pagenumber: pageInfo.PageIndex, recordCount: pageInfo.RowCount, pageSize: pageInfo.PageSize, buttonClickCallback: DepotsLocation.PageClick });
        }
    },
 
    // 绑定行事件
    BindEvent: function () {
        this.InTable.on('loadSuccess', function (e, data) {     //loadSuccess
            LoadBtn.SetBtn();
        });
 
        this.InTable.off("cellSelected").on("cellSelected", function (e, item, rowIndex, colIndex) {
            // 绑定编辑库区事件
            if ($(e.target).is("a.edit")) {
                var Guid = item.Guid;
                $.gitAjax({
                    url: "/DLocationAjax/CheckDepartment",
                    data: { ajaxdata: Guid },
                    type: "post",
                    dataType: "json",
                    async: false,
                    success: function (result) {
                        if (result.Code == '1') {
                            $.jBox.tip("该库位别的部门已使用,不可修改!", "warn");
                            return false;
                        }
                    }
                });
                DepotsLocation.Dialog(Guid, "Edit");
            }
        });
    },
 
    // 获取查询条件
    GetSearch: function () {
        var search = {};
        var searchBar = $("div[data-condition='search']");
        search["DepotsAreaID"] = searchBar.find("select[name='DepotsArea']").val();
        var LRow = searchBar.find("select[name='DepotsRow']").val();
        var LColumn = searchBar.find("select[name='DepotsColumn']").val();
        var LLayer = searchBar.find("select[name='DepotsLayer']").val();
 
        search["LRow"] = 0;
        if (LRow.length > 0)
        {
            search["LRow"] = LRow;
            
        }
        search["LColumn"] = 0;
        if (LColumn.length > 0) {
            search["LColumn"] = LColumn;
 
        }
        search["LLayer"] = 0;
        if (LLayer.length > 0) {
            search["LLayer"] = LLayer;
 
        }
 
        search["LocationCode"] = searchBar.find("input[name='LocationCode']").val();
        search["PropertyID"] = searchBar.find("select[name='Property']").val();
        search["TurnoverDemandID"] = searchBar.find("select[name='TurnoverDemand']").val();
        search["TypeID"] = searchBar.find("select[name='Type']").val();
 
        return search;
    },
 
    // 获取Table选中行
    GetSelect: function () {
        var list = [];
        if (this.InTable != undefined) {
            var rows = this.InTable.selectedRows();
            if (rows != undefined && rows.length > 0) {
                for (var i = 0; i < rows.length; i++) {
                    list.push(rows[i].Guid);
                    
                }
            }
        }
        return list;
    },
 
    // Add Edit 窗体赋值
    Dialog: function (Guid, Command) {
        var submit = function (v, h, f) {
            if (v) {     
                var param = validation(h);
                param["Guid"] = Guid;
                $.gitAjax({
                    url: "/DLocationAjax/SetDLocations",
                    data: { ajaxdata: JSON.stringify(param) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (result.Code == 1) {
                            $.jBox.tip(result.Message, "info");
                            var pageSize = $("#mypager").pager("GetPageSize");
                            var pageIndex = $("#mypager").pager("GetCurrent");
                            DepotsLocation.PageClick(pageIndex, pageSize);
                        }
                        else {
                            $.jBox.tip(result.Message, "warn");
                        }
                    }
                });
            }
        }
 
        var validation = function (h) {
            var param = {};
            param["LRow"] = h.find('select[name = "LRow"]').val();                          // 库排
            param["LColumn"] = h.find('select[name = "LColumn"]').val();                    // 库列
            param["DepotsArea"] = h.find('select[name = "DepotsArea"]').val();              // 库区
            param["LLayer"] = h.find('select[name = "LLayer"]').val();                      // 库层
            param["Type"] = h.find('select[name="Type"]').val();                            // 库位类型
            param["Property"] = h.find('select[name="Property"]').val();                    // 库位属性
            param["TurnoverDemand"] = h.find('select[name="TurnoverDemand"]').val();        // 库位状态
 
            param["Weight"] = h.find("input[name='Weight']").val();                         // 重量限制
            param["Volume"] = h.find("input[name='Volume']").val();                         // 体积限制
            param["Long"] = h.find("input[name='Long']").val();                             // 长
            param["Width"] = h.find("input[name='Width']").val();                           // 宽
            param["Height"] = h.find("input[name='Height']").val();                         // 高
            param["NumPlies"] = h.find("input[name='NumPlies']").val();                     // 层
            param["Demo"] = h.find("input[name='Demo']").val();                             // 备注
            param["IsBatch"] = "1";                                                         // 混放批次
            param["IsProduct"] = "1";                                                       // 混放产品
            if ($("#IsBatch").prop('checked')){
                param["IsBatch"] = "0";
            }
            if ($("#IsProduct").prop('checked')){
                param["IsProduct"] = "0";
            }
 
            if (git.IsEmpty(param["Type"])) {
                $.jBox.tip("请选择库位类型!", "warn");
                return;
            }
            if (git.IsEmpty(param["Property"])){
                $.jBox.tip("请选择库位属性!", "warn");
                return;
            }
            if (git.IsEmpty(param["TurnoverDemand"])) {
                $.jBox.tip("请选择库位状态!", "warn");
                return;
            }
 
            var regPos = /^[+-]?(0|([1-9]\d*))(\.\d+)?$/;          // 正则 数字
            var regex = /^[0]+/;
 
            var Weight = param["Weight"].replace(regex, "");
            if (!regPos.test(Weight) || git.IsEmpty(Weight))
            {
                $.jBox.tip("重量限制应为数字!", "warn");
                return;
            }
 
            //var Volume = param["Volume"].replace(regex, "");
            if (!regPos.test(param["Volume"]) || git.IsEmpty(param["Volume"])) {
                $.jBox.tip("体积限制应为数字!", "warn");
                return;
            }
 
            var Long = param["Long"].replace(regex, "");
            if (!regPos.test(Long) || git.IsEmpty(Long)) {
                $.jBox.tip("长应为数字!", "warn");
                return;
            }
            var Width = param["Width"].replace(regex, "");
            if (!regPos.test(Width) || git.IsEmpty(Width)) {
                $.jBox.tip("宽应为数字!", "warn");
                return;
            }
            var Height = param["Height"].replace(regex, "");
            if (!regPos.test(Height) || git.IsEmpty(Height)) {
                $.jBox.tip("高应为数字!", "warn");
                return;
            }
 
 
            return param;
        }
 
        //窗体加载完成回调事件 
        var loaded = function (h) {
            // 设置禁止更改列
            h.find('input[name="LocationCode"]').attr("disabled", "disabled"); 
            h.find('input[name="NumPlies"]').attr("disabled", "disabled"); 
            h.find('select[name = "DepotsArea"]').attr("disabled", "disabled");
            h.find('select[name = "LRow"]').attr("disabled", "disabled");
            h.find('select[name = "LColumn"]').attr("disabled", "disabled");
            h.find('select[name = "LLayer"]').attr("disabled", "disabled");    
        } 
 
        switch (Command) {
            case "Add":
                $.jBox.open("get:/BasicInfo/DepotsLocation/AddEdit", "新增库位", 600, 450, { buttons: { "确定": true, "关闭": false },top:'5%', submit: submit });
                break;
            case "Edit":
                $.jBox.open("get:/BasicInfo/DepotsLocation/AddEdit?Guid=" + Guid, "编辑库位", 600, 450, { buttons: { "确定": true, "关闭": false }, submit: submit, loaded: loaded });
                break;
            default: break;
        }
    },
 
    // view页操作响应
    ToolBar: function () {
 
        var btnClick = $("div.toolbar");
        btnClick.find("a.btn").click(function () {
            var command = $(this).attr("data-command");
            switch (command) {
                case "Add":
                    var list = DepotsLocation.Dialog("", "Add");
                    break;
                case "Del":
                    var submit = function (v, h, f) {
                        if (v == "ok") {
                            var list = DepotsLocation.GetSelect();
                            if (list.length == 0) {
                                $.jBox.tip("请选择要删除的项", "warn");
                                return false;
                            }
                            var param = {};
                            param["list"] = JSON.stringify(list);
 
                            $.gitAjax({
                                url: "/DLocationAjax/DelLocations",
                                data: param,
                                type: "post",
                                dataType: "json",
                                success: function (result) {
                                    // 提示操作信息
                                    $.jBox.tip(result.Message, "success");
 
                                    var pageSize = $("#mypager").pager("GetPageSize");
                                    DepotsLocation.PageClick(1, pageSize);
                                }
                            });
                        }
                    }
                    $.jBox.confirm("确定要删除吗?", "提示", submit);
                    break;
                case "Edits":
                    var list = DepotsLocation.GetSelect();
                    if (list.length == 0) {
                        $.jBox.tip("请选择要编辑的项", "warn");
                        return false;
                    }
 
                    for (i = list.length - 1; i >= 0; i--) {
                        console.log(i)
                        $.gitAjax({
                            url: "/DLocationAjax/CheckDepartment",
                            data: { ajaxdata: list[i]},
                            type: "post",
                            dataType: "json",
                            async: false ,
                            success: function (result) {
                                if (result.Code == '1') {
                                    list.pop();
                                    $.jBox.tip("已自动移除别的部门占用的库位!", "warn");
                                }
                            }
                        });
                    }
                    if (list.length == 0) {
                        $.jBox.tip("请选择本部门占用储位!", "warn");
                        return false;
                    }
 
                    var param = {};
                    param["list"] = JSON.stringify(list);
                    $.gitAjax({
                        url: "/DLocationAjax/SetLocationsSeession",
                        data: param,
                        type: "post",
                        dataType: "json",
                        success: function (result) {
                            // 提示操作信息
                            //$.jBox.tip(result.Message, "success");
 
                           // var pageSize = $("#mypager").pager("GetPageSize");
                            //DepotsArea.PageClick(1, pageSize);
                        }
                    });
 
 
                    var Guid = list[0];
                    DepotsLocation.Dialog(Guid, "Edit");
                    break;
                default: break;
            }
 
        })
 
        // 搜索按钮绑定查询事件  获取div => div.find事件搜寻按钮 => click事件
        var searchBar = $("div[data-condition='search']");
        searchBar.find("a[data-command='search']").click(function () {
            // 调用查询方法,绑定分页信息
            DepotsLocation.PageClick(1, 50);
        });
 
 
        $("#Region").change(function () {
            var Region = ($(this).val());       // 获取库区编码
           
            if (Region != "") {
                $.gitAjax({
                    url: "/DLocationAjax/BindOption",
                    data: { ajaxdata: Region, opertype:"Region"},
                    type: "post",
                    dataType: "json",
                    success: function (result) {            // result = 后台返回值
                        if (result != null) {
                            // 清空下拉框选项 重新赋值 
                            $("#DepotsArea").empty();
                            $("#DepotsArea").html(result.DepotsArea);
                            $("#DepotsRow").empty();
                            $("#DepotsColumn").empty();
                            $("#DepotsLayer").empty();
                        }
                    }
                })
            }
        });
 
        $("#DepotsArea").change(function () {
            var DepotsArea = ($(this).val());       // 获取库区编码       
            if (DepotsArea != "") {
                $.gitAjax({
                    url: "/DLocationAjax/BindOption",
                    data: { ajaxdata: DepotsArea, opertype: ""},
                    type: "post",
                    dataType: "json",
                    success: function (result) {            // result = 后台返回值
                        if (result != null) {
                            // 清空下拉框选项 重新赋值 
                            $("#DepotsRow").empty();
                            $("#DepotsRow").html(result.DepotsRow);
                            $("#DepotsColumn").empty();
                            $("#DepotsColumn").html(result.DepotsColumn);
                            $("#DepotsLayer").empty();
                            $("#DepotsLayer").html(result.DepotsLayer);
                        }
                    }
                })
            }
        });
 
        //监听回车事件,用于扫描
        searchBar.find("input[name='DepotsCode']").keydown(function (event) {
            if (event.keyCode == 13) {
                var value = $(this).val();
                if (!git.IsEmpty(value)) {
                    DepotsLocation.PageClick(1, 50);
 
                    setTimeout(function () {
                        searchBar.find("input[name='DepotsCode']").val("");
                        searchBar.find("input[name='DepotsCode']").focus();
                    }, 300);
                }
            }
        });
 
        //窗体加载获得焦点
        searchBar.find("input[name='DepotsCode']").focus();
 
        //加载默认数据
        DepotsLocation.PageClick(1, 50);
    }
}