chenhaozhe
2026-02-05 88af17ff7248af4f435e48fe237d55d31fdd478d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
<template>
    <view class="form">
        <view class="form-base-info">
            <view class="form-item">
                <view class="title">箱条码</view>
                <!-- 按照源单物料样式添加disabled类和禁用属性 -->
                <view class="right" :class="disableBarCodePack ? 'disabled' : ''">
                    <input type="text" :focus="HBarCodePackFocus" v-model="HBarCode_Pack"
                        @confirm="GetMeesageByBarCode_Pack(HBarCode_Pack)" :disabled="disableBarCodePack" />
                </view>
                <view class="right-icon">
                    <uni-icons class="right-icon" :class="disableBarCodePack ? 'disabled':''" type="scan"
                        style="background-color: #3A78FF;padding: 6rpx;color: #fff;border-radius: 100%;" size="20"
                        @click="toScanCode" :disabled="disableBarCodePack"></uni-icons>
                </view>
            </view>
            <view class="form-item">
                <view class="title">产品码</view>
                <!-- 按照源单物料样式添加disabled类和禁用属性 -->
                <view class="right" :class="disableBarCode ? 'disabled' : ''">
                    <input type="text" :focus="HBarCodeFocus" v-model="HBarCode"
                        @confirm="GetMeesageByBarCode(HBarCode)" :disabled="disableBarCode" />
                </view>
                <view class="right-icon">
                    <uni-icons class="right-icon" :class="[disableBarCode ? 'disabled':'']" type="scan"
                        style="background-color: #3A78FF;padding: 6rpx;color: #fff;border-radius: 100%;" size="20"
                        @click="toScanCode2" :disabled="disableBarCode"></uni-icons>
                </view>
            </view>
            <view class="form-item">
                <view class="title">已扫数量</view>
                <view class="right disabled">
                    <input type="text" disabled :value="hform.HQtySum" />
                </view>
 
            </view>
        </view>
        <view class="tabs">
            <view :class="tabs == 0 ? 'on':''" @tap="tabs = 0">单据信息</view>
            <view :class="tabs == 1 ? 'on':''" @tap="tabs = 1">装箱信息</view>
        </view>
 
        <!-- 单据信息 -->
        <view v-if="tabs == 0">
            <view class="bill-info">
                <view class="form-item">
                    <view class="title">源单类型:</view>
                    <view class="right" v-show="showHMainSourceBillType" style='position: relative;'>
                        <picker :range="arrayHMainSourceBillType" v-model="HMainSourceBillTypeIndex"
                            @change="HMainSourceBillTypeChange">
                            <input name="HMainSourceBillType" disabled :value="HMainSourceBillType"
                                placeholder="请选择源单类型" />
                            <view class="picker-overlay"></view>
                        </picker>
                    </view>
                    <view class="righton" v-show="!showHMainSourceBillType">
                        <input name="HMainSourceBillType" disabled :value="HMainSourceBillType" placeholder="请选择源单类型" />
                    </view>
                </view>
            </view>
            <view class="bill-info">
                <view class="form-item">
                    <view class="title">源单单号:</view>
                    <view class="right" v-show="showHSourceBillNo">
                        <input :focus="HSourcebillNoFocus" type="text" @confirm="onHSourceBillNoConfirmHandler"
                            name="HSourceBillNo" v-model="hform.HSourceBillNo" placeholder="请输入源单单号" />
                    </view>
                    <view class="icon-wrapper" v-show="showHSourceBillNo" :disabled="hform.HMainSourceBillType === -1">
                        <uni-icons type="search" size="20" @click="showBillList"></uni-icons>
                    </view>
                    <view class="icon-wrapper" v-show="showHSourceBillNo">
                        <uni-icons type="right" size="20" @click="onHSourceBillNoConfirmHandler"></uni-icons>
                    </view>
                    <view class="righton" v-show="!showHSourceBillNo">
                        <input name="HSourceBillNo" disabled v-model="hform.HSourceBillNo" placeholder="请输入源单单号" />
                    </view>
                </view>
            </view>
            <view class="bill-info">
                <view class="form-item">
                    <view class="title">源单物料</view>
                    <view class="right disabled">
                        <input type="text" disabled :value="hform.HMaterName" />
                    </view>
 
                </view>
            </view>
            <view class="bill-info">
                <view class="form-item">
                    <view class="title">单据日期</view>
                    <view class="right">
                        <uni-datetime-picker type="date" v-model="hform.HDate">
                            <input type="text" v-model="hform.HDate" />
                        </uni-datetime-picker>
                    </view>
                </view>
            </view>
            <view class="bill-info">
                <view class="form-item">
                    <view class="title">制单人</view>
                    <view class="right disabled">
                        <input type="text" disabled :value="hform.HMaker" />
                    </view>
                </view>
            </view>
            <view class="bill-info">
                <view class="form-item">
                    <view class="title">单据号</view>
                    <view class="right disabled">
                        <input type="text" disabled :value="hform.HBillNo" />
                    </view>
                </view>
            </view>
            <view class="bill-info">
                <view class="form-item">
                    <view class="title">单据ID</view>
                    <view class="right disabled">
                        <input type="text" disabled :value="hform.HInterID" />
                    </view>
                </view>
            </view>
            <view class="bill-info">
                <view class="form-item">
                    <view class="title">组织</view>
                    <view class="right disabled">
                        <input type="text" disabled :value="hform.HStockOrgName" />
                    </view>
                </view>
            </view>
        </view>
        <!-- 装箱信息 -->
        <view v-if="tabs == 1">
            <zb-table id="list-table" :checked-highlight="true" :fit="true" :style="{height: `${listTableHeight}px`}"
                :columns="columns" :data="listData" :show-header="true" :border="true" :row-key="row => row.index"
                @toggleRowSelection="handleSelect" @toggleAllSelection="handleSelectAll"
                @rowClick="onTableRowClickHandler" />
        </view>
        <view class="bottom-btn" id="bottom-btn">
            <button :class="EnableSubmit?'btn-a':'btn-c'" :disabled="!EnableSubmit" size="mini"
                @tap="cmdSubmit">提交</button>
            <view style="flex: 1;"></view>
            <button class="btn-d" size="mini" @tap="cmdDelete">删除</button>
            <button class="btn-c" size="mini" @tap="cmdExit">退出</button>
        </view>
        <!-- 弹窗组件 -->
        <BillListPopupVue ref="billList" :HBillType="HBillType" :HSourceBillType="hform.HMainSourceBillType || 3710"
            :HStockOrgID="hform.HStockOrgID"></BillListPopupVue>
 
    </view>
