1
z8018
2025-12-17 68389acdc272b78f1cc4d80180d4650e6254edcf
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
<template>
    <div class="picking-container">
        <!-- 顶部订单信息 -->
        <el-card class="order-info-card" shadow="never">
            <div class="order-header">
                <div class="order-title">
                    <i class="el-icon-document"></i>
                    <span class="order-label">订单号:</span>
                    <span class="order-value">{{ orderNo }}</span>
                </div>
                <div class="order-status" v-if="orderInfo">
                    <el-tag :type="getStatusType(orderInfo.status)" size="medium">
                        {{ orderInfo.statusName || '进行中' }}
                    </el-tag>
                </div>
            </div>
        </el-card>
 
        <!-- 扫码操作区域 -->
        <el-card class="scan-section-card" shadow="never">
            <div class="scan-section">
                <el-alert title="请使用扫码枪扫描,支持回车自动确认" type="info" :closable="false" show-icon class="scan-alert">
                    <template #default>
                        <div>
                            <div>1. 请先扫描托盘码 → 2. 再扫描物料标签码</div>
                            <div style="margin-top: 8px; font-size: 13px; color: #666;">
                                <i class="el-icon-info" style="color: #409EFF;"></i>
                                支持扫托盘码整箱出库:扫描托盘码后可直接进行整箱物料拣选,无需再扫描物料标签码。
                            </div>
                        </div>
                    </template>
                </el-alert>
 
                <el-form :model="scanForm" :rules="scanRules" ref="scanFormRef" class="scan-form">
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item label="托盘码" prop="palletCode">
                                <el-input ref="palletInput" v-model="scanForm.palletCode" placeholder="请扫描托盘码"
                                    size="large" clearable @keyup.enter="handlePalletScan">
                                    <template #prefix>
                                        <i class="el-icon-box"></i>
                                    </template>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="物料条码" prop="materialBarcode">
                                <el-input ref="materialInput" v-model="scanForm.materialBarcode" placeholder="请扫描物料条码"
                                    size="large" clearable :disabled="unpickedData.length <= 0"
                                    @keyup.enter="handleMaterialScan">
                                    <template #prefix>
                                        <i class="el-icon-s-grid"></i>
                                    </template>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item class="button-form-item">
                                <div class="action-buttons">
                                    <el-button type="primary" size="large" @click="handleConfirmPick"
                                        :loading="confirmLoading" :disabled="!canConfirm">
                                        <i class="el-icon-check"></i>
                                        确认拣选
                                    </el-button>
                                    <el-button type="warning" size="large" @click="handleEmptyBox"
                                        :disabled="!scanForm.palletCode">
                                        <i class="el-icon-delete"></i>
                                        取空箱
                                    </el-button>
                                    <el-button type="success" size="large" @click="handleReturnToWarehouse"
                                        :disabled="!scanForm.palletCode">
                                        <i class="el-icon-refresh-left"></i>
                                        回库
                                    </el-button>
                                </div>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
 
                <!-- 分拣统计信息 -->
                <div class="picking-stats" v-if="scanForm.palletCode && unpickedData.length > 0">
                    <el-divider content-position="left">
                        <span style="color: #409EFF; font-size: 14px;">
                            <i class="el-icon-data-analysis"></i> 托盘分拣统计
                        </span>
                    </el-divider>
                    <div class="stats-container">
                        <div class="stat-item">
                            <el-tag type="primary" size="medium" effect="dark">
                                <i class="el-icon-s-order"></i>
                                分拣总数:<b>{{ calculateTotalAssignQuantity() }}</b>
                            </el-tag>
                        </div>
                        <div class="stat-item">
                            <el-tag type="success" size="medium" effect="dark">
                                <i class="el-icon-circle-check"></i>
                                已分拣:<b>{{ calculateTotalSortedQuantity() }}</b>
                            </el-tag>
                        </div>
                        <div class="stat-item">
                            <el-tag type="warning" size="medium" effect="dark">
                                <i class="el-icon-time"></i>
                                未分拣:<b>{{ calculateTotalUnsortedQuantity() }}</b>
                            </el-tag>
                        </div>
                        <div class="stat-item">
                            <el-tag type="success" size="medium" effect="dark">
                                <i class="el-icon-box"></i>
                                是否整出:{{ hasWholeOut() ? '是' : '否' }}
                            </el-tag>
                        </div>
                    </div>
                </div>
            </div>
        </el-card>
 
        <!-- 数据列表区域 -->
        <div class="tables-section">
            <el-row :gutter="20">
                <!-- 未拣选列表 -->
                <el-col :span="12">
                    <el-card class="table-card" shadow="never">
                        <template #header>
                            <div class="card-header">
                                <span class="card-title">
                                    <i class="el-icon-time"></i>
                                    未拣选列表
                                </span>
                                <el-badge :value="unpickedCount" class="badge-item" type="warning">
                                    <el-button size="small" @click="refreshUnpickedTable" icon="el-icon-refresh">
                                        刷新
                                    </el-button>
                                </el-badge>
                            </div>
                        </template>
 
                        <el-table ref="unpickedTable" :data="unpickedData" height="400" stripe highlight-current-row>
                            <el-table-column type="index" label="序号" width="60" align="center" />
                            <el-table-column prop="materielCode" label="物料编码" width="120" show-overflow-tooltip />
                            <el-table-column prop="materielName" label="物料名称" width="80" show-overflow-tooltip />
                            <el-table-column prop="batchNo" label="批次号" width="100" />
                            <el-table-column prop="assignQuantity" label="分拣数量" width="80" align="right">
                                <template #default="scope">
                                    <el-text type="danger">{{ scope.row.assignQuantity }}</el-text>
                                </template>
                            </el-table-column>
                            <el-table-column prop="sortedQuantity" label="已分拣数量" width="120" align="right">
                                <template #default="scope">
                                    <el-text type="danger">{{ scope.row.sortedQuantity }}</el-text>
                                </template>
                            </el-table-column>
                            <el-table-column prop="unit" label="单位" width="60" />
                            <el-table-column prop="locationCode" label="库位" />
                            <!-- <el-table-column label="操作" width="80" align="center">
                                <template #default="scope">
                                    <el-button type="text" size="small" @click="quickPick(scope.row)"
                                        :disabled="!scanForm.palletCode">
                                        拣选
                                    </el-button>
                                </template>
                            </el-table-column> -->
                        </el-table>
 
                        <div class="table-footer">
                            <el-descriptions :column="2" size="small">
                                <el-descriptions-item label="总条数">
                                    <el-text type="info">{{ unpickedTotal }}</el-text>
                                </el-descriptions-item>
                                <el-descriptions-item label="总数量">
                                    <el-text type="warning">{{ unpickedQuantity }}</el-text>
                                </el-descriptions-item>
                            </el-descriptions>
                        </div>
                    </el-card>
                </el-col>
 
                <!-- 已拣选列表 -->
                <el-col :span="12">
                    <el-card class="table-card" shadow="never">
                        <template #header>
                            <div class="card-header">
                                <span class="card-title">
                                    <i class="el-icon-circle-check"></i>
                                    已拣选列表
                                </span>
                                <el-badge :value="pickedCount" class="badge-item" type="success">
                                    <el-button size="small" @click="refreshPickedTable" icon="el-icon-refresh">
                                        刷新
                                    </el-button>
                                </el-badge>
                            </div>
                        </template>
 
                        <el-table ref="pickedTable" :data="pickedData" height="400" stripe>
                            <el-table-column type="index" label="序号" width="60" align="center" />
                            <el-table-column prop="materielCode" label="物料编码" width="120" />
                            <el-table-column prop="materielName" label="物料名称" show-overflow-tooltip />
                            <el-table-column prop="batchNo" label="批次号" width="100" />
                            <el-table-column prop="changeQuantity" label="拣选数量" width="80" align="right">
                                <template #default="scope">
                                    <el-text type="success">{{ 0 - scope.row.changeQuantity }}</el-text>
                                </template>
                            </el-table-column>
                            <el-table-column prop="changeQuantity" label="原库存量" width="80" align="right">
                                <template #default="scope">
                                    <el-text type="success">{{ scope.row.beforeQuantity }}</el-text>
                                </template>
                            </el-table-column>
                            <el-table-column prop="changeQuantity" label="拣选后库存量" width="80" align="right">
                                <template #default="scope">
                                    <el-text type="success">{{ scope.row.afterQuantity }}</el-text>
                                </template>
                            </el-table-column>
                            <el-table-column prop="unit" label="单位" width="60" />
                            <el-table-column prop="palletCode" label="托盘码" width="100" />
                            <el-table-column prop="createDate" label="拣选时间" width="160" />
                            <el-table-column prop="originalBarcode" label="原物料码" width="160" />
                            <el-table-column prop="newBarcode" label="新物料码" width="160" />
                            <!-- <el-table-column label="操作" width="80" align="center">
                                <template #default="scope">
                                    <el-button type="text" size="small" @click="undoPick(scope.row)">
                                        撤销
                                    </el-button>
                                </template>
                            </el-table-column> -->
                        </el-table>
 
                        <div class="table-footer">
                            <el-descriptions :column="2" size="small">
                                <el-descriptions-item label="总条数">
                                    <el-text type="info">{{ pickedTotal }}</el-text>
                                </el-descriptions-item>
                                <el-descriptions-item label="总数量">
                                    <el-text type="success">{{ pickedQuantity }}</el-text>
                                </el-descriptions-item>
                            </el-descriptions>
                        </div>
                    </el-card>
                </el-col>
            </el-row>
 
            <!-- 托盘物料库存信息 -->
            <!-- <div class="pallet-inventory" v-if="scanForm.palletCode && unpickedData.length > 0">
                <el-divider content-position="left">
                    <span style="color: #67C23A; font-size: 14px;">
                        <i class="el-icon-goods"></i> 托盘物料库存信息
                    </span>
                </el-divider>
                <div class="inventory-container">
                    <el-table :data="unpickedData" size="small" :show-header="true" :border="true" stripe
                        highlight-current-row max-height="200" class="inventory-table">
                        <el-table-column type="index" label="序号" width="50" align="center" />
                        <el-table-column prop="materielCode" label="物料编码" width="100" show-overflow-tooltip />
                        <el-table-column prop="materielName" label="物料名称" width="120" show-overflow-tooltip />
                        <el-table-column prop="batchNo" label="批次号" width="90" />
                        <el-table-column label="当前库存" width="80" align="right">
                            <template #default="scope">
                                <el-text type="primary" tag="b">{{ scope.row.currentStock || 0 }}</el-text>
                            </template>
                        </el-table-column>
                        <el-table-column label="分拣数量" width="80" align="right">
                            <template #default="scope">
                                <el-text type="warning">{{ scope.row.assignQuantity }}</el-text>
                            </template>
                        </el-table-column>
                        <el-table-column label="已分拣" width="70" align="right">
                            <template #default="scope">
                                <el-text type="success">{{ scope.row.sortedQuantity || 0 }}</el-text>
                            </template>
                        </el-table-column>
                        <el-table-column label="剩余库存" width="80" align="right">
                            <template #default="scope">
                                <el-text type="info">{{ calculateRemainingStock(scope.row) }}</el-text>
                            </template>
                        </el-table-column>
                        <el-table-column prop="unit" label="单位" width="100" align="center" />
                        <el-table-column prop="locationCode" label="库位" width="150" />
                        <el-table-column label="状态" width="80" align="center">
                            <template #default="scope">
                                <el-tag :type="getStockStatusType(scope.row)" size="mini">
                                    {{ getStockStatusText(scope.row) }}
                                </el-tag>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </div> -->
        </div>
 
        <print-view ref="printView" @parentcall="parentcall"></print-view>
 
        <!-- 确认对话框 -->
        <el-dialog v-model="confirmDialogVisible" title="操作确认" width="400px" :before-close="handleDialogClose">
            <div class="confirm-content">
                <p>{{ confirmMessage }}</p>
            </div>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="confirmDialogVisible = false">取消</el-button>
                    <el-button type="primary" @click="executeConfirm" :loading="executeLoading">
                        确定
                    </el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
 
