From 68e75f8e483accd14d34ea64e228678c58b498bc Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期四, 22 一月 2026 21:46:38 +0800
Subject: [PATCH] 虚拟出入库合单优化

---
 项目代码/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue |  534 ++++++++++++++++++++++++++++++----------------------------
 1 files changed, 278 insertions(+), 256 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue"
index c7201a6..85cfe01 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue"
@@ -175,7 +175,7 @@
 import http from '@/api/http.js';
 import VolBox from '@/components/basic/VolBox.vue';
 
-// 鏂板锛氶槻鎶栧嚱鏁�
+// 闃叉姈鍑芥暟淇濇寔涓嶅彉
 function debounce(func, wait) {
   let timeout;
   return function () {
@@ -206,30 +206,25 @@
 
       unpalletBarcodes: [],
       unpalletBarcodesLoading: false,
-      unpalletMaterials: [], // 鏈粍鐩樿缁嗘暟鎹垪琛�
+      unpalletMaterials: [],
 
-      // 鎵爜鏋浉鍏冲彉閲�
       scanCode: '',
       lastKeyTime: null,
       isManualInput: false,
       isScanning: false,
       scanTimer: null,
       manualInputTimer: null,
-      scanTarget: 'tray', // 褰撳墠鎵爜鐩爣: tray 鎴� material
-      isSubmitting: false, // 鏂板锛氭彁浜ら攣瀹氾紝闃叉閲嶅璇锋眰
-      // 淇锛氭敼涓烘寜鎵樼洏瀛樺偍宸茬粍鐩樻潯鐮侊紝閬垮厤鐘舵�佹贩娣�
-      palletGroupedBarcodes: {}, // 鏍煎紡锛歿 [trayBarcode]: [barcode1, barcode2, ...] }
+      scanTarget: 'tray',
+      isSubmitting: false,
+      palletGroupedBarcodes: {},
 
-      // 搴撳瓨缁熻鐩稿叧鍙橀噺
       totalStockSum: 0,
       totalStockCount: 0,
       uniqueUnit: '',
       sumLoading: false,
       sumError: '',
-      // 浠撳簱鐩稿叧鍙橀噺
       warehouseTypes: [],
       warehouseLoading: false,
-      // 浠撳簱鍖哄煙鐩稿叧鍙橀噺
       locationTypes: [],
       locationLoading: false,
       form: {
@@ -261,26 +256,25 @@
   },
 
   computed: {
-    // 褰撳墠閫夋嫨鐨勪粨搴撳悕绉�
     currentWarehouseName() {
       const warehouse = this.warehouseTypes.find(item => item.warehouseType === this.form.warehouseType);
       return warehouse ? warehouse.warehouseTypeDesc : '';
     },
-    // 褰撳墠閫夋嫨鐨勪粨搴撳尯鍩熸弿杩�
+    
     currentLocationDesc() {
       const location = this.locationTypes.find(item => item.locationType === this.form.locationType)
       return location ? location.locationTypeDesc : ''
     },
-    // 鏂板锛氶槻鎶栧悗鐨勭墿鏂欐彁浜ゆ柟娉�
+    
     debounceHandleBarcodeSubmit() {
       return debounce(this.handleBarcodeSubmit, 500);
     }
   },
+  
   watch: {
     visible(newVal, oldVal) {
       this.palletVisible = newVal;
 
-      // 褰撲粠 false 鍙樹负 true 鏃讹紝琛ㄧず寮规鎵撳紑
       if (newVal === true && oldVal === false) {
         console.log('寮规鎵撳紑锛岄噸缃暟鎹�');
         this.resetData();
@@ -291,15 +285,16 @@
         });
       }
 
-      // 褰撲粠 true 鍙樹负 false 鏃讹紝琛ㄧず寮规鍏抽棴
       if (newVal === false && oldVal === true) {
         console.log('寮规鍏抽棴锛岄噸缃暟鎹�');
         this.resetData();
       }
     },
+    
     palletVisible(newVal) {
       this.$emit('update:visible', newVal);
     },
+    
     docNo(newVal) {
       if (newVal) {
         this.palletForm = { palletCode: '', barcode: '' };
@@ -309,13 +304,16 @@
       }
     }
   },
