王 垚
2023-01-04 5faab615c58b52dec282b6ea5db12830ffa33894
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
 
 
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>条码单据</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/style-self.css" media="all">
 
</head>
<body>
    <div id="layout1" class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <form id="form1" class="layui-form" action="">
                        <div class="layui-card-header">
                            <div class="layui-btn-group">
                                <!--<button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="Saver">保存</button>-->
                                <!--<button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="HBarcodeSaverPZ">生成品种码</button>
                                <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="HBarcodeSaverWY">生成唯一码</button>-->
                                <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="HBarcodeSaverBox">生成内外箱条码</button>
                                <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="Print">条码打印</button>
                                <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="Exit">退出</button>
 
                            </div>
                        </div>
                        <div class="layui-card-body">
                            <div class="layui-form-item">
                                <div class="layui-row">
                                    <div class="layui-col-xs3">
                                        <label class="layui-form-label">单 据 号:</label>
                                        <div class="layui-input-inline">
                                            <input class="layui-input" name="HBillNo" lay-verify="HBillNo" id="HBillNo" readonly="readonly" autocomplete="off">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs3">
                                        <label class="layui-form-label">单据日期:</label>
                                        <div class="layui-input-inline">
                                            <input class="layui-input" name="HDate" id="HDate" readonly="readonly" autocomplete="off" disabled>
                                        </div>
                                    </div>
                                    <div class="layui-col-xs3">
                                        <label class="layui-form-label">主    管:</label>
                                        <div class="layui-input-inline">
                                            <input class="layui-input" name="HManagerName" id="HManagerName" readonly="readonly" autocomplete="off" disabled>
                                            <input id="HManagerID" name="HManagerID" type="hidden" />
                                        </div>
                                    </div>
                                    <div class="layui-col-xs3">
                                        <label class="layui-form-label">业 务 员:</label>
                                        <div class="layui-input-inline">
                                            <input class="layui-input" name="HEmpName" id="HEmpName" readonly="readonly" autocomplete="off">
                                            <input id="HEmpID" name="HEmpID" type="hidden" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-row">
                                    <div class="layui-col-xs3">
                                        <label class="layui-form-label"> 供 应 商:</label>
                                        <div class="layui-input-inline">
                                            <input class="layui-input" name="HSupName" lay-verify="HSupName" id="HSupName" readonly="readonly" autocomplete="off">
                                            <input id="HSupID" name="HSupID" type="hidden" />
                                        </div>
                                    </div>
                                    <div class="layui-col-xs3">
                                        <label class="layui-form-label">制 单 人:</label>
                                        <div class="layui-input-inline">
                                            <input class="layui-input" name="HMaker" id="HMaker" readonly="readonly" autocomplete="off">
                                        </div>
                                    </div>
                                    <div class="layui-col-xs6">
                                        <label class="layui-form-label"> 备    注:</label>
                                        <div class="layui-input-block">
                                            <input class="layui-input" name="HRemark" id="HRemark" readonly="readonly" autocomplete="off">
                                        </div>
                                    </div>
                                </div>
                            </div>
 
                        </div>
                        <div class="layui-tab layui-tab-brief" lay-filter="tabDemo">
                            <ul class="layui-tab-title">
                                <li class="layui-this" lay-id="1">源单信息</li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">
                                    <table class="layui-hide" id="mainTable" lay-filter="mainTable"></table>
                                    <script type="text/html" id="toolbarDemo">
                                        <div class="layui-btn-container">
                                            <!--<button type="button" class="layui-btn layui-btn-sm" lay-event="btn-normal">普通条码</button>-->
                                            <!--<button type="button" class="layui-btn layui-btn-sm" lay-event="btn-box">内外箱条码</button>-->
 
                                        </div>
                                    </script>
                                </div>
                            </div>
                        </div>
                        <!--<blockquote class="layui-elem-quote">条码</blockquote>-->
                    </form>
                </div>
 
            </div>
        </div>
    </div>
    <!--<script src="../../layuiadmin/layui/lay/modules/mobile/jquery-3.3.1.min.js"></script>-->
    <script src="../../layuiadmin/layui/layui.js"></script>
    <script src="../../layuiadmin/Scripts/json2.js" type="text/javascript"></script>
    <script src="../../layuiadmin/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../../../../Scripts/webConfig.js"></script>
    <!--<script src="../../../../Scripts/jquery-1.8.2.js"></script>-->
    <script>
        function f_alert(sMsg) {
            layer.alert(sMsg, { icon: 5 });
            //layer.open({
            //    type: 1
            //  , offset: 'auto' //具体配置参考:http://www.layui.com/doc/modules/layer.html#offset
            //  , id: 'layerDemo' //防止重复弹出
            //  , content: '<div style="padding: 20px 100px;">' + sMsg + '</div>'
            //  , shade: 0 //不显示遮罩
            //  , yes: function () {
            //      layer.closeAll();
            //  }
            //});
        }
        function isPositiveIntegerTimes(x, y) {
            if (x > y) {
                var flag = x;
                x = y;
                y = flag;
            }
            var z = y % x;
            if (x == 0) {
                return true;
            }
            else {
                if (z == 0) {
                    return true;
                }
                else {
                    return false;
                }
            }
        }
        function addDate(date, days) {
            if (days == undefined || days == '') {
                days = 1;
            }
            var date = new Date(date);
            date.setDate(date.getDate() + days);
            var month = date.getMonth() + 1;
            var day = date.getDate();
            var mm = "'" + month + "'";
            var dd = "'" + day + "'";
 
            //单位数前面加0
            if (mm.length == 3) {
                month = "0" + month;
            }
            if (dd.length == 3) {
                day = "0" + day;
            }
 
            var time = date.getFullYear() + "-" + month + "-" + day
            return time;
        }
        function DateDiff(sDate1, sDate2) {    //sDate1和sDate2是2002-12-18格式
            var aDate, oDate1, oDate2, iDays
            aDate = sDate1.split("-")
            oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])    //转换为12-18-2002格式
            aDate = sDate2.split("-")
            oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
            iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24)    //把相差的毫秒数转换为天数
            return iDays
        }
        function getUrlVars() {
            var vars = [], hash;
            var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashes.length; i++) {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
            }
            return vars;
        }
        var params = getUrlVars();
        var linterid = params[params[0]];
        var lentryid = params[params[1]];
        var type = params[params[2]];
        //原生成条码方法(送货单默认)
        var mainUrl = "GetHBarCodeShowBillMain"; //表头数据加载ajax
        var subUrl = "GetHBarCodeShowBillSub";//表体数据加载ajax h_v_SRM_POInStockBillSub_ForWeb2
        var saveBarCode = "GetBarcodeSaveBillBox";//条码生成保存方法ajax GetBarcodeSaveBillBox  GetBarcodeSaveBillOnlyInnerBox
        var openTmpListType = "HBarCodePrint"; //条码打印按钮 弹出界面
        //采购订单条码生成规则
        if (type == 'SRM_POOrderBillList') {
            mainUrl = 'GetHBarCodeShowBillMainBycg';
            subUrl = "GetHBarCodeShowBillSubBycg"; //h_v_Cg_POOrderBillSub_ForWeb2
            saveBarCode = "GetBarcodeSaveBillBoxBycg";
            openTmpListType = 'SRM_POOrderBillList';
 
        }
        //委外订单
        else if (type == 'SRM_EntrustOrderBill') {
            mainUrl = 'GetHBarCodeShowBillMainBywy';
            subUrl = "GetHBarCodeShowBillSubBywy"; //h_v_srm_EntrustOrderBillSub_ForWeb2
            saveBarCode = "GetBarcodeSaveBillBoxBycg";//调用采购数据
            openTmpListType = 'SRM_POOrderBillList';
        }
        // debugger;
        $.ajax({
            url: GetWEBURL() + mainUrl,
            type: "GET",
            data: { "sMsg": linterid },
            success: function (d) {
                $("#HInterID").val(d.data[0].HInterID);
                $("#HBillNo").val(d.data[0].HBillNo);
                $("#HRemark").val(d.data[0].HRemark);
                $("#HDate").val(d.data[0].HDateForWeb);
                //$("#HMaker").val(d.data[0].HMaker);
                $("#HMakerDate").val(d.data[0].HMakerDate)
                $("#HChecker").val(d.data[0].HChecker);
                $("#HCheckDate").val(d.data[0].HCheckDate);
                $("#HSupID").val(d.data[0].HSupID);
                $("#HSupName").val(d.data[0].HSupName);
                $("#HEmpID").val(d.data[0].HEmpID);
                $("#HEmpName").val(d.data[0].HEmpName);
                $("#HManagerID").val(d.data[0].HManagerID);
                $("#HManagerName").val(d.data[0].HManagerName);
                $("#HMaker").val(sessionStorage["HUserName"]);
            }
        });
 
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form', 'element', 'layer', 'laydate'], function () {
            var table = layui.table
                , $ = layui.$
                , form = layui.form
                , layer = layui.layer
                , laydate = layui.laydate
                , element = layui.element; //Tab的切换功能,切换事件监听等,需要依赖element模块
 
            //生成品种码
            form.on('submit(HBarcodeSaverPZ)', function (data) {//保存
                //debugger;
                var sMainStr = JSON.stringify(data.field);
                var sSubStr = JSON.stringify(table.cache['mainTable']);
                var sMainSub = sMainStr + ';' + sSubStr;
                layer.load(3)
                $.ajax(
                    {
                        type: "POST",
                        url: GetWEBURL() + "GetBarcodeSaveBillVarieties", //方法所在页面和方法名
                        async: true,
                        data: { "msg": sMainSub },
                        dataType: "json",
                        success: function (data) {
                            if (data.count == 1) { // 说明验证成功了,
                                layer.msg(data.Message, { icon: 1 });
                                element.tabDelete('tabDemo', '2'); //删除
                                element.tabAdd('tabDemo', {
                                    title: '条码信息'
                                    , content: '<table class="layui-hide" id="subTable" lay-filter="subTable"></table>' //支持传入(html代码)不持支直接传入html页面
                                    , id: '2' //选项卡标题的lay-id属性值
                                });
 
                                table.render({
                                    elem: '#subTable'
                                    , url: GetWEBURL() + 'GetHBarCodeShowBillSub2'
                                    //, toolbar: '#toolbarDemo1'
                                    , defaultToolbar: ['filter', 'exports']
                                    , where: { sMsg: linterid }
                                    , cols: [[
                                        // , { field: 'HMTONO', title: '计划跟踪单号', width: 100, sort: true, fixed: true edit: 'text', hide: true }
                                        , { field: 'HItemID', title: 'HItemID', width: 100, hide: true }
                                        , { field: 'HMaterID', title: '物料ID', width: 100, hide: true }
                                        , { field: 'HMaterNumber', title: '物料代码', width: 200 }
                                        , { field: 'HMaterName', title: '物料名称', width: 200 }
                                        , { field: 'HMaterModel', title: '规格型号', width: 200 }
                                        , { field: 'HBarCode', title: '条码编号', width: 200 }
                                        , { field: 'HUnitName', title: '计量单位', width: 100 }
                                        , { field: 'HUnitNumber', title: '计量单位代码', width: 100, hide: true }
                                        , { field: 'HUnitID', title: '计量单位ID', width: 100, hide: true }
                                        , { field: 'HQty', title: '数量', width: 100 }
                                        , { field: 'HBatchNo', title: '批次', width: 100 }
                                        , { field: 'HEndQty', title: '是否尾箱', width: 100 }
                                        , { field: 'HKFDate', title: '生产日期', width: 100 }
                                        , { field: 'HKFPeriod', title: '保质期', width: 100 }
                                        , { field: 'HKFDQDate', title: '到期日期', width: 100 }
                                    ]]
                                    // , data: [linterid]
                                    //  , page: true
                                    , done: function () {
                                        layer.closeAll("loading");
                                    }
                                });
                                element.tabChange('tabDemo', '2');
                            }
                            else {
                                // $("#verifycode").click();
                                layer.msg(data.Message, { icon: 5 });
                            }
                            layer.closeAll("loading");
                        },
                        error: function (err) {
                            f_alert("错误:" + err);
                        }
                    });
                return false;
            });
            //生成唯一码
            form.on('submit(HBarcodeSaverWY)', function (data) {//保存
                //debugger;
                var sMainStr = JSON.stringify(data.field);
                var sSubStr = JSON.stringify(table.cache['mainTable']);
                var sMainSub = sMainStr + ';' + sSubStr;
                layer.load(3)
                $.ajax(
                    {
                        type: "POST",
                        url: GetWEBURL() + "GetBarcodeSaveBillOnly", //方法所在页面和方法名
                        async: true,
                        data: { "msg": sMainSub },
                        dataType: "json",
                        success: function (data) {
                            if (data.count == 1) { // 说明验证成功了,
                                layer.msg(data.Message, { icon: 1 });
                                element.tabDelete('tabDemo', '2'); //删除
                                element.tabAdd('tabDemo', {
                                    title: '条码信息'
                                    , content: '<table class="layui-hide" id="subTable" lay-filter="subTable"></table>' //支持传入(html代码)不持支直接传入html页面
                                    , id: '2' //选项卡标题的lay-id属性值
                                });
                                table.render({
                                    elem: '#subTable'
                                    , url: GetWEBURL() + 'GetHBarCodeShowBillSub2'
                                    , toolbar: '#toolbarDemo1'
                                    , defaultToolbar: ['filter', 'exports']
                                    , where: { sMsg: linterid }
                                    , cols: [[
                                        // , { field: 'HMTONO', title: '计划跟踪单号', width: 100, sort: true, fixed: true edit: 'text', hide: true }
                                        , { field: 'HItemID', title: 'HItemID', width: 100, hide: true }
                                        , { field: 'HMaterID', title: '物料ID', width: 100, hide: true }
                                        , { field: 'HMaterNumber', title: '物料代码', width: 200 }
                                        , { field: 'HMaterName', title: '物料名称', width: 200 }
                                        , { field: 'HMaterModel', title: '规格型号', width: 200 }
                                        , { field: 'HBarCode', title: '条码编号', width: 200 }
                                        , { field: 'HUnitName', title: '计量单位', width: 100 }
                                        , { field: 'HUnitNumber', title: '计量单位代码', width: 100, hide: true }
                                        , { field: 'HUnitID', title: '计量单位ID', width: 100, hide: true }
                                        , { field: 'HQty', title: '数量', width: 100 }
                                        , { field: 'HBatchNo', title: '批次', width: 100 }
                                        , { field: 'HEndQty', title: '是否尾箱', width: 100 }
                                        , { field: 'HKFDate', title: '生产日期', width: 100 }
                                        , { field: 'HKFPeriod', title: '保质期', width: 100 }
                                        , { field: 'HKFDQDate', title: '到期日期', width: 100 }
 
                                    ]]
                                    // , data: [linterid]
                                    //  , page: true
                                    , done: function () {
                                        layer.closeAll("loading");
                                    }
                                });
                                element.tabChange('tabDemo', '2');
                            }
                            else {
                                // $("#verifycode").click();
                                layer.msg(data.Message, { icon: 5 });
                            }
                            layer.closeAll("loading");
                        },
                        error: function (err) {
                            f_alert("错误:" + err);
                        }
                    });
                return false;
            });
            //生成内外箱码
            form.on('submit(HBarcodeSaverBox)', function (data) {//保存
                //debugger;
                var sMainStr = JSON.stringify(data.field);
                var sSubStr = JSON.stringify(table.cache['mainTable']);
                var sMainSub = sMainStr + ';' + sSubStr;
                var _sSubStr = JSON.parse(sSubStr);
                for (var i = 0; i < _sSubStr.length; i++) {
                    if (_sSubStr[i].HQty > 0 && (_sSubStr[i].HMinQty == 0 || _sSubStr[i].HWXQty == 0)) {
                        layer.msg("明细记录第" + (i + 1) + "行,包装数量不能为0!", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                        return Result = false;
                    }
                    if (_sSubStr[i].HQty > _sSubStr[i].HNotBarcodeCount) {
                        layer.msg("明细记录第" + (i + 1) + "行,本次生成条码数量不能超出未生成条码数量!", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                        return Result = false;
                    }
                    if (_sSubStr[i].HQty > 0 && (_sSubStr[i].HBatchNo == "" || _sSubStr[i].HKFDate == "")) {
                        layer.msg("明细记录第" + (i + 1) + "行,批次或生产日期不能为空!", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                        return Result = false;
                    }
                }
                layer.load(3)
                $.ajax(
                    {
                        type: "POST",
                        url: GetWEBURL() + saveBarCode, //方法所在页面和方法名
                        async: true,
                        data: { "msg": sMainSub },
                        dataType: "json",
                        success: function (data) {
                            if (data.count == 1) { // 说明验证成功了,
                                layer.msg(data.Message, { icon: 1 });
                                element.tabDelete('tabDemo', '2'); //删除
                                element.tabDelete('tabDemo', '3'); //删除
 
                                element.tabAdd('tabDemo', {
                                    title: '外箱条码'
                                    , content: '<table class="layui-hide" id="subTable" lay-filter="subTable"></table>' //支持传入(html代码)不持支直接传入html页面
                                    , id: '2' //选项卡标题的lay-id属性值
                                });
                                table.render({
                                    elem: '#subTable'
                                    , url: GetWEBURL() + 'GetHBarCodeShowBillSub3'  //h_v_Web_BarCodeBill_ForWeb1
                                    , toolbar: '#toolbarDemo1'
                                    , defaultToolbar: ['filter', 'exports']
                                    , where: { sMsg: linterid }
                                    , cols: [[
                                        // , { field: 'HMTONO', title: '计划跟踪单号', width: 100, sort: true, fixed: true edit: 'text', hide: true }
                                        , { field: 'HItemID', title: 'HItemID', width: 100, hide: true }
                                        , { field: 'HMaterID', title: '物料ID', width: 100, hide: true }
                                        , { field: 'HMaterNumber', title: '物料代码', width: 200 }
                                        , { field: 'HMaterName', title: '物料名称', width: 200 }
                                        , { field: 'HMaterModel', title: '规格型号', width: 200 }
                                        , { field: 'HBarCode', title: '条码编号', width: 200 }
                                        , { field: 'HUnitName', title: '计量单位', width: 100 }
                                        , { field: 'HUnitNumber', title: '计量单位代码', width: 100, hide: true }
                                        , { field: 'HUnitID', title: '计量单位ID', width: 100, hide: true }
                                        , { field: 'HQty', title: '数量', width: 100 }
                                        , { field: 'HBatchNo', title: '批次', width: 100 }
                                        , { field: 'HEndQty', title: '是否尾箱', width: 100 }
                                        , { field: 'HKFDate', title: '生产日期', width: 100 }
                                        , { field: 'HKFPeriod', title: '保质期', width: 100 }
                                        , { field: 'HKFDQDate', title: '到期日期', width: 100 }
 
                                    ]]
                                    , done: function () {
                                        layer.closeAll("loading");
                                    }
                                });
 
                                element.tabAdd('tabDemo', {
                                    title: '内箱条码'
                                    , content: '<table class="layui-hide" id="subTable2" lay-filter="subTable2"></table>' //支持传入(html代码)不持支直接传入html页面
                                    , id: '3' //选项卡标题的lay-id属性值
                                });
                                table.render({
                                    elem: '#subTable2'
                                    , url: GetWEBURL() + 'GetHBarCodeShowBillSub4'
                                    , toolbar: '#toolbarDemo2'
                                    , defaultToolbar: ['filter', 'exports']
                                    , where: { sMsg: linterid }
                                    , cols: [[
                                        // , { field: 'HMTONO', title: '计划跟踪单号', width: 100, sort: true, fixed: true edit: 'text', hide: true }
                                        , { field: 'HItemID', title: 'HItemID', width: 100, hide: true }
                                        , { field: 'HMaterID', title: '物料ID', width: 100, hide: true }
                                        , { field: 'HMaterNumber', title: '物料代码', width: 200 }
                                        , { field: 'HMaterName', title: '物料名称', width: 200 }
                                        , { field: 'HMaterModel', title: '规格型号', width: 200 }
                                        , { field: 'HBarCode', title: '条码编号', width: 200 }
                                        , { field: 'HUnitName', title: '计量单位', width: 100 }
                                        , { field: 'HUnitNumber', title: '计量单位代码', width: 100, hide: true }
                                        , { field: 'HUnitID', title: '计量单位ID', width: 100, hide: true }
                                        , { field: 'HQty', title: '数量', width: 100 }
                                        , { field: 'HBatchNo', title: '批次', width: 100 }
                                        , { field: 'HEndQty', title: '是否尾箱', width: 100 }
                                        , { field: 'HKFDate', title: '生产日期', width: 100 }
                                        , { field: 'HKFPeriod', title: '保质期', width: 100 }
                                        , { field: 'HKFDQDate', title: '到期日期', width: 100 }
 
                                    ]]
                                    // , data: [linterid]
                                    //  , page: true
                                    , done: function () {
                                        layer.closeAll("loading");
                                    }
                                });
                                element.tabChange('tabDemo', '2');
                            }
                            else {
                                // $("#verifycode").click();
                                layer.msg(data.Message, { icon: 5 });
                            }
                            layer.closeAll("loading");
                        },
                        error: function (err) {
                            f_alert("错误:" + err);
                        }
                    });
                return false;
            });
            form.on('submit(Print)', function (data) {//打印
                var data1 = layui.table.cache["subTable"]
                    , data2 = layui.table.cache["subTable2"];
                var rows = '';
                var rows2 = '';
                if (data1 == undefined || data2 == undefined) {
                    layer.msg("请先生成内外箱条码!")
                    return;
                }
                for (var i = 0; i < data1.length; i++) {
                    rows += data1[i].HItemID.toString() + ',';
                    rows2 += data1[i].HBarCode.toString() + ',';
                }
                for (var j = 0; j < data2.length; j++) {
                    rows += data2[j].HItemID.toString() + ',';
                    rows2 += data2[j].HBarCode.toString() + ',';
                }
                rows = rows.substring(rows.length - 1, 0);
                rows2 = rows2.substring(rows2.length - 1, 0);
                if (rows == "") {
                    layer.msg("没有需要打印的数据!")
                    return;
                }
                else {
                    var url = "linteridSession";
                    $.ajax({
                        type: "POST",
                        url: GetWEBURL() + url, //方法所在页面和方法名
                        async: true,
                        data: { "linterid": rows.toString(), "HUserName": sessionStorage["HUserName"] },
                        dataType: "json",
                        success: function (data) {
                            layer.closeAll("loading");
                        },
                        error: function (err) {
                            layer.alert("错误:" + err, { icon: 5 });
                        }
                    });
                    sessionStorage["linterid"] = rows.toString();
                    layer.open({
                        type: 2
                        , area: ['50%', '50%']
                        , title: '打印模版选择'
                        , shade: 0.6 //遮罩透明度
                        , maxmin: false //允许全屏最小化
                        , anim: 0 //0-6的动画形式,-1不开启
                        , content: ['../../views/BaseSet/SRM_OpenTmpList.html?linterid=' + sessionStorage["HUserName"] + '&HBarcode=&Type=' + openTmpListType, 'yes']
                        , resize: false
                        //, cancel: function () {
                        //    $(".layui-btn").removeClass("layui-btn-disabled");
                        //}
                    })
                }
            });
            form.on('submit(Exit)', function (data) {//退出
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            });
            //监听提交
            form.verify({
                numberOrEmpty: function (value, item) {
                    // if (value != '') {
                    if (!/^\d+$/.test(value)) {
                        return '不能为空或数字或者0';
                    }
                    //}
                }
            });
            layer.load(3)
            table.render({
                elem: '#mainTable'
                , url: GetWEBURL() + subUrl
                , toolbar: '#toolbarDemo' //开启头部工具栏,并为其绑定左侧模板
                , defaultToolbar: ['filter', 'exports']
                , where: { sMsg: linterid, sMsg2: lentryid }
                , cols: [[
                    , { field: 'HMaterID', title: '物料ID', width: 100, hide: true }
                    , { field: 'HMaterNumber', title: '物料编码', width: 120 }
                    , { field: 'HOldMaterNumber', title: '旧物料编码', width: 120 }
                    , { field: 'HMaterShortNumber', title: '物料代码', width: 120, hide: true }
                    , { field: 'HSubjoin', title: '物料代码', width: 120}
                    , { field: 'HMaterName', title: '物料名称', width: 120 }
                    , { field: 'HMaterModel', title: '规格型号', width: 120 }
                    , { field: 'HUnitName', title: '计量单位', width: 100 }
                    , { field: 'HUnitNumber', title: '计量单位代码', width: 100, hide: true }
                    , { field: 'HUnitID', title: '计量单位ID', width: 100, hide: true }
                    , { field: 'HDDQty', title: '订单数量', width: 100 }
                    , { field: 'HBarcodeCount', title: '已生成条码数量', width: 135 }
                    , { field: 'HNotBarcodeCount', title: '未生成条码数量', width: 135 }
                    , { field: 'HQty', title: '本次生成条码数量', width: 135, edit: 'text', event: "inputHQty" }
                    , { field: 'HMinQty', title: '内箱包装数', width: 100, edit: 'text', event: "inputHMinQty" }
                    , { field: 'HBQty', title: '内箱数', width: 100 }
                    , { field: 'HWXQty', title: '外箱包装数', width: 100, edit: 'text', event: "inputHWXQty" }
                    , { field: 'HWBQty', title: '外箱数', width: 100 }
                    , { field: 'HPrice', title: '单价', width: 100, hide: true }
                    , { field: 'HMoney', title: '金额', width: 100, hide: true }
                    , { field: 'HMTONO', title: '计划跟踪单号', width: 100 }
                    , { field: 'HBatchNo', title: '批次', width: 100, edit: 'text' }
                    //, { field: 'HBeginDate', title: '生产日期', width: 120, data_field: 'HBeginDate', event: "chooseHBeginDate" }
                    //, { field: 'HEndDate', title: '失效日期', width: 120, data_field: 'HEndDate', event: "chooseHEndDate" }
                    , { field: 'HKFDate', title: '生产日期', align: 'center', width: 150, data_field: 'HKFDate', event: "chooseHKFDate" }//
                    , { field: 'HKFPeriod', title: '保质期', width: 100, edit: 'text', event: "inputHKFPeriod" }//
                    , { field: 'HKFDQDate', title: '到期日期', align: 'center', width: 150, data_field: 'HKFDQDate', event: "chooseHKFDQDate" }//
                    //, { field: 'HDate', title: '要求交货日期', width: 150 }
                    , { field: 'HPOOrderInterID', title: '采购订单主内码', width: 150, hide: true }
                    , { field: 'HPOOrderEntryID', title: '采购订单子内码', width: 150, hide: true }
                    , { field: 'HPOOrderBillNo', title: '采购订单号', width: 200 }
                    , { field: 'HWWOrderInterID', title: '委外订单主内码', width: 150, hide: true }
                    , { field: 'HWWOrderEntryID', title: '委外订单子内码', width: 150, hide: true }
                    , { field: 'HWWOrderDetaiLID    ', title: '委外订单明细内码', width: 150, hide: true }
                    , { field: 'HWWOrderBillNo', title: '委外订单单号', width: 200 }
                    , { field: 'HSourceBillType', title: '源单类型', width: 100 }
                    , { field: 'HSourceBillNo', title: '源单单号', width: 200 }
                    , { field: 'HSourceEntryID', title: '源单子内码', width: 150, hide: true }
                    , { field: 'HSourceInterID', title: '源单主内码', width: 150, hide: true }
                    , { field: 'HSupID', title: '供应商ID', width: 150, hide: true }
                    , { field: 'HSupName', title: '供应商名称', width: 150, hide: true }
 
                ]]
                , done: function (res, curr, count) {
                    layer.closeAll("loading");
                }
            });
            //头工具栏事件
            table.on('toolbar(mainTable)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
 
                    //自定义头工具栏
                    case 'btn-normal':
                        table.render({
                            elem: '#mainTable'
                            , url: GetWEBURL() + 'GetHBarCodeShowBillSub'
                            , toolbar: '#toolbarDemo' //开启头部工具栏,并为其绑定左侧模板
                            , defaultToolbar: ['filter', 'exports']
                            , where: { sMsg: linterid, sMsg2: lentryid }
                            , cols: [[
                                , { field: 'HMaterID', title: '物料ID', width: 100, hide: true }
                                , { field: 'HMaterNumber', title: '物料代码', width: 100 }
                                , { field: 'HMaterName', title: '物料名称', width: 200 }
                                , { field: 'HMaterModel', title: '规格型号', width: 200 }
                                , { field: 'HUnitName', title: '计量单位', width: 100 }
                                , { field: 'HUnitNumber', title: '计量单位代码', width: 100, hide: true }
                                , { field: 'HUnitID', title: '计量单位ID', width: 100, hide: true }
                                , { field: 'HQty', title: '数量', width: 100 }
                                , { field: 'HMinQty', title: '最小包装数', width: 100, edit: 'text' }
                                , { field: 'HBQty', title: '条码张数', width: 100 }
                                , { field: 'HPrice', title: '单价', width: 100, hide: true }
                                , { field: 'HMoney', title: '金额', width: 100, hide: true }
                                , { field: 'HMTONO', title: '计划跟踪单号', width: 100 }
                                , { field: 'HBatchNo', title: '批次', width: 100, edit: 'text' }
                                //, { field: 'HBeginDate', title: '生产日期', width: 120, data_field: 'HBeginDate', event: "chooseHBeginDate" }
                                //, { field: 'HEndDate', title: '失效日期', width: 120, data_field: 'HEndDate', event: "chooseHEndDate" }
                                , { field: 'HKFDate', title: '生产日期', align: 'center', width: 150, data_field: 'HKFDate', event: "chooseHKFDate" }
                                , { field: 'HKFPeriod', title: '保质期', width: 100, edit: 'text', event: "inputHKFPeriod" }
                                , { field: 'HKFDQDate', title: '到期日期', align: 'center', width: 150, data_field: 'HKFDQDate', event: "chooseHKFDQDate" }
                                //, { field: 'HDate', title: '要求交货日期', width: 150 }
                                , { field: 'HPOOrderInterID', title: '采购订单主内码', width: 150, hide: true }
                                , { field: 'HPOOrderEntryID', title: '采购订单子内码', width: 150, hide: true }
                                , { field: 'HPOOrderBillNo', title: '采购订单号', width: 200 }
                                , { field: 'HWWOrderInterID', title: '委外订单主内码', width: 150, hide: true }
                                , { field: 'HWWOrderEntryID', title: '委外订单子内码', width: 150, hide: true }
                                , { field: 'HWWOrderDetaiLID    ', title: '委外订单明细内码', width: 150, hide: true }
                                , { field: 'HWWOrderBillNo', title: '委外订单单号', width: 200 }
                                , { field: 'HSourceBillType', title: '源单类型', width: 100 }
                                , { field: 'HSourceBillNo', title: '源单单号', width: 200 }
                                , { field: 'HSourceEntryID', title: '源单子内码', width: 150, hide: true }
                                , { field: 'HSourceInterID', title: '源单主内码', width: 150, hide: true }
                                , { field: 'HSupID', title: '供应商ID', width: 150, hide: true }
                            ]]
                            , done: function () {
                                layer.closeAll("loading");
                            }
                        });
                        break;
                    case "btn-box":
                        table.render({
                            elem: '#mainTable'
                            , url: GetWEBURL() + 'GetHBarCodeShowBillSub'
                            , toolbar: '#toolbarDemo' //开启头部工具栏,并为其绑定左侧模板
                            , defaultToolbar: ['filter', 'exports']
                            , where: { sMsg: linterid, sMsg2: lentryid }
                            , cols: [[
                                , { field: 'HMaterID', title: '物料ID', width: 100, hide: true }
                                , { field: 'HMaterNumber', title: '物料代码', width: 100 }
                                , { field: 'HMaterName', title: '物料名称', width: 200 }
                                , { field: 'HMaterModel', title: '规格型号', width: 200 }
                                , { field: 'HUnitName', title: '计量单位', width: 100 }
                                , { field: 'HUnitNumber', title: '计量单位代码', width: 100, hide: true }
                                , { field: 'HUnitID', title: '计量单位ID', width: 100, hide: true }
                                , { field: 'HQty', title: '数量', width: 100 }
                                , { field: 'HMinQty', title: '内箱包装数', width: 100, edit: 'text' }
                                , { field: 'HBQty', title: '内箱数', width: 100 }
                                , { field: 'HWXQty', title: '外箱包装数', width: 100, edit: 'text' }
                                , { field: 'HWBQty', title: '外箱数', width: 100 }
                                , { field: 'HPrice', title: '单价', width: 100, hide: true }
                                , { field: 'HMoney', title: '金额', width: 100, hide: true }
                                , { field: 'HMTONO', title: '计划跟踪单号', width: 100 }
                                , { field: 'HBatchNo', title: '批次', width: 100, edit: 'text' }
                                , { field: 'HKFDate', title: '生产日期', align: 'center', width: 150, data_field: 'HKFDate', event: "chooseHKFDate" }
                                , { field: 'HKFPeriod', title: '保质期', width: 100, edit: 'text', event: "inputHKFPeriod" }
                                , { field: 'HKFDQDate', title: '到期日期', align: 'center', width: 150, data_field: 'HKFDQDate', event: "chooseHKFDQDate" }
                                //, { field: 'HDate', title: '要求交货日期', width: 150 }
                                , { field: 'HPOOrderInterID', title: '采购订单主内码', width: 150, hide: true }
                                , { field: 'HPOOrderEntryID', title: '采购订单子内码', width: 150, hide: true }
                                , { field: 'HPOOrderBillNo', title: '采购订单号', width: 200 }
                                , { field: 'HWWOrderInterID', title: '委外订单主内码', width: 150, hide: true }
                                , { field: 'HWWOrderEntryID', title: '委外订单子内码', width: 150, hide: true }
                                , { field: 'HWWOrderDetaiLID    ', title: '委外订单明细内码', width: 150, hide: true }
                                , { field: 'HWWOrderBillNo', title: '委外订单单号', width: 200 }
                                , { field: 'HSourceBillType', title: '源单类型', width: 100 }
                                , { field: 'HSourceBillNo', title: '源单单号', width: 200 }
                                , { field: 'HSourceEntryID', title: '源单子内码', width: 150, hide: true }
                                , { field: 'HSourceInterID', title: '源单主内码', width: 150, hide: true }
                                , { field: 'HSupID', title: '供应商ID', width: 150, hide: true }
                            ]]
                            , done: function () {
                                layer.closeAll("loading");
                            }
                        });
                        break;
 
 
                };
            });
            //监听行工具事件
            table.on('tool(mainTable)', function (obj) {
                var data = obj.data;
                if (obj.event === 'chooseHKFDate') {
                    var field = $(this).data('field');
                    laydate.render({
                        elem: this.firstChild
                        , show: true //直接显示
                        , closeStop: this
                        , done: function (value, date) {
                            data[field] = value;
                            obj.update(data);
                            if (parseInt(obj.data.HKFPeriod) >= 0) {
                                var sKFDQDate = addDate(value, parseInt(obj.data.HKFPeriod));
                                obj.update({
                                    HKFDQDate: sKFDQDate,
                                });
                            }
                        }
                    });
                }
                else if (obj.event == 'chooseHKFDQDate') {
                    var field = $(this).data('field');
                    laydate.render({
                        elem: this.firstChild
                        , show: true //直接显示
                        , closeStop: this
                        , done: function (value, date) {
                            data[field] = value;
                            obj.update(data);
                            if (obj.data.HKFDQDate != "" && obj.data.HKFDate != "") {
                                var days = DateDiff(obj.data.HKFDQDate, obj.data.HKFDate);
                                obj.update({
                                    HKFPeriod: days,
                                });
                            }
                        }
                    });
                }
                else if (obj.event == 'chooseHBeginDate') {
                    var field = $(this).data('field');
                    laydate.render({
                        elem: this.firstChild
                        , show: true //直接显示
                        , closeStop: this
                        , done: function (value, date) {
                            data[field] = value;
                            obj.update(data);
 
                        }
                    });
                }
                else if (obj.event == 'chooseHEndDate') {
                    var field = $(this).data('field');
                    laydate.render({
                        elem: this.firstChild
                        , show: true //直接显示
                        , closeStop: this
                        , done: function (value, date) {
                            data[field] = value;
                            obj.update(data);
 
                        }
                    });
                }
                else if (obj.event == 'inputHKFPeriod') {
                    $(obj.tr).find(".layui-table-edit").keyup(function () {
                        var $input = $(this), val = $input.val();
                        if (!val) val = "1";
                        $input.val(val.replace(/[^\d]/g, ''));
                    });
                }
                else if (obj.event == 'inputHQty') {
                    $(obj.tr).find(".layui-table-edit").keyup(function () {
                        var $input = $(this), val = $input.val();
                        if (!val) val = "0";
                        $input.val(val.replace(/[^\d]/g, ''));
                    });
                }
                else if (obj.event == 'inputHMinQty') {
                    $(obj.tr).find(".layui-table-edit").keyup(function () {
                        var $input = $(this), val = $input.val();
                        if (!val) val = "0";
                        $input.val(val.replace(/[^\d]/g, ''));
                    });
                }
                else if (obj.event == 'inputHWXQty') {
                    $(obj.tr).find(".layui-table-edit").keyup(function () {
                        var $input = $(this), val = $input.val();
                        if (!val) val = "0";
                        $input.val(val.replace(/[^\d]/g, ''));
                    });
                }
            });
            table.on('edit(mainTable)', function (obj) { //注:edit是固定事件名,test是table原始容器的属性 lay-filter="对应的值"
                var value = obj.value //得到修改后的值
                    , data = obj.data //得到所在行所有键值
                    , field = obj.field; //得到字段
 
                var HMinQty = 0;
                var HWXQty = 0;
                var HKFPeriod = 0;
                var HWBQty = 0;
                var HBQty = 0;
                if (obj.data.HMinQty != undefined) {
                    HMinQty = parseFloat(obj.data.HMinQty);
                }
                if (obj.data.HWXQty != undefined) {
                    HWXQty = parseFloat(obj.data.HWXQty);
                }
                if (obj.data.HKFPeriod != undefined) {
                    HKFPeriod = parseFloat(obj.data.HKFPeriod);
                }
                if (obj.data.HWBQty != undefined) {
                    HWBQty = parseFloat(obj.data.HWBQty);
                }
                if (obj.data.HBQty != undefined) {
                    HBQty = parseFloat(obj.data.HBQty);
                }
                //HMinQty 内箱包装数
                //HBQty 内箱数
                //HWXQty 外箱包装数
                //HWBQty 外箱数 HWBQty
                switch (field) {
                    case "HQty":
                        obj.update({
                            HMinQty: 0,
                            HBQty: 0,
                            HWXQty: 0,
                            HWBQty: 0,
                        });
                        break;
                    case "HMinQty": //内箱包装数
                        if (HMinQty < 0) {
                            f_alert("内箱包装数不能为负数!");
                        }
                        else if (HWXQty > 0 && HMinQty > HWXQty) {
                            f_alert("内箱包装数量不能超出外箱包装数量")
                            obj.update({
                                HBQty: Math.ceil(parseFloat(obj.data.HQty) / parseFloat(obj.value)),
                                HWXQty: 0,
                                HWBQty: 0,
                            });
                            return;
                        }
                        else (HWXQty > 0)//外箱包装数大于0时候
                        {
                            obj.update({
                                //外箱包装总数 =  内箱数量/外箱数量 * 内箱包装数量
                                HBQty: Math.ceil(parseFloat(obj.data.HQty) / parseFloat(obj.value)),
 
                            });
                            if (parseFloat(obj.data.HWBQty) > 0)
                                obj.update({
                                    HWXQty: Math.ceil(parseFloat(obj.data.HBQty) / parseFloat(obj.data.HWBQty)) * parseFloat(obj.data.HMinQty),
                                });
                        }
                        break;
                    case "HWXQty":
                        if (HWXQty > 0) {
                            if (HMinQty >= 0) {
                                if (isPositiveIntegerTimes(HMinQty, parseFloat(obj.value))) //外箱包装数能被内箱包装数整除
                                {
                                    obj.update({
                                        HWBQty: Math.ceil(parseFloat(obj.data.HQty) / parseFloat(obj.value)),
                                    });
                                }
                                else {
                                    //obj.update({
                                    //    HWXQty: 0,
                                    //});
                                    f_alert("外箱包装数必须是内箱包装数的整数倍!");
                                }
                            }
                        }
                        else {
                            //obj.update({
                            //    HWXQty: 0,
                            //});
                            f_alert("外箱包装数不能为负数!");
                        }
                        break;
                    case "HKFPeriod":
                        if (HKFPeriod >= 0) {
                            var sKFDQDate = addDate(obj.data.HKFDate, HKFPeriod);
                            obj.update({
                                HKFDQDate: sKFDQDate,
                            });
                        }
                }
 
 
            });
            var $ = layui.$, active = {
                reload: function () {
                    var demoReload = $('#mainTable');
                    //执行重载
                    table.reload('mainTable', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            key: {
                                id: demoReload.val()
                            }
                        }
                    });
                }
            };
 
            $('.test-table-reload-btn .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
</body>
</html>