<script>
 
import printView from "@/extension/outbound/extend/printView.vue"
export default {
    components: { printView },
    name: 'OutPicking',
    data() {
        return {
            orderNo: '',
            orderInfo: null,
            scanForm: {
                palletCode: '',
                materialBarcode: ''
            },
            scanRules: {
                palletCode: [
                    { required: true, message: '请扫描托盘码', trigger: 'blur' }
                ],
                materialBarcode: [
                    { required: true, message: '请扫描物料条码', trigger: 'blur' }
                ]
            },
            unpickedData: [],
            pickedData: [],
            unpickedCount: 0,
            unpickedTotal: 0,
            unpickedQuantity: 0,
            pickedCount: 0,
            pickedTotal: 0,
            pickedQuantity: 0,
            confirmLoading: false,
            confirmDialogVisible: false,
            confirmMessage: '',
            currentAction: null,
            executeLoading: false,
            matMixed: true
        }
    },
    computed: {
        canConfirm() {
            return this.scanForm.palletCode && this.scanForm.materialBarcode
        }
    },
    mounted() {
        this.initPage()
    },
    methods: {
        initPage() {
            // 从路由参数获取订单号
            this.orderNo = this.$route.query.orderNo || ''
            if (!this.orderNo) {
                this.$message.error('订单号不能为空')
                this.$router.back()
                return
            }
            // 自动聚焦到托盘码输入框
            this.$nextTick(() => {
                if (this.$refs.palletInput) {
                    this.$refs.palletInput.focus()
                }
            })
        },
 
        loadPalletData() {
            if (!this.scanForm.palletCode) {
                this.unpickedData = []
                return
            }
 
            try {
                this.loadUnpickedData();
                this.loadPickedData();
 
            } catch (error) {
                console.error('加载托盘数据失败:', error)
                this.unpickedData = []
            }
        },
        loadUnpickedData() {
            try {
                this.http.post(`/api/Outbound/QueryPickingTasks?orderNo=${this.orderNo}&palletCode=${this.scanForm.palletCode}`, {}).then(response => {
                    if (response.status) {
                        if (response.data.outStockLockInfos.length > 0) {
                            this.unpickedData = response.data.outStockLockInfos;
                            this.matMixed = response.data.isMatMixed;
                            this.calculateUnpickedStats()
 
                            // 自动聚焦到物料条码输入框
                            this.$nextTick(() => {
                                if (this.$refs.materialInput) {
                                    this.$refs.materialInput.focus()
                                }
                            })
                        } else {
                            this.$message.warning('该托盘无未拣选任务')
                            this.unpickedData = []
                        }
                    } else {
                        this.$message.error(response.message || '获取托盘数据失败')
                        this.unpickedData = []
                    }
                }
                )
 
            } catch (error) {
                console.error('加载未拣选数据失败:', error)
            }
        },
 
        loadPickedData() {
            try {
                this.http.post(`/api/Outbound/QueryPickedList?orderNo=${this.orderNo}&palletCode=${this.scanForm.palletCode}`, {}).then(response => {
                    if (response.status) {
                        if (response.data.length > 0) {
                            this.pickedData = response.data
                            this.calculatePickedStats()
                        } else {
                            this.pickedData = []
                        }
                    } else {
                        this.$message.error(response.message || '获取托盘数据失败')
                        this.pickedData = []
                    }
                }
                )
 
            } catch (error) {
                console.error('加载已拣选数据失败:', error)
            }
        },
 
        // 计算未拣选
        calculateUnpickedStats() {
            // 未拣选条目数量
            this.unpickedCount = this.unpickedData.length
 
            // 计算未拣选的总数量(分拣数量 - 已分拣数量)
            this.unpickedQuantity = this.unpickedData.reduce((sum, item) => {
                const assignQty = item.assignQuantity || 0
                const sortedQty = item.sortedQuantity || 0
                const remainingQty = Math.max(0, assignQty - sortedQty)
                return sum + remainingQty
            }, 0)
 
            // 总条目数(与条目数量相同,这里保留变量一致性)
            this.unpickedTotal = this.unpickedCount
        },
 
        // 计算已拣选
        calculatePickedStats() {
            // 已拣选条目数量
            this.pickedCount = this.pickedData.length
 
            // 计算已拣选的总数量
            this.pickedQuantity = 0 - this.pickedData.reduce((sum, item) => {
                return (sum + item.changeQuantity)
            }, 0)
 
            // 总条目数(与条目数量相同)
            this.pickedTotal = this.pickedCount
        },
 
        handlePalletScan() {
            if (this.scanForm.palletCode) {
                // this.$message.success(`托盘码: ${this.scanForm.palletCode}`)
                this.loadPalletData()
 
 
            }
        },
 
        handleMaterialScan() {
            if (!this.scanForm.palletCode) {
                this.$message.warning('请先扫描托盘码')
                this.$refs.palletInput.focus()
                return
            }
 
            if (!this.scanForm.materialBarcode) {
                this.$message.warning('请扫描物料条码')
                return
            }
 
            // 自动执行确认拣选
            this.handleConfirmPick()
        },
 
        handleConfirmPick() {
            if (!this.scanForm.palletCode || !this.scanForm.materialBarcode) {
                this.$message.warning('请先扫描托盘码和物料条码')
                return
            }
 
            this.confirmLoading = true
 
            try {
                this.http.post('/api/Outbound/CompleteOutboundWithBarcode', {
                    orderNo: this.orderNo,
                    palletCode: this.scanForm.palletCode,
                    barcode: this.scanForm.materialBarcode,
                    operator: this.getUserName()
                }).then(response => {
                    if (response.status) {
                        if (response.data.scannedDetail.isUnpacked && response.data.scannedDetail.materialCodes.length > 0) {
                            this.$refs.printView.open(response.data.scannedDetail.materialCodes);
                        }
                        this.$message.success('拣选确认成功')
                        this.resetMaterialBarcode()
                        // this.loadUnpickedData()
                        // this.loadPickedData()
                        this.loadPalletData()
                    } else {
                        this.$message.error(response.message || '拣选确认失败')
                    }
                })
            } catch (error) {
                console.error('拣选确认失败:', error)
                this.$message.error('拣选确认失败')
            } finally {
                this.confirmLoading = false
            }
        },
 
        handleEmptyBox() {
            if (!this.scanForm.palletCode) {
                this.$message.warning('请先扫描托盘码')
                return
            }
 
            this.confirmMessage = `确定要取空托盘 ${this.scanForm.palletCode} 吗?`
            this.currentAction = 'emptyBox'
            this.confirmDialogVisible = true
        },
 
        handleReturnToWarehouse() {
            if (!this.scanForm.palletCode) {
                this.$message.warning('请先扫描托盘码')
                return
            }
 
            this.confirmMessage = `确定要将托盘 ${this.scanForm.palletCode} 回库吗?`
            this.currentAction = 'returnToWarehouse'
            this.confirmDialogVisible = true
        },
 
        executeConfirm() {
            this.executeLoading = true
 
            try {
                let apiUrl = ''
                let params = {
                    orderNo: this.orderNo,
                    palletCode: this.scanForm.palletCode
                }
 
                if (this.currentAction === 'emptyBox') {
                    apiUrl = '/api/Outbound/EmptyBox'
                } else if (this.currentAction === 'returnToWarehouse') {
                    apiUrl = '/api/Outbound/ReturnToWarehouse'
                }
 
                this.http.post(apiUrl, params).then(response => {
 
                    if (response.status) {
                        this.$message.success('操作成功')
                        this.confirmDialogVisible = false
                        this.resetForm()
                        // this.loadUnpickedData()
                        // this.loadPickedData()
                    } else {
                        this.$message.error(response.message || '操作失败')
                    }
                })
            } catch (error) {
                console.error('操作失败:', error)
                this.$message.error('操作失败')
            } finally {
                this.executeLoading = false
            }
        },
 
        handleDialogClose() {
            if (!this.executeLoading) {
                this.confirmDialogVisible = false
            }
        },
 
        quickPick(row) {
            this.scanForm.materialBarcode = row.materielCode
            this.handleConfirmPick()
        },
 
        undoPick(row) {
            try {
                this.$confirm('确定要撤销这条拣选记录吗?', '提示', {
                    type: 'warning'
                })
 
                const response = this.http.post('/api/Outbound/UndoPicking', {
                    id: row.id
                }).then(response => {
                    if (response.status) {
                        this.$message.success('撤销成功')
                        this.loadUnpickedData()
                        this.loadPickedData()
                    } else {
                        this.$message.error(response.message || '撤销失败')
                    }
                })
            } catch (error) {
                if (error !== 'cancel') {
                    console.error('撤销失败:', error)
                    this.$message.error('撤销失败')
                }
            }
        },
 
        // handleUnpickedRowClick(row) {
        //     // 点击未拣选行时自动填充物料条码
        //     this.scanForm.materialBarcode = row.materielCode
        // },
 
        refreshUnpickedTable() {
            if (this.scanForm.palletCode) {
                this.loadPalletData()
            }
        },
 
        refreshPickedTable() {
            this.loadPickedData()
        },
 
        resetMaterialBarcode() {
            this.scanForm.materialBarcode = ''
            this.$nextTick(() => {
                if (this.$refs.materialInput) {
                    this.$refs.materialInput.focus()
                }
            })
        },
 
        resetForm() {
            this.scanForm.palletCode = ''
            this.scanForm.materialBarcode = ''
            this.unpickedData = []
            this.$nextTick(() => {
                if (this.$refs.palletInput) {
                    this.$refs.palletInput.focus()
                }
            })
        },
 
        getUserName() {
            // 尝试从 Vuex store 获取用户名
            if (this.$store && this.$store.state && this.$store.state.userInfo) {
                return this.$store.state.userInfo.userName || this.$store.state.userInfo.username || '未登录用户'
            }
 
            // 尝试从 localStorage 获取
            try {
                const userInfo = localStorage.getItem('user')
                if (userInfo) {
                    const user = JSON.parse(userInfo)
                    return user.userName || user.username || '未登录用户'
                }
            } catch (error) {
                console.error('获取用户信息失败:', error)
            }
 
            return '未登录用户'
        },
 
        // 计算分拣总数
        calculateTotalAssignQuantity() {
            return this.unpickedData.reduce((sum, item) => {
                return sum + (item.assignQuantity || 0)
            }, 0)
        },
 
        // 计算已分拣总数
        calculateTotalSortedQuantity() {
            return this.unpickedData.reduce((sum, item) => {
                return sum + (item.sortedQuantity || 0)
            }, 0)
        },
 
        // 计算未分拣总数
        calculateTotalUnsortedQuantity() {
            return this.unpickedData.reduce((sum, item) => {
                const assignQty = item.assignQuantity || 0
                const sortedQty = item.sortedQuantity || 0
                return sum + Math.max(0, assignQty - sortedQty)
            }, 0)
        },
 
        // 检查是否包含整出
        hasWholeOut() {
            return this.unpickedData.some(item => item.assignQuantity === item.originalQuantity) && this.matMixed;
        },
 
        // 计算剩余库存
        calculateRemainingStock(row) {
            const currentStock = row.currentStock || 0
            const assignQty = row.assignQuantity || 0
            return Math.max(0, currentStock - assignQty)
        },
 
        // 获取库存状态类型
        getStockStatusType(row) {
            const currentStock = row.currentStock || 0
            const assignQty = row.assignQuantity || 0
            const sortedQty = row.sortedQuantity || 0
 
            if (sortedQty >= assignQty) {
                return 'success' // 已完成
            } else if (currentStock < assignQty) {
                return 'danger' // 库存不足
            } else {
                return 'warning' // 进行中
            }
        },
 
        // 获取库存状态文本
        getStockStatusText(row) {
            const currentStock = row.currentStock || 0
            const assignQty = row.assignQuantity || 0
            const sortedQty = row.sortedQuantity || 0
 
            if (sortedQty >= assignQty) {
                return '已完成'
            } else if (currentStock < assignQty) {
                return '库存不足'
            } else {
                return '分拣中'
            }
        },
 
        getStatusType(status) {
            const statusMap = {
                0: 'info',    // 待处理
                10: 'warning', // 进行中
                20: 'primary', // 拣选中
                30: 'success', // 已完成
                40: 'danger'   // 异常
            }
            return statusMap[status] || 'info'
        }
    }
}
</script>
 