</template>
<script>
    import dayjs from 'dayjs'
    import {
        getUserInfo
    } from "../../utils/auth";
    import {
        CommonUtils
    } from "@/utils/common.js"
    import {
        MpaasScan
    } from "@/utils/mpaasScan.js"
    import BillListPopupVue from '../../components/BillListPopup/BillListPopup.vue';
 
    export default {
        data() {
            return {
                // ==================== 布局计算相关 ====================
                // 计算列表高度
                bottomBtnTop: 0,
                listTableTop: 0,
 
                // ==================== 界面状态控制 ====================
                EnableSubmit: true, // 是否允许提交
                disableBarCodePack: true, // 箱条码禁用状态
                disableBarCode: true, // 产品码禁用状态
                HBarCodePackFocus: false, // 箱条码输入框聚焦状态
                HBarCodeFocus: false, // 产品码输入框聚焦状态
                tabs: 0, // 当前选项卡(0:单据信息,1:装箱信息)
 
 
                // ==================== 业务数据 ====================
                HBarCode_Pack: '', // 箱条码
                HBarCode: '', // 产品码
                HBillType: '3783', // 单据类型
                HBillSubType: '1', // 子类型(1装箱、2组托)
                OperationType: 1, // 操作类型(1新增、2从缓存列表中返回)
                HMaterNumber_Pack: "", // 托条码对应物料代码
                HBarCode_Pack_Temp: "", // 从缓存列表中返回箱条码
                BarCodeType: 1, // 条码类型(1:装箱,2:组托)
 
                HSourcebillNoFocus: false, // 源单单号输入框聚焦状态 - 新增这个属性
                showHMainSourceBillType: true,
                showHSourceBillNo: true,
                HMainSourceBillTypeIndex: 0,
                HMainSourceBillType: '生产订单',
                arrayHMainSourceBillType: ['生产订单', '手工录入'],
                arrayHMainSourceBillValue: [3710, -1],
 
                // ==================== 列表数据 ====================
                listOption: [], // 列表选项
                listData: [], // 表格数据
                selectedRows: [], // 表格选中的数据
                columns: [ // 表格列配置
                    {
                        type: 'selection',
                        fixed: true,
                        width: 50
                    },
                    {
                        name: 'index',
                        label: '序号',
                        width: 60,
                        hidden: true
                    },
                    {
                        name: '条码编号',
                        label: '条码编号',
                        width: 100
                    },
                    {
                        name: '数量',
                        label: '数量',
                        width: 100
                    },
                    {
                        name: '物料代码',
                        label: '物料代码',
                        width: 100
                    },
                    {
                        name: '物料名称',
                        label: '物料名称',
                        width: 100
                    },
                    {
                        name: '条码个数',
                        label: '条码个数',
                        width: 100
                    }
                ],
 
                // ==================== 主表单数据 ====================
                hform: {
                    HDate: dayjs(new Date()).format('YYYY-MM-DD'), // 单据日期
                    HMaker: getUserInfo()['Czymc'], // 制单人
                    HBillNo: '', // 单据号
                    HInterID: '', // 单据ID
                    HStockOrgName: uni.getStorageSync("Organization"), // 组织名称
                    HStockOrgID: uni.getStorageSync("OrganizationID"), // 组织ID
                    HMainSourceBillType: 3710, //源单类型
                    HMaterName: '', //源单物料
                    HMaterID: '', //源单物料id
                    HQtySum: '', //外箱码数量
                    totalQty: 0, // 总数
                },
 
                // ==================== 系统配置 ====================
                HModName: "Sc_PackUnionBill_Packing_PDA", // 模块名称
                ModRightName: "CE_PackUnionBill_Packing", // 模块权限参数
                titleData: [] // 不需要显示的字段
            }
        },
        components: {
            BillListPopupVue,
        },
        // ==================== 计算属性 ====================
        computed: {
            // 计算表格高度
            listTableHeight: {
                get() {
                    return this.bottomBtnTop - this.listTableTop - 10
                }
            }
        },
 
        // ==================== 方法 ====================
        methods: {
            // 复选框变化处理
            checkboxGroupChangeHandler(e) {
                let checkBoxValues = Array.from(e.detail.value)
                this.hform.HQualityApproval = checkBoxValues.includes('qualityApproval')
            },
 
            // 表格行点击处理
            onTableRowClickHandler(row, index) {
                if (!this.listData[index].checked) {
                    this.$set(this.listData[index], 'checked', true)
                } else {
                    this.listData[index].checked = !this.listData[index].checked
                }
            },
 
            // 刷新产品码输入框焦点
            async HBarCodeFocusRefresh() {
                this.HBarCode = ''
                this.HBarCodeFocus = false
                await this.$nextTick()
                this.HBarCodeFocus = true
            },
 
            // 刷新箱条码输入框焦点
            async HBarCodePackFocusRefresh() {
                this.HBarCode_Pack = ''
                this.HBarCodePackFocus = false
                await this.$nextTick()
                setTimeout(() => {
                    this.HBarCodePackFocus = true
                }, 60)
            },
 
            // 扫描箱条码
            toScanCode() {
                MpaasScan.scanCode((scanCode) => {
                    this.HBarCode_Pack = scanCode
                    this.GetMeesageByBarCode_Pack(this.HBarCode_Pack)
                })
            },
 
            // 根据箱条码获取信息
            GetMeesageByBarCode_Pack(HBarCode_Pack) {
                CommonUtils.doRequest2({
                    url: '/WEBSController/GetHBarCode_CusJX',
                    data: {
                        HInterID: this.hform.HInterID || 0,
                        HBillNo: this.hform.HBillNo,
                        HBillType: this.HBillType,
                        HBillSubType: this.HBillSubType,
                        HBarCode_Pack: HBarCode_Pack,
                        HSourceBillNo: this.hform.HSourceBillNo,
                    },
                    resFunction: (res) => {
                        let {
                            data,
                            count,
                            Message,
                            list
                        } = res.data
                        if (count == 1) {
                            CommonUtils.doRequest2({
                                url: '/WEBSController/Get_PackBarCode_PackUnionBill_New_Json_Cus',
                                data: {
                                    HInterID: this.hform.HInterID || 0,
                                    HBillNo: this.hform.HBillNo,
                                    HBillType: this.HBillType,
                                    HBillSubType: this.HBillSubType,
                                    HBarCode_Pack: HBarCode_Pack,
                                    HSourceBillNo: this.hform.HSourceBillNo,
                                },
                                resFunction: (res) => {
                                    let {
                                        data,
                                        count,
                                        Message,
                                        list
                                    } = res.data
                                    if (count == 1) {
                                        CommonUtils.playSound(1)
                                        this.hform.HBillNo = data[0].HBillNo
                                        this.hform.HInterID = data[0].HInterID
                                        this.HMaterNumber_Pack = data[0].HMaterNumber
                                        this.hform.HMaterName = data[0].HMaterName
                                        // 设置总数,当前扫描数量通过DisBillEntryList更新
                                        const totalQty = data[0].HQty || 0
                                        this.hform.HQtySum = `0/${totalQty}`
                                        //处理成功后聚焦到产品码输入框
                                        this.HBarCodeFocusRefresh()
                                        this.DisBillEntryList();
                                        uni.showToast({
                                            icon: 'none',
                                            title: Message
                                        })
                                    } else {
                                        CommonUtils.playSound(0)
                                        this.HBarCodePackFocusRefresh()
                                        uni.showToast({
                                            icon: 'none',
                                            title: Message
                                        })
                                    }
                                }
                            })
                        } else {
                            CommonUtils.playSound(0)
                            this.HBarCodePackFocusRefresh()
                            uni.showToast({
                                icon: 'none',
                                title: Message
                            })
                        }
                    }
                })
            },
 
            // 扫描产品码s
            toScanCode2() {
                MpaasScan.scanCode((scanCode) => {
                    this.HBarCode = scanCode
                    this.GetMeesageByBarCode(scanCode)
                })
            },
 
            // 根据产品码获取信息
            GetMeesageByBarCode(HBarCode) {
                let HBarCode_Pack = this.HBarCode_Pack
                let sOldBarCode = this.HBarCode
                let HDeleteFlag = sOldBarCode.substring(0, 1)
                let sBarCode = sOldBarCode.slice(1)
 
                if (!HBarCode_Pack) {
                    return uni.showToast({
                        icon: 'none',
                        title: '箱条码不能为空,请先扫描托条码!'
                    })
                }
                if (HDeleteFlag == '*') {
                    // 删除条码逻辑
                    if (!sBarCode) {
                        return uni.showToast({
                            icon: 'none',
                            title: '请扫描要删除的条码'
                        })
                    } else {
                        this.HBarCodeFocusRefresh()
                    }
                    CommonUtils.doRequest2({
                        url: '/WEBSController/set_DelPackUnionBill_Temp_Pack_Json',
                        data: {
                            "HInterID": this.hform.HInterID,
                            "HBarCode": sBarCode,
                            "HBillType": this.HBillType
                        },
                        resFunction: (res) => {
                            let {
                                data,
                                count,
                                Message
                            } = res.data
                            if (count == 1) {
                                CommonUtils.playSound(1)
                                this.tabs = 1
                                this.DisBillEntryList()
                            } else {
                                CommonUtils.playSound(0)
                                uni.showToast({
                                    icon: 'none',
                                    title: Message
                                })
                            }
                        }
                    })
                } else {
                    // 新增条码逻辑
                    let sBarCode = this.HBarCode
                    if (!sBarCode) {
                        return uni.showToast({
                            icon: 'none',
                            title: '条码不能为空,请扫描条码!'
                        })
                    }
                    CommonUtils.doRequest2({
                        url: '/WEBSController/Get_BarCode_PackUnionBill_New_Json_Cus',
                        data: {
                            "HBarCode": sBarCode,
                            "HInterID": this.hform.HInterID,
                            "HBillNo": this.hform.HBillNo,
                            "HBillType": this.HBillType,
                            "HBillSubType": this.HBillSubType,
                            "HBarCode_Pack": this.HBarCode_Pack,
                            "HMaterNumber_Pack": this.HMaterNumber_Pack,
                            "HMaker": this.hform.HMaker,
                            "HStockOrgID": this.hform.HStockOrgID
                        },
                        resFunction: (res) => {
                            let {
                                data,
                                count,
                                Message
                            } = res.data
                            if (count == 1) {
                                CommonUtils.playSound(1)
                                this.tabs = 1
                                this.HBarCodeFocusRefresh()
                                this.DisBillEntryList()
                            } else {
                                CommonUtils.playSound(0)
                                this.HBarCodeFocusRefresh()
                                uni.showToast({
                                    icon: 'none',
                                    title: Message
                                })
                            }
                        }
                    })
                }
            },
            // 显示单据明细列表
            DisBillEntryList() {
                CommonUtils.doRequest2({
                    url: '/WEBSController/GetBillEntry_Tmp_Pack_Json',
                    data: {
                        "HInterID": this.hform.HInterID,
                        "HBillNo": this.hform.HBillNo,
                        "HBillType": this.HBillType
                    },
                    resFunction: (res) => {
                        let {
                            count,
                            data,
                            Message
                        } = res.data
                        this.listData = []
                        if (count == 1) {
                            for (let i = 0; i < data.length; i++) {
                                this.listData.push(Object.assign(data[i], {
                                    index: i
                                }))
                            }
 
                            // 新增:根据返回的条码列表数量更新已扫数量
                            if (this.hform.HQtySum && this.hform.HQtySum.includes('/')) {
                                const total = this.hform.HQtySum.split('/')[1] // 获取总数
                                const currentScanned = data.length // 当前已扫描数量
                                this.hform.HQtySum = `${currentScanned}/${total}`
                                // 新增:检查是否达到总数,如果是则提示保存
                                if (currentScanned >= total) {
                                    uni.showModal({
                                        title: '提示',
                                        content: '已扫数量已达到上限,是否立即保存?',
                                        confirmText: '保存',
                                        cancelText: '取消',
                                        success: ({
                                            confirm
                                        }) => {
                                            if (confirm) {
                                                // 用户点击保存,调用保存方法
                                                this.cmdSubmit()
                                            } else {
                                                // 用户点击取消,不做任何操作
                                                uni.showToast({
                                                    icon: 'none',
                                                    title: '您可以选择手动保存'
                                                })
                                            }
                                        }
                                    })
                                }
                            } else {
                                // 如果没有数据,重置已扫数量
                                if (this.hform.HQtySum && this.hform.HQtySum.includes('/')) {
                                    const total = this.hform.HQtySum.split('/')[1] // 获取总数
                                    this.hform.HQtySum = `0/${total}`
                                }
                            }
                        } else {
                            // 如果没有数据,重置已扫数量
                            if (this.hform.HQtySum && this.hform.HQtySum.includes('/')) {
                                const total = this.hform.HQtySum.split('/')[1] // 获取总数
                                this.hform.HQtySum = `0/${total}`
                            }
                        }
                    }
                })
            },
 
            // 表格选择处理
            handleSelect(selected, array) {
                this.selectedRows = array
            },
 
            // 表格全选处理
            handleSelectAll(selected, array) {
                this.selectedRows = array
            },
            // 播放提示音
            playSound(type) {
                const innerAudioContext = uni.createInnerAudioContext();
                innerAudioContext.src = type == 1 ? '/static/success.wav' : '/static/jingbao.wav';
                innerAudioContext.play();
            },
 
            // -----------------设置源单信息----------------------------------------------------
            async setSourceBillInfo(data) {
                this.hform.HMaterName = data[0].物料名称
                this.hform.HMaterID = data[0].HMaterID
                this.hform.HSourceBillNo = data[0].单据号
                this.hform.HMainSourceBillType = data[0].HSourceBillType
 
                // 更新源单类型显示
                const index = this.arrayHMainSourceBillValue.findIndex(e => e == data[0].HSourceBillType)
                if (index !== -1) {
                    this.HMainSourceBillType = this.arrayHMainSourceBillType[index]
                    this.HMainSourceBillTypeIndex = index
                    this.showHMainSourceBillType = false
                }
 
                if (data.hMulSourceFlagField == 0) {
                    this.showHSourceBillNo = false
                }
            },
            // 源单类型变更
            HMainSourceBillTypeChange(e) {
                this.HMainSourceBillTypeIndex = e.detail.value
                this.HMainSourceBillType = this.arrayHMainSourceBillType[this.HMainSourceBillTypeIndex]
                this.hform.HMainSourceBillType = this.arrayHMainSourceBillValue[this.HMainSourceBillTypeIndex]
            },
 
            // 源单单号确认
            async onHSourceBillNoConfirmHandler() {
                if (this.hform.HMainSourceBillType == -1) {
                    CommonUtils.playSound(1)
                    return
                }
                // 获取源单状态
                await this.getSourceBarCodeControl(this.hform.HSourceBillNo)
            },
            // 获取源单状态
            async getSourceBarCodeControl(HSourceBillNo) {
                try {
                    let res = await CommonUtils.doRequest2Sync({
                        url: '/WEBSController/GetSourceBillList_Control',
                        data: {
                            HBillType: this.HBillType,
                            HSourceBillType: this.hform.HMainSourceBillType,
                            HStockOrgID: this.hform.HStockOrgID,
                            HSourceBillNo: HSourceBillNo,
                            HMater: '',
                            HCustom: ''
                        }
                    })
 
                    if (res.data.count == 1) {
                        // 获取源单数据
                        await this.getSourceBarCodeData(this.hform.HSourceBillNo)
                    } else {
                        CommonUtils.playSound(0)
                        uni.showToast({
                            title: res.data.Message,
                            icon: 'none'
                        })
                        this.refreshHSourceBillState()
                    }
                } catch (error) {
                    CommonUtils.playSound(0)
                    uni.showToast({
                        title: '获取源单数据失败',
                        icon: 'none'
                    })
                    this.refreshHSourceBillState()
                }
            },
            // 获取源单数据
            async getSourceBarCodeData(HSourceBillNo) {
                try {
                    let res = await CommonUtils.doRequest2Sync({
                        url: '/WEBSController/GetSourceBillList_Json',
                        data: {
                            HBillType: this.HBillType,
                            HSourceBillType: this.hform.HMainSourceBillType,
                            HStockOrgID: this.hform.HStockOrgID,
                            HSourceBillNo: HSourceBillNo,
                            HMater: '',
                            HCustom: ''
                        }
                    })
 
                    if (res.data.count == 1) {
                        CommonUtils.playSound(1)
                        await this.setSourceBillInfo(res.data.data)
                        // 源单数据返回成功后,解除禁用并聚焦到箱条码
                        this.disableBarCodePack = false
                        this.disableBarCode = false
                        this.HBarCodePackFocusRefresh()
                    } else {
                        CommonUtils.playSound(0)
                        uni.showToast({
                            title: res.data.Message,
                            icon: 'none'
                        })
                        this.refreshHSourceBillState()
                    }
                } catch (error) {
                    CommonUtils.playSound(0)
                    uni.showToast({
                        title: '获取源单数据失败',
                        icon: 'none'
                    })
                    this.refreshHSourceBillState()
                }
            },
 
            // 刷新源单输入状态
            async refreshHSourceBillState() {
                this.HSourcebillNoFocus = false
                await this.$nextTick(() => {
                    this.hform.HSourceBillNo = ""
                    this.HSourcebillNoFocus = true
                })
            },
 
            // 显示源单列表
            showBillList() {
                this.$refs.billList.showPopup()
            },
            //--------------------------------------------------------------------------------------
 
            // 获取最大单据号
            getMaxNo() {
                CommonUtils.doRequest2({
                    url: "/WEBSController/GetMaxBillNoAndID_Json",
                    data: {
                        "HBillType": this.HBillType
                    },
                    resFunction: (d) => {
                        let {
                            count,
                            data,
                            Message
                        } = d.data
                        if (count == 1) {
                            this.hform.HInterID = data[0].HInterID;
                            this.hform.HBillNo = data[0].HBillNo
                        } else {
                            uni.showModal({
                                title: "温馨提示",
                                showCancel: false,
                                content: Message
                            })
                        }
                    }
                })
            },
 
            // 提交前检查
            submitPreCheck() {
                if (CommonUtils.isEmpty(this.hform.HInterID)) {
                    uni.showToast({
                        icon: 'none',
                        title: '单据内码获取失败,错误的单据内码!'
                    })
                    return false
                }
                if (CommonUtils.isEmpty(this.hform.HBillNo)) {
                    uni.showToast({
                        icon: 'none',
                        title: '单据号获取失败,错误的单据号!'
                    })
                    return false
                }
                if (this.listData.length < 1) {
                    uni.showToast({
                        icon: 'none',
                        title: '没有扫码信息,请先扫描条码,确认无误后再提交!'
                    })
                    return false
                }
                return true
            },
 
            // 删除选中行
            cmdDelete() {
                if (this.selectedRows.length != 1) {
                    return uni.showToast({
                        icon: 'none',
                        title: '请选择一行记录,进行删除!'
                    })
                }
                uni.showModal({
                    title: '删除确认',
                    content: '确认要删除选中行所有扫码记录?删除后将不可恢复!',
                    success: ({
                        confirm
                    }) => {
                        if (confirm) {
                            CommonUtils.doRequest2({
                                url: '/WEBSController/set_DelPackUnionBill_Temp_Pack_Json',
                                data: {
                                    HInterID: this.hform.HInterID,
                                    HBillType: this.HBillType,
                                    HBarCode: this.selectedRows[0].HBarCode
                                },
                                resFunction: (res) => {
                                    let {
                                        data,
                                        count,
                                        Message
                                    } = res.data
                                    if (count == 1) {
                                        CommonUtils.playSound(1)
                                        uni.showToast({
                                            icon: 'none',
                                            title: Message
                                        })
                                        this.DisBillEntryList()
                                    } else {
                                        CommonUtils.playSound(0)
                                        uni.showToast({
                                            icon: 'none',
                                            title: Message
                                        })
                                    }
                                }
                            })
                        }
                    }
                })
            },
 
            // 提交单据
            cmdSubmit() {
                let checkRes = this.submitPreCheck()
                if (!checkRes) return
 
                this.EnableSubmit = false
                CommonUtils.doRequest2({
                    url: '/WEBSController/set_SavePackUnionBill_Json',
                    data: {
                        "HInterID": this.hform.HInterID,
                        "HBillType": this.HBillType,
                        "HBillNo": this.hform.HBillNo,
                        "HBarCode_Pack": this.HBarCode_Pack,
                        "HMaker": this.hform.HMaker,
                        "HStockOrgID": this.hform.HStockOrgID
                    },
                    resFunction: (res) => {
                        let {
                            data,
                            count,
                            Message
                        } = res.data
                        if (count == 1) {
                            this.Sc_ICMOBillWorkQtyStatus_Save()
                            uni.showModal({
                                title: '温馨提示',
                                content: Message,
                                confirmText: "新增",
                                cancelText: '关闭',
                                success: ({
                                    confirm,
                                    cancel
                                }) => {
                                    if (confirm) {
                                        uni.redirectTo({
                                            url: `/pages/zhuangxiangdan/form?HSourceBillNo=${encodeURIComponent(this.hform.HSourceBillNo)}`
                                        })
                                    }
                                    if (cancel) {
                                        uni.navigateBack()
                                    }
                                }
                            })
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: Message
                            })
                        }
                    }
                })
            },
            //自动生产产量汇报单
            Sc_ICMOBillWorkQtyStatus_Save() {
                CommonUtils.doRequest2({
                    url: "/WEBSController/Sc_ICMOBillWorkQtyStatus_Tmp_Save",
                    data: {
                        "HInterID": this.hform.HInterID
                    },
                    resFunction: (d) => {
                        let {
                            count,
                            data,
                            Message
                        } = d.data
                        if (count == 1) {
 
                        } else {
                            uni.showModal({
                                title: "温馨提示",
                                showCancel: false,
                                content: Message
                            })
                        }
                    }
                })
            },
 
            // 退出页面
            cmdExit() {
                uni.navigateBack()
            }
        },
 
        // ==================== 生命周期 ====================
        async onReady() {
            // 计算表格高度
            // #ifndef MP-WEIXIN
            let query = uni.createSelectorQuery().in(this)
            query.select("#bottom-btn").boundingClientRect((data) => {
                if (data) this.bottomBtnTop = data.top
            }).exec();
            query.select("#list-table").boundingClientRect((data) => {
                if (data) this.listTableTop = data.top
            }).exec();
            // #endif
        },
 
        onLoad(e) {
            console.log('onLoad params:', e)
            // 初始化参数
            this.BarCodeType = e.BarCodeType || 1
            this.OperationType = e.OperationType || 1
            this.HBarCode_Pack = e.HBarCode_Pack_Temp || ""
            this.hform.HSourceBillNo = e.HSourceBillNo || ""
 
            // 根据操作类型初始化数据
            if (this.OperationType == 1) {
                this.getMaxNo() // 新增模式:获取新单据号
                // 初始化时聚焦到源单单号
                this.HSourcebillNoFocus = true
                if (this.hform.HSourceBillNo != "" && this.hform.HSourceBillNo != undefined) {
                    this.getSourceBarCodeData(this.hform.HSourceBillNo)
                }
            } else if (this.OperationType == 2) {
                this.disableBarCodePack = false
                this.disableBarCode = false
                this.GetMeesageByBarCode_Pack(this.HBarCode_Pack) // 缓存模式:加载已有数据
                this.DisBillEntryList()
                this.tabs = 0
            }
 
            // 默认聚焦到箱条码输入框
            //this.HBarCodePackFocusRefresh()
            uni.$on('BillSelectComplete', (e) => {
                console.log("接收到的源单: ", e.HBillNo)
                // 获取源单状态
                this.getSourceBarCodeControl(e.HBillNo)
                //this.getSourceBarCodeData(e.HBillNo)
                this.$refs.billList.exit()
            })
        },
        onUnload() {
            uni.$off('BillSelectComplete')
        }
    }
