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
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
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
/**
*
*出库管理功能
*
**/
 
var ErpOutManager = {
    InTable: undefined,
    Server: function () {
        var config = (function () {
            var URL_Add = "/Business/ErpOutAjax/Add";
 
            var URL_LoadDetail = "/Business/ErpOutAjax/LoadDetail";
            var URL_AddProduct = "/Business/ErpOutAjax/AddProduct";
            var URL_DelProduct = "/Business/ErpOutAjax/DelProduct";
            var URL_UpdateProduct = "/Business/ErpOutAjax/UpdateProduct";
 
            var URL_GetList = "/Business/ErpOutAjax/GetErpOutList";
            var URL_GetDetail = "/Business/ErpOutAjax/GetDetail";
            var URL_Delete = "/Business/ErpOutAjax/Delete";
            var URL_Out = "/Business/ErpOutAjax/Out";
            var URL_Close = "/Business/ErpOutAjax/Close";
            var URL_Audite = "/Business/ErpOutAjax/Audit";
            var URL_ToExcel = "/Business/ErpOutAjax/ToExcel";
 
            return {
                URL_GetList: URL_GetList,
                URL_GetDetail: URL_GetDetail,
                URL_LoadDetail: URL_LoadDetail,
                URL_AddProduct: URL_AddProduct,
                URL_DelProduct: URL_DelProduct,
                URL_UpdateProduct: URL_UpdateProduct,
                URL_Add: URL_Add,
 
                URL_Delete: URL_Delete,
                URL_Close: URL_Close,
                URL_Audite: URL_Audite,
                URL_ToExcel: URL_ToExcel,
                URL_Out: URL_Out,
            };
        })();
 
        //数据操作服务
        var dataServer = (function ($, config) {
 
            //查询分页列表
            var Add = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Add,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var LoadDetail = function (data, callback) {
                $.gitAjax({
                    url: config.URL_LoadDetail,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var AddProduct = function (data, callback) {
                $.gitAjax({
                    url: config.URL_AddProduct,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var DelProduct = function (data, callback) {
                $.gitAjax({
                    url: config.URL_DelProduct,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var UpdateProduct = function (data, callback) {
                $.gitAjax({
                    url: config.URL_UpdateProduct,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            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 GetDetail = function (data, callback) {
                $.gitAjax({
                    url: config.URL_GetDetail,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
            var Out = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Out,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
            var Delete = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Delete,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var Close = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Close,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var Audite = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Audite,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var ToExcel = function (data, callback) {
                $.gitAjax({
                    url: config.URL_ToExcel,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            return {
                Add: Add,
                LoadDetail: LoadDetail,
                AddProduct: AddProduct,
                DelProduct: DelProduct,
                UpdateProduct: UpdateProduct,
                GetList: GetList,
                GetDetail: GetDetail,
                Delete: Delete,
                Close: Close,
                Audite: Audite,
                ToExcel: ToExcel,
                Out: Out,
            }
 
        })($, config);
        return dataServer;
    },
    PageClick: function (PageIndex, PageSize) {
        $.jBox.tip("正在努力加载数据...", "loading");
        var Server = ErpOutManager.Server();
        var search = ErpOutManager.GetSearch();
        search["PageIndex"] = PageIndex;
        search["PageSize"] = PageSize;
 
        Server.GetList(search, function (result) {
            $.jBox.closeTip();
            if (result.Code == 1) {
                ErpOutManager.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 = ErpOutManager.Server();
        var search = ErpOutManager.GetSearch();
        search["PageIndex"] = PageIndex;
        search["PageSize"] = PageSize;
        Server.GetList(search, function (result) {
            $.jBox.closeTip();
            if (result.Code == 1) {
                ErpOutManager.SetTable(result);
            } else {
                $.jBox.tip(result.Message, "warn");
            }
        });
    },
    SetTable: function (result) {
        var cols = [
            {
                title: '操作', name: 'OrdNo', width: 150, align: 'left', lockWidth: false, renderer: function (data, item, rowIndex) {
 
                    var html = "";
                    if (item.Statu == "等待执行" || item.Statu == "等待下发") {
                        html += '<a class="view" href="javascript:void(0)">查看</a>&nbsp;';
                        html += '<a class="edit dis" href="javascript:void(0)">编辑&nbsp;</a>';
                        html += '<a class="out dis" href="javascript:void(0)">出库</a>&nbsp;';
                        html += '<a class="delete dis" href="javascript:void(0)">删除&nbsp;</a>';
                        html += '<a class="print" href="javascript:void(0)">打印</a>&nbsp;';
                        
                    } else {
                        html += '<a class="view" href="javascript:void(0)">查看</a>&nbsp;';
                        html += '<a class="print" href="javascript:void(0)">打印</a>&nbsp;';
                    }
 
                    return html;
                }
            },
            {
                title: '订单号', name: 'OrdNo', width: 125, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '通道口', name: 'AccessName', width: 125, 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: 'CompletionTime', width: 150, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    //return git.JsonToDateTime(data);
                    return data;
                }
            },
            {
                title: '创建人', name: 'CreateUser', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '创建时间', name: 'CreateTime', width: 150, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    //return git.JsonToDateTime(data);
                    return data;
                }
            },
            {
                title: '修改人', name: 'UpdateUser', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '修改时间', name: 'UpdateTime', width: 150, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '备注', name: 'Demo', width: 350, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
        ];
 
        if (this.InTable == undefined) {
 
            var ht = masterUI.MMGridHeight();
            this.InTable = $("#tabList").mmGrid({
                cols: cols,
                items: result.Result.List,
                checkCol: true,
                multiSelect: false,
                nowrap: true,
                height: ht
            });
            //绑定编辑 删除事件
            ErpOutManager.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: ErpOutManager.PageClick });
        }
    },
    BindEvent: function () {
 
        this.InTable.off("cellSelected").on("cellSelected", function (e, item, rowIndex, colIndex) {
 
            if ($(e.target).is("a.edit")) {
                var SN = item.OrdNo;
                if (item.Statu == "等待执行" || item.Statu == "等待下发") {
                    var SN = item.OrdNo;
                    //window.location.href = "/Business/ErpOut/Add?OrdNo=" + SN;
                    ErpOutDetail.AddProduct(SN, '', item.Statu);
                } else {
                    $.jBox.tip("该订单不能编辑", "warn");
                }
            } else if ($(e.target).is("a.audit")) {
                var SN = item.OrdNo;
                ErpOutManager.Detail(SN, "Audit");
            } else if ($(e.target).is("a.view")) {
                var SN = item.OrdNo;
                ErpOutManager.Detail(SN, "View");
            } else if ($(e.target).is("a.out")) {
 
                if (item.Statu == "正在执行" || item.Statu == "执行完成") {
                    $.jBox.confirm("该订单数据正在执行或执行完成,不可重复出库!", "提示", submit1);
                } else if (item.Statu == "等待执行") {
                    var SN = item.OrdNo;
                    var AccessCode = item.AccessCode;
                    var submit1 = function (v, h, f) {
                        if (v == "ok") {
                            var list = [];
                            list.push(SN);
                            var param = {};
                            param["list"] = JSON.stringify(list);
                            param["AccessCode"] = AccessCode;
                            var Server = ErpOutManager.Server();
                            Server.Out(param, function (result) {
                                if (result.Code == 1) {
                                    var pageSize = $("#mypager").pager("GetPageSize");
                                    ErpOutManager.PageClick(1, pageSize);
                                } else {
                                    $.jBox.tip(result.Message, "success");
                                }
                            });
                        }
                    }
                    $.jBox.confirm("该操作将出库该订单所有托盘,确定要出库吗?", "提示", submit1);
                }
            }
            else if ($(e.target).is("a.delete")) {
 
                if (item.Statu == "正在执行" || item.Statu == "执行完成") {
                    $.jBox.confirm("该订单数据正在执行或执行完成,不可删除!", "提示", submit);
                } else if (item.Statu == "等待执行" || item.Statu == "等待下发") {
                    var SN = item.OrdNo;
                    var submit = function (v, h, f) {
                        if (v == "ok") {
                            var list = [];
                            list.push(SN);
                            var param = {};
                            param["list"] = JSON.stringify(list);
                            var Server = ErpOutManager.Server();
                            Server.Delete(param, function (result) {
                                if (result.Code == 1) {
                                    var pageSize = $("#mypager").pager("GetPageSize");
                                    ErpOutManager.PageClick(1, pageSize);
                                } else {
                                    $.jBox.tip(result.Message, "success");
                                }
                            });
                        }
                    }
                    $.jBox.confirm("该操作将删除该订单所有数据,确定要删除吗?", "提示", submit);
                }
            } else if ($(e.target).is("a.print")) {
                // if (item.AuditFlag == "已审核") {
                var SN = item.OrdNo;
                $.jBox.open("get:/Business/ErpOut/ReportShow?ReportNo=出库单&OrdNo=" + SN, "打印", 1150, 700);
                //window.location.href = "/Business/ErpOut/ReportShow?ReportNo=出库单&OrdNo=" + SN;
                //  }
                // else { $.jBox.tip("该订单还未审核,或审核未通过,不可 编辑", "warn"); }
            }
        });
 
        this.InTable.on('loadSuccess', function (e, data) {
 
            LoadBtn.SetBtn();
        });
 
    },
    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].OrdNo);
                }
            }
        }
        return list;
    },
    GetRows: 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]);
                }
            }
        }
        return list;
    },
    GetSearch: function () {
        var search = {};
        var searchBar = $("div[data-condition='search']");
        search["OrdNo"] = searchBar.find("input[name='OrdNo']").val();
        search["Statu"] = searchBar.find("select[name='Statu']").val();
        search["AccessCode"] = searchBar.find("select[name='AccessCode']").val();
        search["BatchNo"] = searchBar.find("input[name='BatchNo']").val();
        search["BatchDemo"] = searchBar.find("input[name='BatchDemo']").val();
 
        search["MatNo"] = searchBar.find("input[name='MatNo']").val();
        search["MatName"] = searchBar.find("input[name='MatName']").val();
        search["LingNo"] = searchBar.find("input[name='LingNo']").val();
        search["TuNo"] = searchBar.find("input[name='TuNo']").val();
 
        search["BeginTime"] = searchBar.find("input[name='BeginTime']").val();
        search["EndTime"] = searchBar.find("input[name='EndTime']").val();
 
        return search;
    },
    Detail: function (OrdNo, Command) {
        var submit = function (v, h, f) {
            if (v == "1") {
                var list = [];
                list.push(OrdNo);
                var param = {};
                param["list"] = JSON.stringify(list);
                param["Operation"] = "AD02"; //审核不通过
                var Server = ErpOutManager.Server();
                Server.Audite(param, function (result) {
                    if (result.Code == 1) {
                        var pageSize = $("#mypager").pager("GetPageSize");
                        ErpOutManager.PageClick(1, pageSize);
                        $.jBox.close();
                    } else {
                        $.jBox.tip(result.Message, "info");
                    }
                });
            } else if (v == "2") {
                var list = [];
                list.push(OrdNo);
                var param = {};
                param["list"] = JSON.stringify(list);
                param["Operation"] = "AD03"; //审核不通过
 
                var Server = ErpOutManager.Server();
                Server.Audite(param, function (result) {
                    if (result.Code == 1) {
                        var pageSize = $("#mypager").pager("GetPageSize");
                        ErpOutManager.PageClick(1, pageSize);
                        $.jBox.close();
                    } else {
                        $.jBox.tip(result.Message, "success");
                    }
                });
            } else if (v == "3") {
                //打印
            } else if (v == "4") {
                $.jBox.close();
            }
            return false;
        }
 
        var TabGrid = undefined;
        var SetTable = function (h, result) {
            var cols = [
                {
                    title: '生产令号', name: 'LingNo', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                },
                {
                    title: '图号', name: 'TuNo', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                },
                {
                    title: '序号', name: 'PageNo', width: 60, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                },
                {
                    title: '物料编码', name: 'MatCode', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                },
                {
                    title: '物料名称', name: 'MatName', width: 160, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                },
                {
                    title: '规格型号', name: 'PackFormat', width: 260, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                },
                {
                    title: '合格证', name: 'Certificate', width: 260, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                },
                {
                    title: '实出数量', name: 'CurQuant', width: 70, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                },
                {
                    title: '单位', name: 'Unit', width: 60, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                },
                {
                    title: '库位地址', name: 'LocationCode', width: 120, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                },
                {
                    title: '托盘号', name: 'Palno', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                },
                {
                    title: '领料人', name: 'PickerUser', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                },
                {
                    title: '备  注', name: 'Demo', width: 120, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                        return data;
                    }
                }
            ];
 
            if (TabGrid == undefined) {
                TabGrid = h.find('#tabDetail').mmGrid({
                    cols: cols,
                    items: result.Result.List,
                    checkCol: false,
                    nowrap: true,
                    height: 250
                });
            } else {
                TabGrid.load(result.Result.List);
            }
            var pageInfo = result.PageInfo;
            if (pageInfo != undefined) {
                $("#myDetailPager").pager({ pagenumber: pageInfo.PageIndex, recordCount: pageInfo.RowCount, pageSize: pageInfo.PageSize, buttonClickCallback: function (PageIdex, PageSize) { PageClick(h, PageIdex, PageSize); } });
            }
        }
 
        var load = function (h) {
            PageClick(h, 1, 50);
        }
        var PageClick = function (h, PageIndex, PageSize) {
            var Server = ErpOutManager.Server();
            var search = {};
            search["OrdNo"] = OrdNo;
            if (PageIndex == undefined) {
                PageIndex = h.find('#myDetailPager').pager("GetCurrent");
                search["PageIndex"] = pageIndex;
            }
            else
                search["PageIndex"] = PageIndex;
            if (PageSize == undefined) {
                PageSize = h.find('#myDetailPager').pager("GetCurrent");
                search["PageSize"] = PageSize;
            }
            else
                search["PageSize"] = PageSize;
            Server.GetDetail(search, function (result) {
                if (result.Code == 1) {
                    SetTable(h, result);
                } else {
                    $.jBox.tip(result.Message, "warn");
                }
            });
        }
 
 
        if (Command == "View") {
            $.jBox.open("get:/Business/ErpOut/Detail?OrdNo=" + OrdNo, "出库单详细", 850, 480, {
                buttons: { "关闭": 4 }, submit: submit, loaded: function (h) {
                    load(h);
                }
            });
        } else if (Command == "Audit") {
            $.jBox.open("get:/Business/ErpOut/Detail?OrdNo=" + OrdNo, "入库单详细", 850, 480, {
                buttons: { "审核通过": 1, "审核不通过": 2, "关闭": 4 }, submit: submit, loaded: function (h) {
                    load(h);
                }
            });
        }
    },
    ToolBar: function () {
        //工具栏按钮点击事件
        $("div.toolbar").find("a.btn").click(function () {
            var command = $(this).attr("data-command");
            switch (command) {
                case "Add":
                    ErpOutDetail.AddProduct();
                    break;
                case "Input":
                    $('#excelFile').click();
                    break;
                default: break;
            }
        });
 
        //搜索 高级搜索按钮
        var searchBar = $("div[data-condition='search']");
        searchBar.find("a[data-command='search']").click(function () {
            ErpOutManager.PageClick(1, 50);
        });
 
        $('#excelFile').on('change', function () {
            ErpOutManager.ImportExcel();
        });
 
 
        //窗体加载获得焦点
        searchBar.find("input[name='OrdNo']").focus();
        //加载默认数据
        ErpOutManager.PageClick(1, 50);
    },
    ImportExcel: function () {
        var formData = new FormData();
        var filename = $("#excelFile")[0].files[0];
        if (filename == null || filename == "" || filename == "undefined") {
            $.jBox.tip("请选择文件", "warn");
            return;
        } else {
            formData.append('file', $("#excelFile")[0].files[0]); //将文件转成二进制形式
            $.ajax({
                type: "post",
                url: "/Business/ErpOut/ExcelToUpload",//"/文件名/控制器名/控制器内方法"
                async: false,
                contentType: false, //这个一定要写
                processData: false, //这个也一定要写,不然会报错
                data: formData,
                dataType: 'json', //返回类型
                success: function (data) {
                    var submit = function () {
                        window.location.href = "/Business/ErpOut/Index";
                    }
                    $.jBox.confirm(data, "提示", submit);
                },
            })
        }
    },
}
 
 
 
var ErpOutDetail = {
    Servers: function (URL, data, callback) {
        $.gitAjax({
            url: URL,
            data: data,
            type: "post",
            dataType: "json",
            success: function (result) {
                callback(result);
            }
        });
    },
    BindTable: undefined,
    BindTableEvent: function (staut) {
        ErpOutDetail.BindTable.off("cellSelected").on("cellSelected", function (e, item, rowIndex, colIndex) {
            if ($(e.target).is("a.delete")) {
                var StoreGuid = item.StoreGuid;
                var Guid = item.Guid;
                var submit = function (v, h, f) {
                    if (v == "ok") {
                        var param = {};
                        param["StoreGuid"] = StoreGuid;
                        param["Guid"] = Guid;
 
                        ErpOutDetail.Servers("/Business/ErpOutAjax/DelProduct",
                            { ajaxdata: JSON.stringify(param) },
                            function (result) {
                                if (result.Code == 1) {
                                    var pageSize = $("#mypager1").pager("GetPageSize");
                                    ErpOutDetail.SetTable(result);
                                } else {
                                    $.jBox.tip(result.Message, "warn");
                                }
                            })
                    }
                }
                $.jBox.confirm("确定要删除吗?", "提示", submit);
            }
            else if ($(e.target).is("a.edit")) {
                $('div.controls').find("#MatGuid").val(item.MatGuid);
                $('div.controls').find("#StoreGuid").val(item.StoreGuid);
                $('div.controls').find("#MatNo").val(item.MatNo);
                $('div.controls').find("#CurQuant").val(item.CurQuant);
                $('div.controls').find("#MatName").val(item.MatName);
                $('div.controls').find("#Guid").val(item.Guid);
 
                // 若属性没值不清空文本框
                if (!git.IsEmpty(item.PickerUser)) {
                    $('div.controls').find("#PickerUser").val(item.PickerUser);
                }
                if (!git.IsEmpty(item.DetailDemo)) {
                    $('div.controls').find("#DetailDemo").val(item.DetailDemo);
                }
            }
        });
    },
    SetTable: function (result) {
        ErpOutDetail.BindTable.load(result.Result.List);
        ErpOutDetail.BindTableEvent();
    },
    InitTable: function () {
        var cols = [
            {
                title: '操作', name: 'Guid', width: 60, align: 'left', lockWidth: false, renderer: function (data, item, rowIndex) {
                    var html = "";
                    html += '<a class="edit " href="javascript:void(0)">编辑&nbsp;</a>';
                    html += '<a class="delete " href="javascript:void(0)">删除&nbsp;</a>';
                    return html;
                }
            },
            {
                title: '生产令号', name: 'LingNo', width: 80, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '批次号', name: 'BatchNo', width: 80, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '批次描述', name: 'BatchDemo', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '图号', name: 'TuNo', width: 80, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '序号', name: 'PageNo', width: 60, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '合格证', name: 'Certificate', width: 60, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '物料编码', name: 'MatNo', width: 80, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '物料名称', name: 'MatName', width: 180, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '出库数', name: 'CurQuant', width: 50, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '类型', name: 'MayType', width: 60, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '库位地址', name: 'LocationCode', width: 60, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '领料人', name: 'PickerUser', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '备    注', name: 'DetailDemo', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
        ];
        {
            ErpOutDetail.BindTable = $("#tabList1").mmGrid({
                cols: cols,
                items: null,
                indexCol: true,
                checkCol: false,
                nowrap: true,
                height: 365
            });
            //绑定编辑 删除事件
            ErpOutDetail.BindTableEvent();
        }
    },
    EventBind: function () {
        $('div.controls').find("#btnBind").click(function () {
            // 物料编码验证
            if (git.IsEmpty($('div.controls').find("#MatNo").val()) ||
                git.IsEmpty($('div.controls').find("#MatGuid").val()) ||
                git.IsEmpty($('div.controls').find("#StoreGuid").val())) {
                $.jBox.tip("物料编码不能为空", "warn");
                return false;
            }
            if (!git.checkInteger($('div.controls').find("#CurQuant").val())) {
                $.jBox.tip("总数必须为数字", "warn");
                return false;
            }
            if (git.IsEmpty($('div.controls').find("#CurQuant").val())) {
                $.jBox.tip("总数不允许为空", "warn");
                return false;
            }
 
            var param = {};
            param["Guid"] = $('div.controls').find("#Guid").val();
            param["MatGuid"] = $('div.controls').find("#MatGuid").val();
            param["StoreGuid"] = $('div.controls').find("#StoreGuid").val();
            param["CurQuant"] = $('div.controls').find("#CurQuant").val();
            param["PickerUser"] = $('div.controls').find("#PickerUser").val();
            param["DetailDemo"] = $('div.controls').find("#DetailDemo").val();
 
            // 判断物料是否存在
            ErpOutDetail.Servers("/Business/ErpOutAjax/IsCheckMatNum",
                { ajaxdata: JSON.stringify(param) }, function (result) {
                    if (result == null) {
                        $.jBox.tip("出库数量输入有误!", "warn");
                        return false;
                    }
                    else {
                        ErpOutDetail.Servers("/Business/ErpOutAjax/AddMat",
                            { ajaxdata: JSON.stringify(param) },
                            function (result) {
                                if (result.Code == 1) {
                                    ErpOutDetail.SetTable(result);
                                    $('div.controls').find("#Guid").val("");
                                    $('div.controls').find("#MatNo").val("");
                                    $('div.controls').find("#MatName").val("");
                                    $('div.controls').find("#MatGuid").val("");
                                    $('div.controls').find("#StoreGuid").val("");
                                    $('div.controls').find("#CurQuant").val("");
                                } else {
                                    $.jBox.tip(result.Message, "warn");
                                }
                            })
                    }
                });
        });
 
 
 
        ErpOutDetail.InitTable();
 
        ErpOutDetail.Servers("/Business/ErpOutAjax/Init",
            { aaa: "" }, function (result) {
                if (result.Code == 1) {
                    ErpOutDetail.SetTable(result);
                } else {
                    $.jBox.tip(result.Message, "warn");
                }
            });
    },
    AddProduct: function (OrdNo, LingNo, Status, demo) {
 
        var submit = function (v, h, f) {
            if (v) {
                var bl = true;
                var data = {};
                data["OrdNo"] = OrdNo;
                data["Statu"] = Status;
                data["AccessCode"] = h.find("select[name='AccessCode']").val();
                data["Demo"] = h.find('input[name="Demo"]').val();
                var PickerUser = h.find('input[name="PickerUser"]').val();
 
                $.gitAjax({
                    async: false,
                    url: "/Business/ErpOutAjax/Add",
                    data: { entity: JSON.stringify(data), pickerUser: PickerUser },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (result.Code == 1) {
                            // 刷新主页面
                            ErpOutManager.PageClick(1, 15);
                        }
                        else {
                            bl = false;
                            $.jBox.tip(result.Message, "warn");
                        }
                    }
                });
 
                return bl;
            }
        }
 
        //对话框加载之后回调事件
        var load = function (h) {
 
            if (OrdNo != null) {
                var entity = {};
                entity["OrdNo"] = OrdNo;
                entity["PageIndex"] = 1;
                entity["PageSize"] = 10;
 
                ErpOutDetail.Servers("/Business/ErpOutAjax/GetDetail",
                    { ajaxdata: JSON.stringify(entity) },
                    function (result) {
                        if (result.Code == 1) {
                            //debugger
                            $('div.controls').find("#OrdNo").val(OrdNo);
                            //$('div.controls').find("#Demo").val(result.Result.List[0].Demo);
                            //$('div.controls').find("#BatchNo").val(result.Result.List[0].BatchNo);
                            //$('div.controls').find("#BatchDemo").val(result.Result.List[0].BatchDemo);
 
                            ErpOutDetail.SetTable(result);
                        } else {
                            $.jBox.tip(result.Message, "warn");
                        }
                    });
            }
 
            // 加载已选物料
            h.find("input[name='MatNo']").SelMatDialog({
                Mult: false,
                callBack: function () {
                    ErpOutDetail.Servers("/Business/ErpOutAjax/GetMatNos",
                        { ajaxdata: "" }, function (result) {
                            if (result != null) {
                                if (result.Code == 1) {
                                    // 查询成功,绑定Table
                                    ErpOutDetail.SetTable(result);
                                }
                                else {
                                    $.jBox.tip("请选择出库物料!", "warn");
                                }
                            }
                        });
                }
            });
 
            h.find("input[name='MatNo']").keydown(function (event) {
                if (event.keyCode == 13) {
                    var value = $(this).val();
                    if (!git.IsEmpty(value)) {
                        //liudl  此处获取物料编码 10-04号
                        //ErpOutManager.DataInteractWay("/Business/ErpOutAjax/GetMatNos",
                        ErpOutDetail.Servers("/Business/ErpOutAjax/GetMatNo",
                            {
                                aaa: JSON.stringify({
                                    MatNo: value,
                                    PageIndex: 1,
                                    PageSize: 10
                                })
                            },
                            function (result) {
                                //debugger
                                if (result != null) {
                                    $('div.controls').find("#MatGuid").val(result.Result.Mat[0].MatGuid);
                                    $('div.controls').find("#MatNo").val(result.Result.Mat[0].MatNo);
                                    $('div.controls').find("#MatName").val(result.Result.Mat[0].MatName);
                                    $('div.controls').find("#MatType").val(result.Result.Mat[0].MatType);
                                    $('div.controls').find("#StoreGuid").val(result.Result.Mat[0].StoreGuid);
 
                                    console.log(result.Result.Mat.length);
                                    for (var i = 0; i < result.Result.Mat.length; i++) {
                                        ErpOutDetail.Servers("/Business/ErpOutAjax/SelMatNos", { aaa: result.Result.Mat[i].StoreGuid },
                                            function (result) {
                                                if (result != null) {
                                                    if (result.Code == 1) {
                                                        // 查询成功,绑定Table
                                                        ErpOutDetail.SetTable(result);
                                                    }
                                                    else {
                                                        $.jBox.tip("请输入正确的出库物料!", "warn");
                                                    }
                                                }
                                            });
                                    }
 
 
                                } else {
                                    $('div.controls').find("#MatGuid").val("");
                                    $('div.controls').find("#MatName").val("");
                                    $('div.controls').find("#MatType").val("");
                                    $.jBox.tip("物料编码不存在!", "warn");
                                }
                            });
 
                        h.find("input[name='LingNo']").focus();
                    }
                }
            });
 
        }
        //debugger
 
        if (git.IsEmpty(OrdNo)) {
 
            $.jBox.open("get:/Business/ErpOut/SetErpOutDetail", "新增出库单", 800, 590, { buttons: { "确定": true, "关闭": false }, top: '6%', submit: submit, loaded: load });
        }
        else {
            var para = {};
            para["OrdNo"] = OrdNo;
            $.jBox.open("get:/Business/ErpOut/SetErpOutDetail?OrdNo=" + OrdNo, "编辑出库单", 800, 590, {
                buttons: { "确定": true, "关闭": false }, top: '6%', submit: submit, loaded: load
            });
            //ErpOutDetail.Servers("/Business/ErpOutAjax/CheckOrdStatus",
            //    { ajaxdata: JSON.stringify(para) },
            //    function (result) {
            //        if (result.Code == 1) {
            //            $.jBox.open("get:/Business/ErpOut/SetErpOutDetail?OrdNo=" + OrdNo, "编辑出库单", 800, 590, { buttons: { "确定": true, "关闭": false }, top: '6%', submit: submit, loaded: load });
            //        } else {
            //            $.jBox.tip(result.Message, "warn");
            //            return false;
            //        }
            //});
        }
 
    },
}