<style scoped>
.picking-container {
    padding: 20px;
    background-color: #f5f5f5;
    min-height: 100vh;
}
 
/* 订单信息卡片 */
.order-info-card {
    margin-bottom: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}
 
.order-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
 
.order-title {
    display: flex;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
}
 
.order-title i {
    margin-right: 10px;
    font-size: 24px;
}
 
.order-label {
    margin-left: 10px;
    opacity: 0.9;
}
 
.order-value {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 1px;
}
 
/* 扫码区域 */
.scan-section-card {
    margin-bottom: 20px;
}
 
.scan-section {
    padding: 10px 0;
}
 
.scan-alert {
    margin-bottom: 20px;
}
 
.scan-form {
    margin-top: 20px;
}
 
.button-form-item {
    margin-bottom: 0;
}
 
.button-form-item .el-form-item__content {
    line-height: normal;
}
 
.action-buttons {
    display: flex;
    gap: 8px;
    width: 100%;
    height: 40px;
}
 
.action-buttons .el-button {
    flex: 1;
    height: 40px;
    font-weight: bold;
    border-radius: 6px;
    margin: 0;
}
 
/* 表格区域 */
.tables-section {
    margin-top: 20px;
}
 
.table-card {
    height: 600px;
    display: flex;
    flex-direction: column;
}
 
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
 
