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
 
var GoodsManager = {
    GoodsGrid: undefined,
 
    Server: function () {
        var config = (function () {
            var URL_GetList = "/GoodsPosAjax/GetList";
            var URL_Lock = "/GoodsPosAjax/GetGoodsPosLock";
            var URL_Add = "/GoodsPosAjax/AddGoods"; 
            var URL_Property = "/GoodsPosAjax/GetGoodsPosProperty";
            var URL_Print = "/GoodsPosAjax/PrintBarCode";       // 打印库位
            var URL_PrintTray = "/GoodsPosAjax/PrintTrayBarCode";       // 批量打印托盘
 
            return {
                URL_GetList: URL_GetList,
                URL_Lock: URL_Lock,
                URL_Add: URL_Add,
                URL_Property: URL_Property,
                URL_Print: URL_Print,
                URL_PrintTray: URL_PrintTray,
            };
        })();
 
        //数据操作服务
        var dataServer = (function ($, config) {
 
            //查询分页列表
            var GetList = function (data, callback) {
                $.gitAjax({
                    url: config.URL_GetList,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var Lock = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Lock,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
            // 打印货位
            var PrintBarCode = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Print,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
            // 打印托盘
            var PrintTrayBarCode = function (data, callback) {
                $.gitAjax({
                    url: config.URL_PrintTray,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var Property = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Property,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var Add = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Add,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            return {
                GetList: GetList,
                Lock: Lock,
                Property: Property,
                Add: Add,
                PrintBarCode: PrintBarCode,
                PrintTrayBarCode: PrintTrayBarCode,
            }
 
        })($, config);
        return dataServer;
    },
 
    Dialog: function (Addre, Command) {
        var submit = function (v, h, f) {
            if (v) {
                var Property = h.find('select[name="property"]').val();
                if (git.IsEmpty(Property)) {
                    $.jBox.tip("请选择库位属性", "warn");
                    return false;
                }
 
                var statu = h.find('select[name="statu"]').val();
                if (git.IsEmpty(statu)) {
                    $.jBox.tip("请选择库位状态", "warn");
                    return false;
                }
                var Alock = h.find('select[name="Alock"]').val();
                if (git.IsEmpty(Alock)) {
                    $.jBox.tip("请选择库位锁定状态", "warn");
                    return false;
                }
 
                var Demo = h.find('input[name="Demo"]').val();
 
                var param = {};
                param["Operation"] = Command;
                param["Area"] = Addre;
                param["Property"] = Property;
                param["statu"] = statu;
                param["Alock"] = Alock;
                param["Demo"] = Demo;
 
                var Server = GoodsManager.Server();
                Server.Add(param, function (result) {
                    if (result.Code == 1) {
                        var pageSize = $("#mypager").pager("GetPageSize");
                        var pageIndex = $("#mypager").pager("GetCurrent");
 
                        if (Command == "Add") {
                            GoodsManager.PageClick(pageIndex, pageSize);
                        } else if (Command == "Edit") {
                          
                            GoodsManager.Refresh();
                            //$.jBox.tip(result.Message, "warn");     // 库位编辑成功哦那个! 提示
                        }
                    } else {
                        $.jBox.tip(result.Message, "warn");
                    }
                });
 
                // liudl 注释
                //Server.Property(param, function (result) {
                //    if (result.Code == 1) {
                //        $.jBox.tip(result.Message, "info");
 
 
                //        var pageSize = $("#mypager").pager("GetPageSize");
                //        var pageIndex = $("#mypager").pager("GetCurrent");
                //        GoodsManager.PageClick(pageIndex, pageSize);
                //    } else {
                //        //$.jBox.tip(result.Message, "warn");    // 提示空提示
                //    }
                //});
            }
        }
 
        //窗体加载完成回调事件 
        var loaded = function (h)
        {
          
            // 设置禁止更改列
            h.find('select[name="Area"]').attr("disabled", "disabled");
            h.find('select[name="pai"]').attr("disabled", "disabled");                     // 库区编码 总排 列 行 禁止编辑
            h.find('select[name="lie"]').attr("disabled", "disabled");
            h.find('select[name="ceng"]').attr("disabled", "disabled");
        }
 
        if (Command == "Property") {
            $.jBox.open("get:/BasicInfo/GoodsPos/SetProperty", "设定库位属性", 650, 200, { buttons: { "确定": true, "取消": false }, submit: submit });
        } if (Command == "Add") {
            $.jBox.open("get:/BasicInfo/GoodsPos/AddGoods", "新增库位信息", 400, 500, { buttons: { "确定": true, "关闭": false }, submit: submit });
        } else if (Command == "Edit") {
            $.jBox.open("get:/BasicInfo/GoodsPos/AddGoods?Addre=" + Addre, "编辑库位信息", 400, 500, { buttons: { "确定": true, "关闭": false }, submit: submit });
        }
    },
 
    PageClick: function (PageIndex, PageSize) {
        $.jBox.tip("正在努力加载数据...", "loading");
 
        var Server = GoodsManager.Server();       // 绑定方法
        var search = GoodsManager.GetSearch();      // 加载视图过滤条件
        search["PageIndex"] = PageIndex;
        search["PageSize"] = PageSize;
        console.log(JSON.stringify(search));
        Server.GetList(search, function (result) {
            GoodsManager.SetTable(result);
            $.jBox.closeTip();
        });
    },
 
    Refresh: function () {
        var PageSize = $("#mypager").pager("GetPageSize");
        var PageIndex = $("#mypager").pager("GetCurrent");
        $.jBox.tip("正在努力加载数据...", "loading");
 
        var Server = GoodsManager.Server();
        var search = GoodsManager.GetSearch();
        search["PageIndex"] = PageIndex;
        search["PageSize"] = PageSize;
        Server.GetList(search, function (result) {
            GoodsManager.SetTable(result);
            $.jBox.closeTip();
        });
    },
 
    SetTable: function (result) {
        var cols = [
            {
                title: '库区', name: 'Area', width: 90, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '货位地址', name: 'Addre', width: 110, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '排', name: 'pai', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '列', name: 'lie', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '层', name: 'ceng', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '货位属性', name: 'property', width: 100, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
 
            {
                title: '货位状态', name: 'statu', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '锁定状态', name: 'ALock', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },    
            {
                title: '备注', name: 'Demo', width: 120, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '操作', name: 'ID', width: 180, align: 'left', lockWidth: false, renderer: function (data, item, rowIndex) {
                    var html = "";
                    html += '<a class="print" href="javascript:void(0)">打印</a>&nbsp;&nbsp;';
                    html += '<a class="printTray" href="javascript:void(0)">打印托盘码</a>&nbsp;&nbsp;';
                    return html;
                }
            },
        ];
 
        if (this.GoodsGrid == undefined) {
            var ht = masterUI.MMGridHeight();
            this.GoodsGrid = $("#tabList").mmGrid({
                cols: cols,                     // 定义表头
                items: result.Result.List,
                checkCol: true,                 // 是否显示选择框
                nowrap: true,
                remoteSort: true,
                multiSelect: false,              // 单选 / 多选 默认单选
                // indexCol: true,               // 增加索引列
                height: ht
            });
 
            //绑定事件
            GoodsManager.BindEvent();
        } else {
            this.GoodsGrid.load(result.Result.List);
        }
        var pageInfo = result.PageInfo;
        if (pageInfo != undefined) {
            $("#mypager").pager({ pagenumber: pageInfo.PageIndex, recordCount: pageInfo.RowCount, pageSize: pageInfo.PageSize, buttonClickCallback: GoodsManager.PageClick });
        }
    },
 
    BindEvent: function () {
        this.GoodsGrid.on('loadSuccess', function (e, data) {
            LoadBtn.SetBtn();
        });
 
        this.GoodsGrid.off("cellSelected").on("cellSelected", function (e, item, rowIndex, colIndex) {
            // 编辑绑定生成库位事件
            if ($(e.target).is("a.print")) {
                var Addre = item.Addre;
                var submit = function (v, h, f) {
                    if (v == "ok") {
                        var list = [];
                        list.push(Addre);
                        var param = {};
                        param["list"] = JSON.stringify(list);
                        var Server = GoodsManager.Server();
                        Server.PrintBarCode(param, function (result) {
                            // 此方法内的执行顺序是由下往上。
                            // 刷新页面
                            var pageSize = $("#mypager").pager("GetPageSize");
                            GoodsManager.PageClick(1, pageSize);
 
                            $.jBox.tip(result.Message, "warn");     // 条形码打印完毕! 提示
                        });
                    }
                }
                $.jBox.confirm("打印 " + Addre + " 库位条形码?", "提示", submit);
            }
            else if ($(e.target).is("a.printTray"))
            {
                var Addre = item.Addre;
                var submit = function (v, h, f) {
                    if (v == "ok") {
                        var list = [];
                        list.push(Addre);
                        var param = {};
                        param["list"] = JSON.stringify(list);
                        var Server = GoodsManager.Server();
                        Server.PrintTrayBarCode(param, function (result) {
                            // 此方法内的执行顺序是由下往上。
                            // 刷新页面
                            var pageSize = $("#mypager").pager("GetPageSize");
                            GoodsManager.PageClick(1, pageSize);
 
                            $.jBox.tip(result.Message, "warn");     // 条形码打印完毕! 提示
                        });
                    }
                }
                $.jBox.confirm("批量打印 " + Addre + " 库位中所有托盘条形码?", "提示", submit);
            }
        });
    },
 
    GetSelect: function () {
        var list = [];
        if (this.GoodsGrid != undefined) {
            var rows = this.GoodsGrid.selectedRows();
            if (rows != undefined && rows.length > 0) {
                for (var i = 0; i < rows.length; i++) {
                    list.push(rows[i].Addre);
                }
            }
        }
        return list;
    },
 
    GetSearch: function () {
        // 获取下拉框值
        var searchBar = $("div[data-condition='search']");
        var pai = searchBar.find("select[name='pai']").val();
        var lie = searchBar.find("select[name='lie']").val();
        var ceng = searchBar.find("select[name='ceng']").val();
        var area = searchBar.find("select[name='Area']").val();
        var statu = searchBar.find("select[name='statu']").val();
        var property = searchBar.find("select[name='property']").val();
        var Alock = searchBar.find("select[name='Alock']").val();
 
        var search = {};
        search["pai"] = pai;
        search["lie"] = lie;
        search["ceng"] = ceng;
        search["area"] = area;
        search["statu"] = statu;
        search["property"] = property;
        search["Alock"] = Alock;
 
        return search;
    },
 
    ToolBar: function () {
        //工具栏按钮点击事件
        $("div.toolbar").find("a.btn").click(function () {
            var command = $(this).attr("data-command");
 
            if (command == "Lock") {
                var list = GoodsManager.GetSelect();
                if (list.length == 0) {
                    $.jBox.tip("请选择要锁定的货位", "warn");
                    return false;
                }
 
                var param = {};
                param["list"] = JSON.stringify(list);
 
                param["Operation"] = "Lock";
 
                var Server = GoodsManager.Server();
                Server.Lock(param, function (result) {
                    $.jBox.tip(result.Message, "success");
 
                    var pageSize = $("#mypager").pager("GetPageSize");
                    GoodsManager.PageClick(1, pageSize);
                });
 
            }
            else if (command == "Unlock") {
                var list = GoodsManager.GetSelect();
                if (list.length == 0) {
                    $.jBox.tip("请选择要解锁的货位", "warn");
                    return false;
                }
                var param = {};
                param["list"] = JSON.stringify(list);
 
                param["Operation"] = "UnLock";
 
                var Server = GoodsManager.Server();
                Server.Lock(param, function (result) {
                    $.jBox.tip(result.Message, "success");
 
                    var pageSize = $("#mypager").pager("GetPageSize");
                    GoodsManager.PageClick(1, pageSize);
                });
            }
            else if (command == "Property") {
                var list = GoodsManager.GetSelect();
                if (list.length == 0) {
                    $.jBox.tip("请选择要设定属性的库位", "warn");
                    return false;
                }
                //var param = {};
                //param["list"] = JSON.stringify(list);
                GoodsManager.Dialog(list, "Property")
            }
            else if (command == "Add") {
                GoodsManager.Dialog(undefined, command);
            }
            // 编辑库位属性
            else if (command == "Edit")                     
            {
                var list = GoodsManager.GetSelect();
                if (list.length == 0) {
                    $.jBox.tip("请选择要编辑的项", "warn");
                    return false;
                }
                var GoodsPos = list[0];
                GoodsManager.Dialog(GoodsPos, command);
            }
        });
 
        //搜索
        var searchBar = $("div[data-condition='search']");
        searchBar.find("a[data-command='search']").click(function () {
            GoodsManager.PageClick(1, 10);
        });
 
        // 下拉框选择事件
        $("#areaid").change(function () {
            var areaid = ($(this).val());       // 获取库区编码
            if (areaid != "") {
                $.gitAjax({
                    url: "/GoodsPosAjax/BindOption",
                    data: { ajaxdata: areaid },
                    type: "post",
                    dataType: "json",
                    success: function (result) {            // result = 后台返回值
                        if (result != null)
                        {
                            // 清空下拉框选项 重新赋值 
                            $("#paiid").empty();
                            $("#paiid").html(result.pai);
                            $("#lieid").empty();
                            $("#lieid").html(result.lie);
                            $("#cengid").empty();
                            $("#cengid").html(result.ceng);
                        }
                    }
                })
            }
        });
 
        //监听回车事件,用于扫描
        $("input[name='pai']").keydown(function (event)
        {
            if (event.keyCode == 13) {
                var value = $(this).val();
                if (!git.IsEmpty(value)) {
                    GoodsManager.PageClick(1, 10);
                    setTimeout(function () {
                        $("input[name='pai']").val("");
                        $("input[name='pai']").focus();
                    }, 300);
                }
            }
        });
 
        $("input[name='pai']").focus();
        //加载默认数据
        GoodsManager.PageClick(1, 10);
    }
};