chengsc
2024-07-23 f575652587d4160ab42e75acb2bc26b4f60fb7c3
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
var PalletEmptyInManager = {
    EmptyPalletTable: undefined,
    Servers: function (URL, data, callback) {
        $.gitAjax({
            url: URL,
            data: data,
            type: "post",
            dataType: "json",
            success: function (result) {
                callback(result);
            }
        });
    },
    Server: function () {
        var config = (function () {
            var URL_GetList = "/Business/IPalletEmptyInAjax/GetList";
            var URL_Add = "/Business/IPalletEmptyInAjax/Add";
            var URL_Del = "/Business/IPalletEmptyInAjax/Del";
            var URL_ErpIn = "/Business/IPalletEmptyInAjax/ErpIn";
            var URL_ErpClose = "/Business/IPalletEmptyInAjax/ErpClose";
            var URL_CheckStatus = "/Business/IPalletEmptyInAjax/CheckStatus";
            return {
                URL_GetList: URL_GetList,
                URL_Add: URL_Add,
                URL_Del: URL_Del,
                URL_ErpIn:URL_ErpIn,
                URL_ErpClose: URL_ErpClose,
                URL_CheckStatus: URL_CheckStatus,
            };
        })();
 
        //数据操作服务
        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 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);
                        }
                    }
                });
            }
 
            var Del = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Del,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var ErpIn = function (data, callback) {
                $.gitAjax({
                    url: config.URL_ErpIn,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var ErpClose = function (data, callback) {
                $.gitAjax({
                    url: config.URL_ErpClose,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
            var CheckStatus = function (data, callback) {
                $.gitAjax({
                    url: config.URL_CheckStatus,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
            return {
 
                GetList: GetList,
                Add: Add,
                Del: Del,
                ErpIn: ErpIn,
                ErpClose: ErpClose,
                CheckStatus:CheckStatus,
 
            }
        })($, config);
        return dataServer;
    },
    PageClick: function (PageIndex, PageSize) {
        $.jBox.tip("正在努力加载数据...", "loading");
        var Server = PalletEmptyInManager.Server();
        var search = PalletEmptyInManager.GetSearch();
        search["PageIndex"] = PageIndex;
        search["PageSize"] = PageSize;
 
        Server.GetList(search, function (result) {
            //debugger
            $.jBox.closeTip();
            if (result.Code == 1) {
                PalletEmptyInManager.SetTable(result);
            } else {
                $.jBox.tip(result.Message, "warn");
            }
        });
    },
    Refresh: function () {
        var PageSize = $("#mypager").pager("GetPageSize");
        var PageIndex = $("#mypager").pager("GetCurrent");
        $.jBox.tip("正在努力加载数据...", "loading");
        var Server = PalletEmptyInManager.Server();
        var search = PalletEmptyInManager.GetSearch();
        search["PageIndex"] = PageIndex;
        search["PageSize"] = PageSize;
        Server.GetList(search, function (result) {
            $.jBox.closeTip();
            if (result.Code == 1) {
                PalletEmptyInManager.SetTable(result);
            } else {
                $.jBox.tip(result.Message, "warn");
            }
        });
    },
    SetTable: function (result) {
        var cols = [
 
            {
                title: '托盘码', name: 'Palno', width: 120, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '托盘数量', name: 'PalCount', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '指定库位', name: 'LocationCode', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '状态', name: 'Statu', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
 
            {
                title: '创建者', name: 'CreateUser', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '创建时间', name: 'CreateTime', width: 200, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '备注', name: 'Demo', width: 260, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '操作', name: 'OrdNo', width: 80, align: 'left', lockWidth: false, renderer: function (data, item, rowIndex) {
                    var html = "";
                    if (item.Statu == "等待执行") {
                        html += '<a class="edit dis" href="javascript:void(0)">编辑</a>&nbsp;';
                        html += '<a class="del dis" href="javascript:void(0)">删除</a>&nbsp;';
                    }
                    return html;
                }
            },
        ];
        var ht = masterUI.MMGridHeight();
        if (this.EmptyPalletTable == undefined) {
            this.EmptyPalletTable = $("#tabList").mmGrid({
                cols: cols,
                items: result.Result.List,
                checkCol: true,
                fullWidthRows: true,
                nowrap: true,
                height: ht
            });
            //绑定编辑 删除事件
           PalletEmptyInManager.BindEvent();
        }
        else {
            this.EmptyPalletTable.load(result.Result.List);
        }
 
        var pageInfo = result.PageInfo;
        if (pageInfo != undefined) {
            $("#mypager").pager({ pagenumber: pageInfo.PageIndex, recordCount: pageInfo.RowCount, pageSize: pageInfo.PageSize, buttonClickCallback: PalletEmptyInManager.PageClick });
        }
    },
    BindEvent: function () {
 
        this.EmptyPalletTable.on('loadSuccess', function (e, data) {
            LoadBtn.SetBtn();
        });
 
        this.EmptyPalletTable.off("cellSelected").on("cellSelected", function (e, item, rowIndex, colIndex) {
            if ($(e.target).is("a.del")) {
                if (item.Statu == "等待执行") {
                    var Guid = item.Guid;
                    var LocationCode = item.LocationCode;
 
 
                    var submit = function (v, h, f){
                        if (v == "ok") {
                            //// 验证单据状态并删除数据
                            PalletEmptyInManager.Servers("/Business/IPalletEmptyInAjax/IsCheckStatu",
                                { Guid: Guid, LocationCode: LocationCode }, function (result) {
                                    if (result != null) {
                                        $.jBox.tip(result.Message, "warn");
                                    }
 
                                    PalletEmptyInManager.PageClick(1, 50);
                                });
                        }
                    }
 
                    $.jBox.confirm("确定要删除吗?", "提示", submit);
                }
            }
            else if ($(e.target).is("a.edit")) {
                var Guid = item.Guid;
                var Palno = item.Palno;
                var PalCount = item.PalCount;
                var Demo = item.Demo;
                var Addre = item.LocationCode;
                if (item.Statu != "等待执行") {
                    jBox.tip("状态不允许编辑", "warn");
                    return false;
                }
 
                PalletEmptyInManager.Add(Guid, Palno, PalCount, Demo, Addre);
            }
        });
    },
    GetSelect: function () {
        var list = [];
        if (this.EmptyPalletTable != undefined) {
            var rows = this.EmptyPalletTable.selectedRows();
            if (rows != undefined && rows.length > 0) {
                for (var i = 0; i < rows.length; i++) {
                    list.push(rows[i].OrdNo);
                }
            }
        }
        return list;
    },
    GetRows: function () {
        var list = [];
        if (this.EmptyPalletTable != undefined) {
            var rows = this.EmptyPalletTable.selectedRows();
            if (rows != undefined && rows.length > 0) {
                for (var i = 0; i < rows.length; i++) {
                    list.push(rows[i]);
                }
            }
        }
        return list;
    },
    GetSearch: function () {
        var search = {};
        var searchBar = $("div[data-condition='search']");
        search["Palno"] = searchBar.find("input[name='PalletNo']").val();
        search["BeginTime"] = searchBar.find("input[name='BeginTime']").val();
        search["EndTime"] = searchBar.find("input[name='EndTime']").val();
        return search;
    },
    Add: function (Guid, Palno, PalCount, Demo, Addre) {
        
        var submit = function (v, h, f) {
            if (v) {
                var PalletNo = h.find("input[name='PalletNo']").val();
                var PalletCount = h.find("input[name='PalletCount']").val();
                var Demo = h.find("input[name='Demo']").val();
 
                if (git.IsEmpty(PalletNo)) {
                    $.jBox.tip("托盘码不能为空", "warn");
                    return false;
                }
                if (!git.checkStrLength(PalletNo)) {
                    $.jBox.tip("托盘码长度异常,请将输入法切换为英文,重新扫码!", "warn");    
                    return false;
                }
                if (!git.checkInteger(PalletCount)) {
                    $.jBox.tip("数量必须为数字", "warn");
                    return false;
                }
                if (git.IsEmpty(PalletCount)) {
                    $.jBox.tip("数量不能为空", "warn");
                    return false;
                }
 
                var param = {};
                param["Guid"] = Guid;
                param["Palno"] = PalletNo;
                param["PalCount"] = PalletCount;
                param["LocationCode"] = h.find("input[name='Addre']").val();;
                param["Demo"] = Demo;
 
                
                // 验证托盘码是否重复使用 liudl
                PalletEmptyInManager.Servers("/Business/IPalletEmptyInAjax/CheckPalletNo",
                    { ajaxdata: JSON.stringify(param) }, function (result) {
                        if (result.Code == -1) {
                            $.jBox.tip(result.Message, "warn");
                            return false;
                        }
                        else
                        {
                            var Server = PalletEmptyInManager.Server();
                            Server.Add(param, function (result) {
                                if (result.Code == 1) {
                                    PalletEmptyInManager.PageClick(1, 50);
                                } else {
                                    $.jBox.tip(result.Message, "warn");
                                }
                            });
                            $.jBox.close();
                        }
                });
                return false;
            }
            else {
                $.jBox.close();
            }
        }
 
        //对话框加载之后回调事件
        var load = function (h) {
            $("div.controls").find("input[name='Addre']").SelAddre({
                Mult: false,
                TargetStore: $('select[name="StorageNum"]'),
                TargetSup: $('input[name="SupNum"]'),
                callBack: function (result) {
                    $("div.controls").find("input[name='Addre']").val(result.LocationCode);
                }
            });
 
            var param = {};
            
            param["PalletCount"] = PalCount;
            param["PalletNo"] = Palno;
            
            $('div.controls').find("#PalletNo").val(Palno);
            if (!git.IsEmpty(Palno)) {
                $('div.controls').find("#PalletNo").attr("Disabled", "Disabled");
            }
            $('div.controls').find("#Addre").val(Addre);
            $('div.controls').find("#PalletCount").val(PalCount);
            $('div.controls').find("#Demo").val(Demo);
        }
 
        if (git.IsEmpty(Palno)) {
            $.jBox.open("get:/Business/IPalletEmptyIn/Add", "空托入库", 400, 270, { buttons: { "确定": true, "关闭": false }, submit: submit, loaded: load });
        } else {
            $.jBox.open("get:/Business/IPalletEmptyIn/Add", "空托入库", 400, 270, { buttons: { "确定": true, "关闭": false }, submit: submit, loaded: load });
        }
    },
    Del: function () {
        debugger
        var submit = function (v, h, f) {
            if (v == "ok") {
                debugger
                var list = PalletEmptyInManager.GetRows();
 
                if (list.length == 0) {
                    $.jBox.tip("请选择要删除的项", "warn");
                    return false;
                }
                var item = list[0];
 
                if (item.Statu == "正在执行" || item.Statu == "执行完成") {
                    $.jBox.tip("该托盘正在执行入库操作,不可删除!", "warn");
                    return false;
                }
 
                var param = {};
                param["Id"] = item.Id;
                param["PalletNo"] = item.PalletNo;
                param["PalletCount"] = item.PalletCount;
                var Server = PalletEmptyInManager.Server();
                Server.Del(param, function (result) {
                    if (result.Code == 1) {
                        debugger
                        var pageSize = $("#mypager").pager("GetPageSize");
                        PalletEmptyInManager.PageClick(1, pageSize);
                    } else {
                        $.jBox.tip(result.Message, "warn");
                    }
                });
            }
        }
        $.jBox.confirm("该操作将解除托盘与物料绑定关系,确定要删除吗?", "提示", submit);
    },
    ErpIn: function (PalletNo) {
        debugger
        var Server = PalletEmptyInManager.Server();
 
        Server.ErpIn(PalletNo, function (result) {
            debugger
            $.jBox.closeTip();
            if (result.Code == 1) {
                PalletEmptyInManager.SetTable(result);
            } else {
                $.jBox.tip(result.Message, "warn");
            }
        });
    },
    ErpClose: function (PalletNo) {
        debugger
        var Server = PalletEmptyInManager.Server();
 
        Server.ErpClose(PalletNo, function (result) {
            debugger
            $.jBox.closeTip();
            if (result.Code == 1) {
                PalletEmptyInManager.SetTable(result);
            } else {
                $.jBox.tip(result.Message, "warn");
            }
        });
    },
    ToolBar: function () {
        //工具栏按钮点击事件
        $("div.toolbar").find("a.btn").click(function () {
            var command = $(this).attr("data-command");
 
            if (command == "Add") {
                PalletEmptyInManager.Add();
            }
 
        });
 
        //搜索 高级搜索按钮
        var searchBar = $("div[data-condition='search']");
        searchBar.find("a[data-command='search']").click(function () {
            PalletEmptyInManager.PageClick(1, 50);
        });
 
        //加载默认数据
        PalletEmptyInManager.PageClick(1, 50);
    }
}