.card-title {
    display: flex;
    align-items: center;
    font-weight: bold;
    font-size: 16px;
}
 
.card-title i {
    margin-right: 8px;
    color: #409EFF;
}
 
.badge-item {
    margin-left: 10px;
}
 
.table-footer {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #ebeef5;
}
 
/* 表格行样式 */
.el-table tbody tr:hover>td {
    background-color: #f0f9ff !important;
}
 
.el-table tbody tr.current-row>td {
    background-color: #e1f3ff !important;
}
 
/* 对话框样式 */
.confirm-content {
    padding: 20px 0;
    text-align: center;
}
 
.confirm-content p {
    font-size: 16px;
    color: #606266;
}
 
.dialog-footer {
    text-align: center;
}
 
/* 响应式设计 */
@media (max-width: 1200px) {
    .action-buttons .el-button {
        font-size: 14px;
    }
}
 
/* Element UI 组件样式覆盖 */
::v-deep .el-card__header {
    padding: 18px 20px;
    border-bottom: 1px solid #ebeef5;
}
 
::v-deep .el-input__inner {
    border-radius: 6px;
}
 
::v-deep .el-button--primary {
    background: linear-gradient(135deg, #409EFF 0%, #3a8ee6 100%);
    border: none;
}
 
::v-deep .el-button--warning {
    background: linear-gradient(135deg, #E6A23C 0%, #d9971a 100%);
    border: none;
}
 
::v-deep .el-button--success {
    background: linear-gradient(135deg, #67C23A 0%, #5daf34 100%);
    border: none;
}
 
/* 图标样式 */
.el-icon-document,
.el-icon-box,
.el-icon-s-grid,
.el-icon-check,
.el-icon-delete,
.el-icon-refresh-left,
.el-icon-time,
.el-icon-circle-check {
    font-size: 18px;
}
 
/* 描述列表样式 */
::v-deep .el-descriptions__label {
    font-weight: bold;
    color: #909399;
}
 
::v-deep .el-descriptions__content {
    color: #606266;
}
 
/* 表格增强样式 */
::v-deep .el-table th {
    background-color: #fafafa;
    font-weight: 600;
    color: #303133;
}
 
::v-deep .el-table .el-text {
    font-weight: 500;
}
 
/* 标签样式增强 */
::v-deep .el-tag--small {
    font-weight: 500;
}
 
/* 提示信息样式增强 */
.scan-alert ::v-deep .el-alert__content {
    width: 100%;
}
 
.scan-alert ::v-deep .el-alert__description {
    margin-top: 8px;
}
 
/* 分拣统计信息样式 */
.picking-stats {
    margin-top: 20px;
    padding: 0 10px;
}
 
.stats-container {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}
 
.stat-item {
    display: inline-flex;
    align-items: center;
}
 
.stat-item .el-tag {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 20px;
}
 
.stat-item .el-tag i {
    margin-right: 6px;
    font-size: 14px;
}
 
.stat-item b {
    margin-left: 4px;
    font-size: 14px;
}
 
/* 分割线样式 */
::v-deep .el-divider__text {
    background-color: #f5f5f5;
    padding: 0 20px;
}
 
/* 托盘库存信息样式 */
.pallet-inventory {
    margin-top: 20px;
    padding: 0 10px;
}
 
.inventory-container {
    margin-top: 10px;
}
 
.inventory-table {
    width: 100%;
}
 
.inventory-table ::v-deep .el-table__header {
    background-color: #f0f9ff;
}
 
.inventory-table ::v-deep .el-table__header th {
    background-color: #e1f3ff;
    color: #1f2937;
    font-weight: 600;
    font-size: 12px;
    padding: 8px 0;
}
 
.inventory-table ::v-deep .el-table__body td {
    padding: 6px 0;
    font-size: 12px;
}
 
.inventory-table ::v-deep .el-table__row {
    cursor: pointer;
}
 
.inventory-table ::v-deep .el-table__row:hover {
    background-color: #f0f9ff;
}
 
/* 库存表格中的标签样式 */
.inventory-table ::v-deep .el-tag--mini {
    font-size: 11px;
    padding: 1px 6px;
    height: 18px;
    line-height: 16px;
}
</style>