+  
   mounted() {
     document.addEventListener('keypress', this.handleKeyPress);
   },
+  
   beforeDestroy() {
     document.removeEventListener('keypress', this.handleKeyPress);
     this.clearAllTimers();
   },
+  
   methods: {
     open() {
       this.show = true;
@@ -325,6 +323,7 @@
       this.initwarehouseTypes();
       this.fetchUnpalletMaterialDetails();
     },
+    
     validateLocationType(rule, value, callback) {
       if (!this.form.warehouseType) {
         callback(new Error('璇峰厛閫夋嫨浠撳簱'));
@@ -335,74 +334,104 @@
       }
     },
 
-    // 鏍规嵁鏉$爜鍒楄〃鑾峰彇璇︾粏鏁版嵁
-    async fetchUnpalletMaterialDetails() {
-      try {
-        const response = await http.post('/api/InboundOrder/UnPalletGroupBarcode?orderNo=' + this.orderNo, {});
-        if (response.status && Array.isArray(response.data)) {
-          this.unpalletMaterials = response.data;
-          this.unpalletBarcodes = response.data.map(item => item.barcode || '');
-          this.totalStockCount = response.data.length;
-        } else {
-          this.unpalletMaterials = [];
-        }
-      } catch (err) {
-        this.unpalletMaterials = this.unpalletBarcodes.map(barcode => ({
-          barcode: barcode,
-          materielCode: '-',
-          batchNo: '-',
-          stockQuantity: '-',
-          unit: '-',
-          supplyCode: '-',
-          warehouseType: '-'
-        }));
-      }
+    // 鑾峰彇鏈粍鐩樼墿鏂欒鎯�
+    fetchUnpalletMaterialDetails() {
+      this.unpalletBarcodesLoading = true;
+      
+      http.post('/api/InboundOrder/UnPalletGroupBarcode?orderNo=' + this.orderNo, {})
+        .then(response => {
+          if (response.status && Array.isArray(response.data)) {
+            this.unpalletMaterials = response.data;
+            this.unpalletBarcodes = response.data.map(item => item.barcode || '');
+            this.totalStockCount = response.data.length;
+          } else {
+            this.unpalletMaterials = [];
+          }
+        })
+        .catch(err => {
+          console.error('鑾峰彇鏈粍鐩樼墿鏂欏け璐�:', err);
+          this.unpalletMaterials = this.unpalletBarcodes.map(barcode => ({
+            barcode: barcode,
+            materielCode: '-',
+            batchNo: '-',
+            stockQuantity: '-',
+            unit: '-',
+            supplyCode: '-',
+            warehouseType: '-'
+          }));
+        })
+        .finally(() => {
+          this.unpalletBarcodesLoading = false;
+        });
     },
-    async initLocationTypes() {
-      try {
-        // 淇锛歨ttp 鏀逛负 this.$http锛堝師浠g爜閿欒锛�
-        const { data } = await this.http.post("api/LocationInfo/GetLocationTypes")
-        this.locationTypes = data
-      } catch (e) {
-        this.$message.error('鑾峰彇鍖哄煙绫诲瀷澶辫触')
-      }
+    
+    // 鍒濆鍖栦粨搴撳尯鍩熺被鍨�
+    initLocationTypes() {
+      this.locationLoading = true;
+      
+      this.http.post("api/LocationInfo/GetLocationTypes")
+        .then(({ data }) => {
+          this.locationTypes = data;
+        })
+        .catch(e => {
+          console.error('鑾峰彇鍖哄煙绫诲瀷澶辫触:', e);
+          this.$message.error('鑾峰彇鍖哄煙绫诲瀷澶辫触');
+        })
+        .finally(() => {
+          this.locationLoading = false;
+        });
     },
-    async initwarehouseTypes() {
-      try {
-        // 淇锛歨ttp 鏀逛负 this.$http锛堝師浠g爜閿欒锛�
-        const { data } = await this.http.post("api/Warehouse/GetwarehouseTypes")
-        this.warehouseTypes = data
-      } catch (e) {
-        this.$message.error('鑾峰彇鍖哄煙绫诲瀷澶辫触')
-      }
+    
+    // 鍒濆鍖栦粨搴撶被鍨�
+    initwarehouseTypes() {
+      this.warehouseLoading = true;
+      
+      this.http.post("api/Warehouse/GetwarehouseTypes")
+        .then(({ data }) => {
+          this.warehouseTypes = data;
+        })
+        .catch(e => {
+          console.error('鑾峰彇浠撳簱绫诲瀷澶辫触:', e);
+          this.$message.error('鑾峰彇浠撳簱绫诲瀷澶辫触');
+        })
+        .finally(() => {
+          this.warehouseLoading = false;
+        });
     },
 
-    async fetchStockStatistics(orderNo) {
-      // 鍗曟嵁鍙蜂负绌烘椂涓嶆煡璇�
+    // 鑾峰彇搴撳瓨缁熻
+    fetchStockStatistics(orderNo) {
       if (!orderNo) {
         this.sumError = '鍗曟嵁鍙蜂负绌猴紝鏃犳硶缁熻';
-        return;
+        return Promise.resolve(null);
       }
 
       this.sumLoading = true;
       this.sumError = '';
-      try {
-        const response = await http.post('/api/InboundOrder/UnPalletQuantity?orderNo=' + orderNo, {});
-        if (response.data) {
-          this.totalStockSum = response.data.stockSumQuantity || 0;
-          this.totalStockCount = response.data.stockCount || 0;
-          this.uniqueUnit = response.data.uniqueUnit || '';
-        }
-      } catch (err) {
-        this.sumError = '缁熻鍔犺浇澶辫触';
-        this.totalStockSum = 0;
-        this.totalStockCount = 0;
-      } finally {
-        this.sumLoading = false;
-      }
+      
+      return http.post('/api/InboundOrder/UnPalletQuantity?orderNo=' + orderNo, {})
+        .then(response => {
+          if (response.data) {
+            this.totalStockSum = response.data.stockSumQuantity || 0;
+            this.totalStockCount = response.data.stockCount || 0;
+            this.uniqueUnit = response.data.uniqueUnit || '';
+          }
+          return response.data;
+        })
+        .catch(err => {
+          console.error('缁熻鍔犺浇澶辫触:', err);
+          this.sumError = '缁熻鍔犺浇澶辫触';
+          this.totalStockSum = 0;
+          this.totalStockCount = 0;
+          throw err;
+        })
+        .finally(() => {
+          this.sumLoading = false;
+        });
     },
 
-    async validateForm() {
+    // 琛ㄥ崟楠岃瘉
+    validateForm() {
       return new Promise((resolve) => {
         if (!this.$refs.locationForm) {
           this.error = '琛ㄥ崟鏈垵濮嬪寲';
@@ -416,10 +445,9 @@
             this.error = '';
             resolve(true);
           } else {
-            // 淇锛歠rom 鏀逛负 form锛堝師浠g爜鎷煎啓閿欒锛�
             if (!this.form.warehouseType) {
               this.error = '璇峰厛閫夋嫨浠撳簱';
-            } else if (this.form.locationType === null || this.form.locationType === undefined || this.form.locationType === '') {
+            } else if (!this.form.locationType) {
               this.error = '璇峰厛閫夋嫨浠撳簱鍖哄煙';
             } else {
               this.error = '璇锋鏌ヨ〃鍗曞~鍐欐槸鍚︽纭�';
@@ -429,7 +457,7 @@
         });
       });
     },
-    // 鑱氱劍鍒版墭鐩樿緭鍏ユ
+    
     focusTrayInput() {
       if (this.$refs.trayInput && this.$refs.trayInput.$el) {
         const inputEl = this.$refs.trayInput.$el.querySelector('input');
@@ -442,7 +470,6 @@
       }
     },
 
-    // 鑱氱劍鍒扮墿鏂欒緭鍏ユ
     focusBarcodeInput() {
       if (this.$refs.barcodeInput && this.$refs.barcodeInput.$el) {
         const inputEl = this.$refs.barcodeInput.$el.querySelector('input');
@@ -454,11 +481,10 @@
         }
       }
     },
-    // 閲嶇疆鎵�鏈夋暟鎹�
+    
     resetData() {
-      // 淇锛氭竻绌烘寜鎵樼洏瀛樺偍鐨勫凡缁勭洏鏉$爜
       this.palletGroupedBarcodes = {};
-      this.isSubmitting = false; // 閲嶇疆鎻愪氦閿�
+      this.isSubmitting = false;
       this.trayBarcode = '';
       this.barcode = '';
       this.materials = [];
@@ -466,12 +492,12 @@
       this.unpalletMaterials = [];
       this.loading = false;
       this.error = '';
-      this.scanCode = ''; // 娓呯┖鎵爜缂撳瓨
+      this.scanCode = '';
       this.lastKeyTime = null;
       this.isManualInput = false;
       this.isScanning = false;
       this.currentFocus = 'warehouse';
-      this.scanTarget = 'tray'; // 閲嶇疆鎵爜鐩爣
+      this.scanTarget = 'tray';
       this.clearAllTimers();
       this.totalStockSum = 0;
       this.totalStockCount = 0;
@@ -480,10 +506,10 @@
       this.form = {
         warehouseType: null,
         locationType: null
-      }
+      };
       this.warehouseTypes = [];
       this.locationTypes = [];
-      // 娓呴櫎琛ㄥ崟楠岃瘉鐘舵��
+      
       this.$nextTick(() => {
         if (this.$refs.locationForm) {
           this.$refs.locationForm.clearValidate();
@@ -491,7 +517,6 @@
       });
     },
 
-    // 娓呴櫎鎵�鏈夎鏃跺櫒
     clearAllTimers() {
       if (this.manualInputTimer) {
         clearTimeout(this.manualInputTimer);
@@ -502,81 +527,75 @@
         this.scanTimer = null;
       }
     },
+    
     handleDialogClose() {
       this.show = false;
       this.resetData();
     },
 
     // 纭鎸夐挳
-    async handleConfirm() {
-      if (!await this.validateForm()) return;
+    handleConfirm() {
+      this.validateForm()
+        .then(valid => {
+          if (!valid) return;
+          
+          if (this.materials.length === 0) {
+            this.$message.warning('璇疯嚦灏戞坊鍔犱竴涓墿鏂�');
+            return;
+          }
 
-      if (this.materials.length === 0) {
-        this.$message.warning('璇疯嚦灏戞坊鍔犱竴涓墿鏂�');
-        return;
-      }
+          if (!this.trayBarcode) {
+            this.$message.warning('璇疯緭鍏ユ墭鐩樻潯鐮�');
+            return;
+          }
 
-      if (!this.trayBarcode) {
-        this.$message.warning('璇疯緭鍏ユ墭鐩樻潯鐮�');
-        return;
-      }
+          const result = {
+            warehouseType: this.form.warehouseType,
+            warehouseName: this.currentWarehouseName,
+            locationType: this.form.locationType,
+            locationDesc: this.currentLocationDesc,
+            trayBarcode: this.trayBarcode,
+            materials: this.materials,
+            docNo: this.docNo
+          };
 
-      const result = {
-        warehouseType: this.form.warehouseType,
-        warehouseName: this.currentWarehouseName,
-        locationType: this.form.locationType,
-        locationDesc: this.currentLocationDesc,
-        trayBarcode: this.trayBarcode,
-        materials: this.materials,
-        docNo: this.docNo
-      };
-
-      // 瑙﹀彂鐖剁粍浠剁殑 back-success 浜嬩欢
-      this.$emit('back-success', result);
-      this.palletVisible = false;
+          this.$emit('back-success', result);
+          this.palletVisible = false;
+        });
     },
-    // 澶勭悊鎵樼洏杈撳叆
+    
     handleTrayInput() {
-      // 鏍囪涓烘墜鍔ㄨ緭鍏ユā寮�
       this.isManualInput = true;
       this.isScanning = false;
 
-      // 娓呴櫎涔嬪墠鐨勮鏃跺櫒
       if (this.manualInputTimer) {
         clearTimeout(this.manualInputTimer);
       }
 
-      // 璁剧疆璁℃椂鍣紝濡傛灉涓�娈垫椂闂村唴娌℃湁杈撳叆锛屽垯閲嶇疆涓烘壂鐮佹ā寮�
       this.manualInputTimer = setTimeout(() => {
         this.isManualInput = false;
       }, 1000);
     },
 
-    // 澶勭悊鐗╂枡杈撳叆
     handleBarcodeInput() {
-      // 鏍囪涓烘墜鍔ㄨ緭鍏ユā寮�
       this.isManualInput = true;
       this.isScanning = false;
 
-      // 娓呴櫎涔嬪墠鐨勮鏃跺櫒
       if (this.manualInputTimer) {
         clearTimeout(this.manualInputTimer);
       }
 
-      // 璁剧疆璁℃椂鍣紝濡傛灉涓�娈垫椂闂村唴娌℃湁杈撳叆锛屽垯閲嶇疆涓烘壂鐮佹ā寮�
       this.manualInputTimer = setTimeout(() => {
         this.isManualInput = false;
       }, 1000);
     },
 
     // 澶勭悊鎵樼洏鏉$爜鎻愪氦
-    async handleTraySubmit() {
-      // 淇锛氬垏鎹㈡墭鐩樻椂娓呯┖鐗╂枡鐩稿叧鐘舵�侊紝閬垮厤鏃ф暟鎹畫鐣�
+    handleTraySubmit() {
       this.barcode = '';
       this.materials = [];
       this.error = '';
 
-      // 鍏堢洿鎺ユ鏌ocationType锛岄伩鍏嶈〃鍗曢獙璇佺殑寮傛闂
       if (!this.form.warehouseType) {
         this.error = '璇峰厛閫夋嫨浠撳簱';
         return;
@@ -586,31 +605,30 @@
         return;
       }
 
-      // 鐒跺悗鍐嶈繘琛屽畬鏁寸殑琛ㄥ崟楠岃瘉
-      if (!await this.validateForm()) return;
+      this.validateForm()
+        .then(valid => {
+          if (!valid) return;
+          
+          const currentTrayBarcode = this.trayBarcode.trim();
 
-      const currentTrayBarcode = this.trayBarcode.trim();
+          if (!currentTrayBarcode) {
+            this.error = '璇疯緭鍏ユ垨鎵弿鎵樼洏鏉$爜';
+            return;
+          }
 
-      if (!currentTrayBarcode) {
-        this.error = '璇疯緭鍏ユ垨鎵弿鎵樼洏鏉$爜';
-        return;
-      }
+          this.error = '';
 
-      this.error = '';
+          if (!this.trayBarcodeReg.test(currentTrayBarcode)) {
+            this.$message("鎵樼洏鍙锋牸寮忛敊璇�");
+            this.focusTrayInput();
+            return;
+          }
 
-      if (!this.trayBarcodeReg.test(currentTrayBarcode)) {
-        this.$message("鎵樼洏鍙锋牸寮忛敊璇�");
-        this.focusTrayInput();
-        return;
-      }
-
-      // 璁剧疆鎵樼洏鏉$爜鍚庯紝鑷姩鑱氱劍鍒扮墿鏂欒緭鍏ユ
-      this.focusBarcodeInput();
-
-      this.$message.success(`鎵樼洏鏉$爜宸茶缃�: ${currentTrayBarcode}`);
+          this.focusBarcodeInput();
+          this.$message.success(`鎵樼洏鏉$爜宸茶缃�: ${currentTrayBarcode}`);
+        });
     },
 
-    // 娓呴櫎鎵樼洏
     clearTray() {
       this.trayBarcode = '';
       this.materials = [];
@@ -622,12 +640,10 @@
       });
     },
 
-    // 娓呯┖鎵樼洏杈撳叆
     handleTrayClear() {
       this.error = '';
     },
 
-    // 娓呯┖杈撳叆
     handleClear() {
       this.error = '';
       this.scanCode = '';
@@ -636,15 +652,15 @@
     },
 
     // 澶勭悊鐗╂枡鏉$爜鎻愪氦
-    async handleBarcodeSubmit() {
+    handleBarcodeSubmit() {
       if (this.isSubmitting) {
         this.$message.warning('姝e湪澶勭悊涓紝璇风◢鍊�');
         return;
       }
 
-      // 鏂板锛氭牎楠屽綋鍓嶆潯鐮佹槸鍚﹀凡琚綋鍓嶆墭鐩樼粍鐩�
       const currentBarcode = this.barcode.trim();
       const currentTrayGrouped = this.palletGroupedBarcodes[this.trayBarcode] || [];
+      
       if (currentTrayGrouped.includes(currentBarcode)) {
         this.error = `鏉$爜 ${currentBarcode} 宸茶褰撳墠鎵樼洏缁勭洏锛岃鍕块噸澶嶆搷浣渀;
         this.barcode = '';
@@ -652,121 +668,135 @@
         return;
       }
 
-      if (!await this.validateForm()) return;
+      this.isSubmitting = true;
+      
+      this.validateForm()
+        .then(valid => {
+          if (!valid) {
+            this.isSubmitting = false;
+            return;
+          }
+          
+          if (!this.trayBarcode) {
+            this.error = '璇峰厛杈撳叆鎵樼洏鏉$爜';
+            this.focusTrayInput();
+            this.isSubmitting = false;
+            return;
+          }
 
-      if (!this.trayBarcode) {
-        this.error = '璇峰厛杈撳叆鎵樼洏鏉$爜';
-        this.focusTrayInput();
-        return;
-      }
+          if (!currentBarcode) {
+            this.error = '璇疯緭鍏ユ垨鎵弿鐗╂枡鏉$爜';
+            this.isSubmitting = false;
+            return;
+          }
 
-      if (!currentBarcode) {
-        this.error = '璇疯緭鍏ユ垨鎵弿鐗╂枡鏉$爜';
-        return;
-      }
-
-      this.focusBarcodeInput();
-      this.error = '';
-      this.loading = true;
-      this.isSubmitting = true; // 寮�鍚彁浜ら攣
-
-      try {
-        // 鏂板锛氳皟璇曟棩蹇楋紝鎵撳嵃璇锋眰鍙傛暟
-        console.log('缁勭洏璇锋眰鍙傛暟:', {
-          palletCode: this.trayBarcode,
-          barcode: currentBarcode,
-          locationTypeDesc: this.currentLocationDesc,
-          locationType: this.form.locationType,
-          warehouseType: this.form.warehouseType
-        });
-
-        // 璋冪敤API鏌ヨ鐗╂枡淇℃伅
-        const materialData = await this.fetchMaterialData(currentBarcode);
-        if (!materialData || materialData.length === 0) {
-          return;
-        }
-
-        this.materials = [];
-        const newBarcodes = []; // 涓存椂瀛樺偍鏈鏂板鐨勬潯鐮�
-        materialData.forEach(item => {
-          this.materials.push({
-            ...item,
-            trayCode: this.trayBarcode,
-            locationType: this.form.locationType,
-            locationDesc: this.currentLocationDesc,
-            scanTime: this.formatTime(new Date())
-          });
-          newBarcodes.push(item.barcode); // 鏀堕泦鏈缁勭洏鐨勬潯鐮�
-        });
-
-        // 淇锛氭寜鎵樼洏瀛樺偍宸茬粍鐩樻潯鐮�
-        if (!this.palletGroupedBarcodes[this.trayBarcode]) {
-          this.palletGroupedBarcodes[this.trayBarcode] = [];
-        }
-        this.palletGroupedBarcodes[this.trayBarcode] = [...new Set([...this.palletGroupedBarcodes[this.trayBarcode], ...newBarcodes])];
-
-        this.orderNo = materialData[0].orderNo;
-        await this.fetchStockStatistics(materialData[0].orderNo);
-        await this.fetchUnpalletMaterialDetails();
-        // 娓呯┖鐗╂枡杈撳叆妗嗗苟淇濇寔鑱氱劍
-        this.barcode = '';
-        this.scanCode = ''; // 娓呯┖鎵爜缂撳瓨
-        this.isScanning = false;
-
-        setTimeout(() => {
           this.focusBarcodeInput();
-        }, 100);
-      } catch (err) {
-        this.error = err.message || '鏌ヨ鏉$爜淇℃伅澶辫触锛岃閲嶈瘯';
-        this.focusBarcodeInput();
-        setTimeout(() => {
-          // 閫変腑杈撳叆妗嗗唴鐨勯敊璇唴瀹癸紙纭繚focus瀹屾垚鍚庢墽琛岋級
-          const inputEl = this.$refs.barcodeInput?.$el?.querySelector('input');
-          if (inputEl) inputEl.select();
-        }, 100);
-      } finally {
-        this.loading = false;
-        this.isSubmitting = false; // 鍏抽棴鎻愪氦閿�
-      }
+          this.error = '';
+          this.loading = true;
+
+          console.log('缁勭洏璇锋眰鍙傛暟:', {
+            palletCode: this.trayBarcode,
+            barcode: currentBarcode,
+            locationTypeDesc: this.currentLocationDesc,
+            locationType: this.form.locationType,
+            warehouseType: this.form.warehouseType
+          });
+
+          return this.fetchMaterialData(currentBarcode);
+        })
+        .then(materialData => {
+          if (!materialData || materialData.length === 0) {
+            return;
+          }
+
+          this.materials = [];
+          const newBarcodes = [];
+          
+          materialData.forEach(item => {
+            this.materials.push({
+              ...item,
+              trayCode: this.trayBarcode,
+              locationType: this.form.locationType,
+              locationDesc: this.currentLocationDesc,
+              scanTime: this.formatTime(new Date())
+            });
+            newBarcodes.push(item.barcode);
+          });
+
+          if (!this.palletGroupedBarcodes[this.trayBarcode]) {
+            this.palletGroupedBarcodes[this.trayBarcode] = [];
+          }
+          this.palletGroupedBarcodes[this.trayBarcode] = [...new Set([...this.palletGroupedBarcodes[this.trayBarcode], ...newBarcodes])];
+
+          this.orderNo = materialData[0].orderNo;
+          
+          return Promise.all([
+            this.fetchStockStatistics(materialData[0].orderNo),
+            this.fetchUnpalletMaterialDetails()
+          ]);
+        })
+        .then(() => {
+          this.barcode = '';
+          this.scanCode = '';
+          this.isScanning = false;
+
+          setTimeout(() => {
+            this.focusBarcodeInput();
+          }, 100);
+        })
+        .catch(err => {
+          console.error('澶勭悊鐗╂枡鏉$爜澶辫触:', err);
+          this.error = err.message || '鏌ヨ鏉$爜淇℃伅澶辫触锛岃閲嶈瘯';
+          this.focusBarcodeInput();
+          setTimeout(() => {
+            const inputEl = this.$refs.barcodeInput?.$el?.querySelector('input');
+            if (inputEl) inputEl.select();
+          }, 100);
+        })
+        .finally(() => {
+          this.loading = false;
+          this.isSubmitting = false;
+        });
     },
 
-    // API璇锋眰 - 鏇挎崲涓哄疄闄呯殑API璋冪敤
-    async fetchMaterialData(barcode) {
-      try {
-        const response = await http.post('/api/Inbound/GroupPallet',
-          {
-            palletCode: this.trayBarcode,
-            barcode: barcode,
-            locationTypeDesc: this.currentLocationDesc,
-            locationType: this.form.locationType, // 娣诲姞浠撳簱鍖哄煙淇℃伅
-            warehouseType: this.form.warehouseType
+    // API璇锋眰
+    fetchMaterialData(barcode) {
+      return http.post('/api/Inbound/GroupPallet', {
+        palletCode: this.trayBarcode,
+        barcode: barcode,
+        locationTypeDesc: this.currentLocationDesc,
+        locationType: this.form.locationType,
+        warehouseType: this.form.warehouseType
+      })
+        .then(response => {
+          let materialData;
+          
+          if (typeof response.data === 'string') {
+            try {
+              materialData = JSON.parse(response.data);
+            } catch (e) {
+              console.error('瑙f瀽鍝嶅簲鏁版嵁澶辫触:', e);
+            }
+          } else {
+            materialData = response.data;
           }
-        );
-        let materialData;
-
-        if (typeof response.data === 'string') {
-          try {
-            materialData = JSON.parse(response.data);
-          } catch (e) { }
-        } else {
-          materialData = response.data;
-        }
-        if (!response.status) {
-          this.error = response.message || '鏌ヨ鏉$爜淇℃伅澶辫触锛岃閲嶈瘯';
-        }
-
-        return materialData;
-
-      } catch (error) {
-        console.error('API璋冪敤澶辫触:', error);
-        this.$message.error('鎺ュ彛璇锋眰澶辫触锛岃鑱旂郴绠$悊鍛�');
-        return [];
-      }
+          
+          if (!response.status) {
+            this.error = response.message || '鏌ヨ鏉$爜淇℃伅澶辫触锛岃閲嶈瘯';
+            return [];
+          }
+          
+          return materialData || [];
+        })
+        .catch(error => {
+          console.error('API璋冪敤澶辫触:', error);
+          this.$message.error('鎺ュ彛璇锋眰澶辫触锛岃鑱旂郴绠$悊鍛�');
+          throw error;
+        });
     },
 
     // 澶勭悊鎵爜鏋緭鍏�
     handleKeyPress(event) {
-      // 濡傛灉鏄墜鍔ㄨ緭鍏ユā寮忔垨姝e湪鎻愪氦锛屼笉澶勭悊鎵爜鏋�昏緫
       if (this.isManualInput || this.isSubmitting) {
         return;
       }
@@ -774,11 +804,9 @@
       const key = event.key;
       const currentTime = new Date().getTime();
 
-      // 蹇界暐鐩存帴鎸変笅鐨勫洖杞﹂敭锛堢敱handleBarcodeSubmit澶勭悊锛�
       if (key === 'Enter') {
-        event.preventDefault(); // 寮哄埗闃绘榛樿琛屼负锛岄伩鍏嶉噸澶嶈Е鍙�
+        event.preventDefault();
         if (this.scanCode.length > 0) {
-          // 鏂板锛氭壂鐮佺洰鏍囦负鐗╂枡鏃讹紝鏍¢獙褰撳墠鎵樼洏鏄惁瀛樺湪
           if (this.scanTarget === 'material' && !this.trayBarcode) {
             this.$message.warning('璇峰厛璁剧疆鎵樼洏鏉$爜');
             this.scanCode = '';
@@ -786,10 +814,8 @@
             return;
           }
 
-          // 鎵爜瀹屾垚锛岃嚜鍔ㄨЕ鍙戞煡璇�
           this.isScanning = false;
 
-          // 鏍规嵁褰撳墠鎵爜鐩爣璁剧疆鐩稿簲鐨勮緭鍏ユ鍊�
           if (this.scanTarget === 'tray') {
             this.trayBarcode = this.scanCode;
             this.handleTraySubmit();
@@ -803,7 +829,6 @@
         return;
       }
 
-      // 鏋勫缓鎵爜鍐呭锛堝揩閫熻繛缁緭鍏ヨ涓烘壂鐮侊級
       if (this.lastKeyTime && currentTime - this.lastKeyTime < 50) {
         this.scanCode += key;
         this.isScanning = true;
@@ -812,7 +837,6 @@
         this.isScanning = true;
       }
 
-      // 璁剧疆璁℃椂鍣紝濡傛灉涓�娈垫椂闂村唴娌℃湁杈撳叆锛屽垯閲嶇疆鎵弿鐘舵��
       if (this.scanTimer) {
         clearTimeout(this.scanTimer);
       }
@@ -835,9 +859,8 @@
       return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
     },
 
-    // 浠撳簱鍒囨崲浜嬩欢锛堣ˉ鍏呭疄鐜帮紝鍘熶唬鐮佺己澶憋級
+    // 浠撳簱鍒囨崲浜嬩欢
     handleWarehouseChange() {
-      // 鍒囨崲浠撳簱鏃舵竻绌哄尯鍩熷拰鎵樼洏鐩稿叧鐘舵��
       this.form.locationType = null;
       this.trayBarcode = '';
       this.barcode = '';
@@ -845,9 +868,8 @@
       this.error = '';
     },
 
-    // 鍖哄煙鍒囨崲浜嬩欢锛堣ˉ鍏呭疄鐜帮紝鍘熶唬鐮佺己澶憋級
+    // 鍖哄煙鍒囨崲浜嬩欢
     handleLocationChange() {
-      // 鍒囨崲鍖哄煙鏃舵竻绌烘墭鐩樼浉鍏崇姸鎬�
       this.trayBarcode = '';
       this.barcode = '';
       this.materials = [];

--
Gitblit v1.9.3