</script>
 
<style lang="scss">
    input {
        width: inherit;
        padding: 8rpx 20rpx;
        font-size: 30rpx;
    }
 
    .form {
        display: flex;
        flex-direction: column;
        gap: 20rpx;
 
        .form-base-info {
            display: flex;
            flex-direction: column;
            gap: 10rpx;
            box-sizing: border-box;
            padding: 30rpx;
        }
 
        .bill-info {
            display: flex;
            flex-direction: column;
            gap: 10rpx;
            box-sizing: border-box;
            padding: 16rpx 30rpx;
        }
 
        .form-item {
            display: flex;
            flex-direction: row;
            gap: 10rpx;
 
            .title {
                width: 5rem;
                flex-shrink: 0;
            }
 
            .right {
                flex: 1;
                border-radius: 22rpx;
                border: 1px solid #acacac;
            }
 
            .disabled {
                border: 1px solid #e4e4e4;
                background-color: #e4e4e4;
            }
 
            .right-icon {
                flex-shrink: 0;
                display: flex;
                justify-content: center;
                align-items: center;
            }
 
            .icon-wrapper {
                background-color: #3A78FF;
                border-radius: 100%;
                width: 52rpx;
                height: 52rpx;
                display: flex;
                justify-content: center;
                align-items: center;
                flex-shrink: 0;
 
                .uni-icons {
                    color: #fff !important;
                }
            }
 
            .icon-wrapper[disabled] {
                background-color: rgba(228, 228, 228, 1);
                pointer-events: none;
                touch-action: none;
            }
        }
    }
 
    .tabs {
        width: 100%;
        display: flex;
        border-bottom: 1px solid #ddd;
        margin: 20rpx 0;
 
        view {
            width: 25%;
            font-size: 30rpx;
            color: #555;
            text-align: center;
            padding: 16rpx 0;
        }
 
        .on {
            color: #3a78ff;
            font-weight: bold;
            border-bottom: 3px solid #3a78ff;
        }
    }
 
    .bottom-btn {
        width: 100%;
        box-sizing: border-box;
        // height: 120rpx;
        position: fixed;
        bottom: 0;
        left: 0;
        background-color: #fff;
        box-shadow: 0 2rpx 10rpx 2rpx rgba(0, 0, 0, 0.4);
        padding: 30rpx 40rpx 40rpx 40rpx;
        display: flex;
        flex-direction: row;
        gap: 10rpx;
 
        button {
            border-radius: 50rpx;
            width: 180rpx;
            height: 66rpx;
            line-height: 66rpx;
            font-size: 28rpx;
        }
 
        .btn-a {
            background-color: #3A78FF;
            color: #fff;
        }
 
        .btn-b {
            background-color: #41a863;
            color: #fff;
        }
 
        .btn-c {
            background-color: #acacac;
            color: #fff;
            // position: absolute;
            // right: 120rpx;
        }
 
        .btn-d {
            background-color: #ff8901;
            color: #fff;
        }
    }
 
    .right-icon.disabled {
        background-color: #ccc !important;
        color: #666 !important;
        cursor: not-allowed;
    }
</style>