1
duhe
2026-03-02 cc91c286ed8384f9f43d0024a3459da989895ca6
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; 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, maximum-scale=1">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../../layuiadmin/Scripts/jquery-1.4.1.js"></script>
    <script src="../../../layuiadmin/PubCustom.js"></script>
    <script src="../../../layuiadmin/MESLanguage.js"></script>
    <script src="../../../layuiadmin/Scripts/webConfig.js"></script>
    <style>
        .layui-form-item .layui-inline {
            margin-right: 0;
        }
 
        html {
            background-color: white;
            color: white;
        }
 
        .bottom-btn {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background: white;
            padding: 15px;
            border-top: 1px solid #e6e6e6;
            text-align: right;
            z-index: 1000;
        }
 
        .btn-a {
            background-color: #3A78FF;
            color: #fff;
            border: none;
        }
 
        .btn-c {
            background-color: #acacac;
            color: #fff;
            border: none;
        }
 
        .btn-d {
            background-color: #ff8901;
            color: #fff;
            border: none;
        }
 
        .result-modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 9999;
        }
 
        .modal-mask {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
        }
 
        .modal-content {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 90%;
            max-width: 800px;
            background: #fff;
            border-radius: 4px;
            overflow: hidden;
        }
 
        .modal-header {
            padding: 15px;
            border-bottom: 1px solid #eee;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
 
        .modal-body {
            padding: 15px;
            max-height: 60vh;
            overflow-y: auto;
        }
 
        .modal-footer {
            padding: 15px;
            border-top: 1px solid #eee;
            display: flex;
            align-items: center;
        }
 
        .form-container {
            padding-bottom: 80px; 
        }
 
        .layui-table {
            width: 100%;
        }
 
        .layui-tab-content {
            min-height: 400px;
        }
 
        .layui-form-checkbox[lay-skin=primary] span {
            padding-left: 28px;
        }
 
        .layui-form-checkbox[lay-skin=primary] i {
            left: 0;
        }
    </style>
</head>
 
<body>
    <div class="layui-fluid" style="padding: 0;">
        <div class="layui-card" style="padding: 2px;background-color: #efefef;">
            <div class="layui-card-body" style="padding: 1px;">
                <div class="layui-card-header">
                    <div class="layui-btn-group">
                        <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" id="btnAddNew">新增</button>
                        <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" id="btnExit">退出</button>
                    </div>
                </div>
                <div class="form-container">
                    <div class="layui-form" action="" lay-filter="formData" style="background-color:white;">
                        <div class="layui-form-item" style="padding-top: 10px;">
                            <div class="layui-row">
                                <div class="layui-col-xs4 layui-inline">
                                    <h1 style="text-align:center;"><b>扫码组托</b></h1>
                                </div>
                                <div class="layui-col-xs4 layui-inline">
                                    <label class="layui-form-label"><span style="color:red;">*</span>条码</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="HBarCode" id="HBarCode" placeholder="请键入后回车" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                        </div>
 
                        <div class="layui-tab" lay-filter="tab-PackUnionBill">
                            <ul class="layui-tab-title" lay-filter="tab-all">
                                <li lay-id="1" style="padding:1px;" class="layui-this">装箱信息</li>
                                <li lay-id="2" style="padding:1px;">单据信息</li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">
                                    <table class="layui-hide" id="mainTable" lay-filter="mainTable"></table>
                                </div>
 
 
                                <div class="layui-tab-item">
                                    <div class="layui-form-item">
                                        <div class="layui-row">
                                            <div class="layui-col-xs4 layui-inline">
                                                <label class="layui-form-label">单据日期</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" class="layui-input" name="HDate" id="HDate" readonly>
                                                </div>
                                            </div>
                                            <div class="layui-col-xs4 layui-inline">
                                                <label class="layui-form-label">制单人</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" class="layui-input" name="HMaker" id="HMaker" readonly>
                                                </div>
                                            </div>
                                            <div class="layui-col-xs4 layui-inline">
                                                <label class="layui-form-label">单据号</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" class="layui-input" name="HBillNo" id="HBillNo" readonly>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-row">
                                            <div class="layui-col-xs4 layui-inline">
                                                <label class="layui-form-label">单据ID</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" class="layui-input" name="HInterID" id="HInterID" readonly>
                                                </div>
                                            </div>
                                            <div class="layui-col-xs4 layui-inline">
                                                <label class="layui-form-label">组织</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" class="layui-input" name="HStockOrgName" id="HStockOrgName" readonly>
                                                </div>
                                            </div>
                                            <div class="layui-col-xs4 layui-inline">
                                                <label class="layui-form-label">质量审批</label>
                                                <div class="layui-input-inline">
                                                    <input type="checkbox" name="HQualityApproval" id="HQualityApproval" lay-skin="primary" title="质量审批">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="bottom-btn">
                    <button type="button" class="layui-btn btn-a" id="btnSubmit">提交</button>
                    <button type="button" class="layui-btn btn-d" id="btnDelete">删除</button>
                    <button type="button" class="layui-btn btn-c" id="btnExit2">退出</button>
                </div>
 
                <div class="result-modal" id="resultModal" style="display: none;">
                    <div class="modal-mask" id="modalMask"></div>
                    <div class="modal-content">
                        <div class="modal-header">
                            <span class="modal-title">装箱结果</span>
                            <i class="layui-icon layui-icon-close" id="closeModal" style="cursor:pointer;"></i>
                        </div>
                        <div class="modal-body">
                            <table class="layui-hide" id="resultTable" lay-filter="resultTable"></table>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="layui-btn btn-a" id="btnAddNew2">新增</button>
                            <div style="flex: 1;"></div>
                            <button type="button" class="layui-btn btn-c" id="closeModal2">关闭</button>
                            <button type="button" class="layui-btn btn-d" id="btnPrint">打印</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
 
    <script>
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate', 'table', 'element'], function () {
            var $ = layui.$
                , admin = layui.admin
                , layer = layui.layer
                , table = layui.table
                , form = layui.form
                , element = layui.element;
 
            // 公共变量
            var EnableSubmit = true;
            var HBarCode = ''; 
            var tabs = 0;
            var HBillType = '3783';
            var HBillSubType = '1'; 
            var OperationType = 1; 
            var HMaterNumber_Pack = ""; 
            var listData = [];
            var selectedRows = []; 
            var HModName = "Sc_PackUnionBill_Packing_PDA";
            var ModRightName = "CE_PackUnionBill_Packing"; 
            var titleData = []; 
            var OperationType = 1; 
            var HBarCode_Pack_Temp = ""; 
            var tableHeight = 400;
 
            // 表单提交值
            var hform = {
                HBarCode_middle:[],
                HDate: getCurrentDate(),
                HMaker: sessionStorage["Czybm"], 
                HInterID: '',
                HStockOrgName: sessionStorage["Organization"],
                HStockOrgID: '1',
                HQualityApproval: false,
                HMainID: '',
                HSubID: '',
                HSourceBillSEQ: '',
                HBillNo: '',
                HMaterNumber: '',
                HMaterID: '',
                HMaterName: '',
                HMaterModel: '',
                HCusModel: '',
                HCusMaterName: '',
                HEmpID: '001',
                HEmpNumber: '001',
                HEmpName: 'admin',
                HGroupID: 0,
                HGroupNumber: '',
                HGroupName: '',
                HMTONo: '',
                HCheckEmpName: '',
                HExpiryDate: getCurrentDate(),
                HExpirationDateFlag: 0,
                HRemark: '',
                HCoilNO: '',
                HFurnaceNO: '',
                HFactory: '',
                HAuxQty: 0,
                HheatNO: '',
                HProduceDate: getCurrentDate(),
                HSPID: 0,
                HSPCode: '',
                HSPName: '',
                HWHID: 0,
                HWHCode: '',
                HWHName: '',
                HQtyMust: 0,
                HQty: 1,
                HBQty: 1,
                HMinQty: 1,
                HPackQty: 0,
                HPrice: 0,
                HMoney: 0,
                HUseLife: 0,
                HLeaveLife: 0,
                HDesignLife: 0,
            };
            function init() {
                form.val('formData', hform);
                getMaxNo();
                initTable();
                initResultTable();
                calculateTableHeight();
                bindEvents();
            }
 
            function getCurrentDate() {
                var now = new Date();
                var year = now.getFullYear();
                var month = (now.getMonth() + 1).toString().padStart(2, '0');
                var day = now.getDate().toString().padStart(2, '0');
                return year + '-' + month + '-' + day;
            }
 
            // 获取最大单据号
            function getMaxNo() {
                $.ajax({
                    url: GetWEBURL() + "/WEBSController/GetMaxBillNoAndID_Json",
                    type: "GET",
                    data: { "HBillType": HBillType },
                    success: function (d) {
                        var data = d.data[0];
                        if (d.count == 1) {
                            hform.HInterID = data.HInterID;
                            hform.HBillNo = data.HBillNo;
                            form.val('formData', hform);
                        } else {
                            layer.alert(d.Message || '获取单据号失败', { icon: 5 });
                        }
                    },
                    error: function () {
                        layer.alert('获取单据号失败,请检查网络连接', { icon: 5 });
                    }
                });
            }
            function initTable() {
                table.render({
                    elem: '#mainTable',
                    height: tableHeight,
                    limit: 200,
                    cols: [[
                        { type: 'checkbox', fixed: 'left' },
                        { type: 'numbers', field: '序号', title: '序号', totalRow: true },
                        { field: '条码编号', title: '条码编号', width: 120 },
                        { field: '数量', title: '数量', width: 100 },
                        { field: '物料代码', title: '物料代码', width: 120 },
                        { field: '物料名称', title: '物料名称', width: 120 },
                        { field: '条码个数', title: '条码个数', width: 100 },
                        { field: 'HInterID', title: 'HInterID', width: 100, hide: true }
                    ]],
                    data: listData,
                    page: false
                });
            }
 
            function initResultTable() {
                table.render({
                    elem: '#resultTable',
                    cols: [[
                        { field: 'hmainid', title: 'hmainid', width: 120, hide: true },
                        { field: '栈板码', title: '栈板码', width: 120 },
                        { field: '中箱码', title: '中箱码', width: 120 },
                        { field: '日期', title: '日期', width: 100 },
                        { field: '物料', title: '物料', width: 100 }
                    ]],
                    data: [],
                    page: false
                });
            }
 
            function calculateTableHeight() {
                var windowHeight = $(window).height();
                var otherElementsHeight = 300; // 估算其他元素的高度
                tableHeight = windowHeight - otherElementsHeight;
                table.resize('mainTable');
            }
 
            function bindEvents() {
                $('#HBarCode').on('keydown', function (e) {
                    if (e.keyCode === 13) {
                        GetMeesageByBarCode();
                    }
                });
 
                $('#btnSubmit').on('click', function () {
                    cmdSubmit();
                });
 
                $('#btnDelete').on('click', function () {
                    cmdDelete();
                });
 
                $('#btnPrint').on('click', function () {
                    var resultTableData = table.cache['resultTable'];
                       
                    if (resultTableData.length > 0)  {
                        var rows = '';
                        for (var i = 0; i < resultTableData.length; i++) {
                            if (resultTableData[i]['hmainid']) {
                                rows += resultTableData[i]['hmainid'] + ',';
                            }
                        }
                        if (rows.length > 0) {
                            rows = rows.substring(0, rows.length - 1);
                        }
                        layer.open({
                            type: 2
                            , area: ['40%', '80%']
                            , title: '打印模版选择'
                            , shade: 0.6 //遮罩透明度
                            , maxmin: false //允许全屏最小化
                            , anim: 0 //0-6的动画形式,-1不开启
                            , content: ['../../BaseSet/SRM_OpenTmpList.html?linterid=' + rows + '&MyMsg=' + rows + '&Type=HGy_BarCodeBill_xiaowei', 'yes']
                            , resize: false
                        })
                    }
                    else {
                        layer.msg(get_MessageError('[0000-1-016]请选择数据打印!', sessionStorage["HTranSlate"]));
                    }
                });
               
                $('#btnAddNew').on('click', function () {
                    toAddNew();
                });
 
                $('#btnAddNew2').on('click', function () {
                    toAddNew();
                });
 
                $('#btnExit, #btnExit2').on('click', function () {
                    cmdExit();
                });
 
                $('#closeModal, #closeModal2, #modalMask').on('click', function () {
                    closeResultTable();
                });
 
                $(window).on('resize', function () {
                    calculateTableHeight();
                });
            }
 
            // 获取条码信息
            function GetMeesageByBarCode() {
                var sBarCode = $('#HBarCode').val();
                if (sBarCode.substring(0, 4) != 'MZXH') {
                    $.ajax({
                        url: GetWEBURL() + '/WEBSController/getMiddleCodeBySn',
                        type: 'GET',
                        async: false,
                        data: {
                            "HBarCode": sBarCode,
                            "HStockOrgID": hform.HStockOrgID
                        },
                        success: function (res) {
                            if (res.count == 1) {
                                sBarCode = res.data[0].HCaseCode;
                            }
                        },
                        error: function (res) {
                            layer.msg(res.Message || '条码处理失败', { icon: 2 });
                            //layer.msg('条码处理失败,请检查网络连接', { icon: 2 });
                            return;
                        }
                    });
                }
                if (!sBarCode) {
                    layer.msg('条码不能为空,请扫描条码!', { icon: 2 });
                    return;
                }
                hform.HBarCode_middle.push(sBarCode);
                console.log(hform.HBarCode_middle)
                console.log(sBarCode.toString().charAt(sBarCode.length - 1))
                if (sBarCode.toString().charAt(sBarCode.length - 1) != "W") {
                    
                    if (listData.length > 0) {
                        // 获取当前条码的后9-10位(从后往前数第9和第8位)
                        if (sBarCode.length >= 10) {
                            var currentLast9to10 = sBarCode.substr(-14, 2); // 获取倒数第9位开始的2位字符
                            // 获取上一条条码的对应位置
                            var lastBarCode = listData[listData.length - 1]['条码编号'];
                            if (lastBarCode.length >= 10) {
                                var lastLast9to10 = lastBarCode.substr(-14, 2);
                                if (currentLast9to10 !== lastLast9to10) {
                                    layer.msg(`当前条码倒数14-15位(${currentLast9to10})与上一条条码(${lastLast9to10})不同,请检查!`, { icon: 5 });
                                    $('#HBarCode').val('');
                                    return;
                                }
                            }
                        }
                    }
                }
                else {
                    if (listData.length > 0) {
                        // 获取当前条码的后9-10位(从后往前数第9和第8位)
                        if (sBarCode.length >= 10) {
                            var currentLast9to10 = sBarCode.substr(-10, 2); // 获取倒数第9位开始的2位字符
                            // 获取上一条条码的对应位置
                            var lastBarCode = listData[listData.length - 1]['条码编号'];
                            if (lastBarCode.length >= 10) {
                                var lastLast9to10 = lastBarCode.substr(-10, 2);
                                if (currentLast9to10 !== lastLast9to10) {
                                    layer.msg(`当前条码倒数10-11位(${currentLast9to10})与上一条条码(${lastLast9to10})不同,请检查!`, { icon: 5 });
                                    $('#HBarCode').val('');
                                    return;
                                }
                            }
                        }
                    }
                }
                // 如果已有条码数据(不是第一条)
                
                FindMaterial(sBarCode).then(function (materialInfo) {
                    if (!materialInfo) {
                        layer.msg('未找到物料信息', { icon: 2 });
                        return;
                    }
                    hform.HMaterID = materialInfo.HMaterID;
                    hform.HMaterNumber = materialInfo.HMaterNumber;
                    hform.HMaterName = materialInfo.HMaterName;
                    hform.HMaterModel = materialInfo.HMaterModel;
                    $.ajax({
                        url: GetWEBURL() + '/WEBSController/get_BarCode_PackUnionBill_New_Json_xiaowei',
                        type: 'GET',
                        data: {
                            "HInterID": hform.HInterID,
                            "HBarCode": sBarCode,
                            "HBillType": HBillType,
                            "HBillSubType": HBillSubType,
                            "HBarCode_Pack": '',
                            "HBillNo": hform.HBillNo,
                            "HMaterNumber_Pack": HMaterNumber_Pack,
                            "HMaker": hform.HMaker,
                            "HStockOrgID": hform.HStockOrgID
                        },
                        success: function (res) {
                            if (res.count == 1) {
                                layer.msg('条码处理成功', { icon: 1 });
                                listData.push({
                                    条码编号: sBarCode,
                                    数量: 1,
                                    物料代码: hform.HMaterNumber,
                                    物料名称: hform.HMaterName,
                                    条码个数: 1,
                                    HInterID: hform.HInterID
                                });
 
                                table.reload('mainTable', {
                                    data: listData
                                });
 
                                $('#HBarCode').val('');
                            } else {
                                layer.msg(res.Message || '条码处理失败', { icon: 2 });
                            }
                        },
                        error: function () {
                            layer.msg('条码处理失败,请检查网络连接', { icon: 2 });
                        }
                    });
                }).catch(function (error) {
                    layer.msg('查找物料失败: ' + error, { icon: 2 });
                });
            }
 
 
            function FindMaterial(sBarCode) {
                return new Promise(function (resolve, reject) {
                    $.ajax({
                        url: GetWEBURL() + '/Gy_Material/findMaterialByNumber',
                        type: 'GET',
                        data: {
                            "HbarCode": sBarCode,
                            "HSTOCKORGID": hform.HStockOrgID
                        },
                        success: function (res) {
                            let data = res.data;
                            if (res.count == 1) {
                                resolve({
                                    HMaterID: data[0].HMaterID,
                                    HMaterNumber: data[0].HMaterNumber,
                                    HMaterName: data[0].HMaterName_m,
                                    HMaterModel: data[0].HMaterModel
                                });
                            } else {
                                resolve(null); 
                            }
                        },
                        error: function () {
                            reject('查找物料失败,请检查网络连接');
                        }
                    });
                });
            }
 
            function submitPreCheck() {
                if (!hform.HInterID) {
                    layer.msg('单据内码获取失败,错误的单据内码!', { icon: 2 });
                    return false;
                }
                if (!hform.HBillNo) {
                    layer.msg('单据号获取失败,错误的单据号!', { icon: 2 });
                    return false;
                }
                if (listData.length < 1) {
                    layer.msg('没有扫码信息,请先扫描条码,确认无误后再提交!', { icon: 2 });
                    return false;
                }
                return true;
            }
 
            // 删除选中行
            function cmdDelete() {
                var checkStatus = table.checkStatus('mainTable');
                if (checkStatus.data.length !== 1) {
                    layer.msg('请选择一行记录,进行删除!', { icon: 2 });
                    return;
                }
 
                layer.confirm('确认要删除选中行所有扫码记录?删除后将不可恢复!', { icon: 3, title: '删除确认' }, function (index) {
                    var selectedRow = checkStatus.data[0];
                    var indexToRemove = listData.findIndex(function (item) {
                        return item['条码编号'] === selectedRow['条码编号'];
                    });
 
                    if (indexToRemove > -1) {
                        listData.splice(indexToRemove, 1);
                    }
 
                    table.reload('mainTable', {
                        data: listData
                    });
 
                    layer.msg('删除成功!', { icon: 1 });
                    layer.close(index);
                });
            }
 
            // 提交
            function cmdSubmit() {
                var checkRes = submitPreCheck();
                if (!checkRes) {
                    return;
                }
                EnableSubmit = false;
                $('#btnSubmit').addClass('layui-btn-disabled').attr('disabled', true);
 
                // 生成条码
                getBarCode_pack().then(function () {
                    console.log(HBillType)
                    $.ajax({
                        url: GetWEBURL() + '/WEBSController/set_SavePackUnionBill_Json',
                        type: 'GET',
                        data: {
                            "HInterID": hform.HInterID,
                            "HBillType": HBillType,
                            "HBillNo": hform.HBillNo,
                            "HBarCode_Pack": HBarCode_Pack,
                            "HMaker": hform.HMaker,
                            "HStockOrgID": hform.HStockOrgID
                        },
                        success: function (res) {
                            console.log(HBarCode_Pack);
                            if (res.count == 1) {
                                layer.msg('提交成功', { icon: 1 });
 
                                getResultTableData();
                            } else {
                                layer.msg(res.Message || '提交失败', { icon: 2 });
                                EnableSubmit = true;
                                $('#btnSubmit').removeClass('layui-btn-disabled').attr('disabled', false);
                            }
                        },
                        error: function () {
                            layer.msg('提交失败,请检查网络连接', { icon: 2 });
                            EnableSubmit = true;
                            $('#btnSubmit').removeClass('layui-btn-disabled').attr('disabled', false);
                        }
                    });
                }).catch(function (error) {
                    layer.msg('条码生成失败: ' + error, { icon: 2 });
                    EnableSubmit = true;
                    $('#btnSubmit').removeClass('layui-btn-disabled').attr('disabled', false);
                });
            }
 
            // 生成条码
            function getBarCode_pack() {
                return new Promise(function (resolve, reject) {
                    var sBarCode = hform.HBarCode_middle[0];
                    var sMainStr = JSON.stringify(hform);
                    var omain = sMainStr + ';' + hform.HStockOrgName + ';' + hform.HEmpName + ';' + sBarCode;
 
                    $.ajax({
                        url: GetWEBURL() + '/Sc_BarCode/Sub_SaveBill_xiaowei',
                        type: 'POST',
                        data: { "msg": omain },
                        success: function (res) {
                            if (res.count == 1) {
                                HBarCode_Pack = res.data[0]['条码编号'];
                                resolve(HBarCode_Pack);
                            } else {
                                reject(res.Message || '条码生成失败');
                            }
                        },
                        error: function () {
                            reject('条码生成请求失败');
                        }
                    });
                });
            }
 
            function getResultTableData() {
                $.ajax({
                    url: GetWEBURL() + '/WEBSController/get_SavePackUnion_xiaowei',
                    type: 'GET',
                    data: { "HBarCode_Pack": HBarCode_Pack },
                    success: function (res) {
                        if (res.count == 1) {
                            var resultData = res.data;
 
                            table.reload('resultTable', {
                                data: resultData
                            });
 
                            $('#resultModal').show();
                        } else {
                            layer.msg(res.Message || '获取数据失败', { icon: 2 });
                            EnableSubmit = true;
                            $('#btnSubmit').removeClass('layui-btn-disabled').attr('disabled', false);
                        }
                    },
                    error: function () {
                        layer.msg('获取结果数据失败,请检查网络连接', { icon: 2 });
                        EnableSubmit = true;
                        $('#btnSubmit').removeClass('layui-btn-disabled').attr('disabled', false);
                    }
                });
            }
 
            // 新增
            function toAddNew() {
                $('#resultModal').hide();
                HBarCode_Pack = '';
                $('#HBarCode').val('');
                listData = [];
                table.reload('mainTable', { data: listData });
                getMaxNo();
                EnableSubmit = true;
                $('#btnSubmit').removeClass('layui-btn-disabled').attr('disabled', false);
            }
 
            
            function closeResultTable() {
                $('#resultModal').hide();
            }
 
            // 退出
            function cmdExit() {
                layer.confirm('您确定要退出吗?', { icon: 3, title: '提示' }, function (index) {
                    
                    console.log('退出操作');
                    layer.close(index);
                });
            }
 
            init();
        });
    </script>
</body>
</html>