From 1378fc4cd7abc24ed3a982e09437c2c8a74e9f2f Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期二, 27 一月 2026 19:06:32 +0800
Subject: [PATCH] 代码优化

---
 项目代码/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue |  998 +++++++++++++++++++++++++---------------------------------
 1 files changed, 433 insertions(+), 565 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 61170fd..5c9a1b6 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"
@@ -1,12 +1,11 @@
 <template>
-  <vol-box v-model="groupPalletVisible" :title="'缁勭洏鎿嶄綔 - 鍗曟嵁鍙凤細' + currentDocNo" :height="1000" :width="1100" :padding="20"
-    :modal="true" @open="handleDialogOpen" @close="handleDialogClose">
+  <vol-box v-model="show" :title="'缁勭洏鎿嶄綔 - 鍗曟嵁鍙凤細' + orderNo" :height="1000" :width="1100" :padding="20" :modal="true">
     <div class="barcode-scanner-container">
 
       <!-- 浠撳簱閫夋嫨 - 绱у噾甯冨眬 -->
       <div class="location-section compact">
         <el-form :model="form" :rules="rules" ref="locationForm" class="compact-form">
-          <el-form-item label="浠撳簱" prop="warehouseType" class="location-select compact-item">
+          <el-form-item label="鍏ュ簱浠撳簱" prop="warehouseType" class="location-select compact-item">
             <el-select v-model="form.warehouseType" placeholder="璇烽�夋嫨浠撳簱" clearable filterable
               @change="handleWarehouseChange" style="width: 100%" :loading="warehouseLoading" size="medium">
               <el-option v-for="item in warehouseTypes" :key="item.warehouseType" :label="item.warehouseTypeDesc"
@@ -53,7 +52,7 @@
 
           <!-- 鎵樼洏鏉$爜杈撳叆 -->
           <div class="input-wrapper custom-input-group compact-input">
-            <div class="input-label">鏂欑鐮�</div>
+            <div class="input-label">鎵樼洏鏉$爜</div>
             <el-input ref="trayInput" v-model="trayBarcode" placeholder="璇锋壂鎻忔垨杈撳叆鏂欑鐮佸悗鎸夊洖杞﹂敭" clearable
               :disabled="!form.locationType || !form.warehouseType" @keyup.enter.native="handleTraySubmit"
               @clear="handleTrayClear" @input="handleTrayInput" class="custom-input" size="medium">
@@ -71,11 +70,11 @@
             <div class="input-label">鐗╂枡鏉$爜</div>
             <el-input ref="barcodeInput" v-model="barcode" placeholder="璇锋壂鎻忔垨杈撳叆鐗╂枡鏉$爜鍚庢寜鍥炶溅閿�" clearable
               :disabled="!form.locationType || !trayBarcode || !form.warehouseType"
-              @keyup.enter.native="handleBarcodeSubmit" @clear="handleClear" @input="handleBarcodeInput"
+              @keyup.enter.native="debounceHandleBarcodeSubmit" @clear="handleClear" @input="handleBarcodeInput"
               class="custom-input" size="medium">
               <template slot="append">
-                <el-button :loading="loading" @click="handleBarcodeSubmit" type="primary" icon="el-icon-search"
-                  :disabled="!form.locationType || !trayBarcode || !barcode || !from.warehouseType" size="medium">
+                <el-button :loading="loading" @click="debounceHandleBarcodeSubmit" type="primary" icon="el-icon-search"
+                  :disabled="!form.locationType || !trayBarcode || !barcode || !form.warehouseType" size="medium">
                   {{ loading ? '鏌ヨ涓�...' : '鏌ヨ' }}
                 </el-button>
               </template>
@@ -85,7 +84,7 @@
           <div class="input-tips compact-tips">
             <p>鎻愮ず锛氳鍏堥�夋嫨浠撳簱 鈫� 閫夋嫨浠撳簱鍖哄煙 鈫� 杈撳叆鏂欑鐮� 鈫� 杈撳叆鐗╂枡鏉$爜</p>
             <p v-if="!form.warehouseType" class="warning-text">鈿狅笍 璇峰厛閫夋嫨浠撳簱</p>
-            <p v-if="!form.locationType && !form.warehouseType" class="warning-text">鈿狅笍 璇峰厛閫夋嫨浠撳簱鍖哄煙</p>
+            <p v-if="form.warehouseType && !form.locationType" class="warning-text">鈿狅笍 璇峰厛閫夋嫨浠撳簱鍖哄煙</p>
             <p v-if="form.warehouseType && form.locationType && !trayBarcode" class="warning-text">鈿狅笍 璇峰厛杈撳叆鏂欑鐮�</p>
           </div>
 
@@ -113,9 +112,9 @@
             </span>
           </div>
 
-          
-          <div  class="table-container">
-            <el-table :data="unpalletMaterials" stripe style="width: 100%" height="100%" size="small" v-loading="unpalletBarcodesLoading">
+          <div class="table-container">
+            <el-table :data="unpalletMaterials" stripe style="width: 100%" height="100%" size="small"
+              v-loading="unpalletBarcodesLoading">
               <el-table-column type="index" label="搴忓彿" width="60" align="center"></el-table-column>
               <el-table-column prop="barcode" label="鏉$爜" min-width="140" show-overflow-tooltip></el-table-column>
               <el-table-column prop="materielCode" label="鐗╂枡缂栫爜" min-width="150" show-overflow-tooltip></el-table-column>
@@ -126,7 +125,7 @@
             </el-table>
           </div>
         </el-card>
-        
+
       </div>
 
       <!-- 鐗╂枡鍒楄〃 - 鍥哄畾楂樺害甯︽粴鍔ㄦ潯 -->
@@ -146,7 +145,7 @@
           <div v-if="materials.length === 0" class="empty-state compact">
             <i class="el-icon-document"></i>
             <p v-if="!form.warehouseType">璇峰厛閫夋嫨浠撳簱</p>
-            <p v-if="!form.locationType">璇峰厛閫夋嫨浠撳簱鍖哄煙</p>
+            <p v-if="form.warehouseType && !form.locationType">璇峰厛閫夋嫨浠撳簱鍖哄煙</p>
             <p v-else-if="!trayBarcode">璇峰厛杈撳叆鏂欑鏉$爜</p>
             <p v-else>鏆傛棤鐗╂枡鏁版嵁锛岃鎵弿鎴栬緭鍏ョ墿鏂欐潯鐮�</p>
           </div>
@@ -166,35 +165,37 @@
         </el-card>
       </div>
     </div>
-
-    <!--      <div slot="footer" class="dialog-footer">
-      <el-button @click="handleCancel">鍙栨秷</el-button>
-      <el-button type="primary" @click="handleConfirm">纭</el-button>
-    </div> -->
+    <template #footer>
+      <el-button type="danger" size="small" @click="handleDialogClose()">鍏抽棴</el-button>
+    </template>
   </vol-box>
 </template>
+
 <script>
 import http from '@/api/http.js';
 import VolBox from '@/components/basic/VolBox.vue';
-import VolForm from '@/components/basic/VolForm.vue';
-import VolTable from '@/components/basic/VolTable.vue';
-import { ElLoading, ElMessage, ElMessageBox } from 'element-plus';
-import { ref, onMounted, onUnmounted } from 'vue'
-import InboundOrder from '../../../views/inbound/inboundOrder.vue';
-import { th } from 'element-plus/es/locales.mjs';
+
+// 闃叉姈鍑芥暟
+function debounce(func, wait) {
+  let timeout;
+  return function () {
+    const context = this;
+    const args = arguments;
+    clearTimeout(timeout);
+    timeout = setTimeout(() => {
+      func.apply(context, args);
+    }, wait);
+  };
+}
 
 export default {
-  name: 'BarcodeScanner',
-  components: { VolBox, VolForm, VolTable },
-  props: {
-    docNo: { type: String, required: true, default: '' },
-    visible: { type: Boolean, required: true, default: false }
-  },
-
+  components: { VolBox },
   data() {
     return {
+      show: false,
+      orderNo: "",
       palletVisible: this.visible,
-      trayBarcodeReg:/^[A-Z]\d{9}$/,
+      trayBarcodeReg: /^[A-Z]\d{9}$/,
       trayBarcode: '',
       barcode: '',
       materials: [],
@@ -203,29 +204,27 @@
       debugMode: false,
       currentFocus: 'warehouse',
 
-      unpalletBarcodes:[],
+      unpalletBarcodes: [],
       unpalletBarcodesLoading: false,
-      unpalletMaterials: [], // 鏈粍鐩樿缁嗘暟鎹垪琛�
+      unpalletMaterials: [],
 
-      // 鎵爜鏋浉鍏冲彉閲�
       scanCode: '',
       lastKeyTime: null,
       isManualInput: false,
       isScanning: false,
       scanTimer: null,
       manualInputTimer: null,
-      scanTarget: 'tray', // 褰撳墠鎵爜鐩爣: tray 鎴� material
+      scanTarget: 'tray',
+      isSubmitting: false,
+      palletGroupedBarcodes: {},
 
-      // 搴撳瓨缁熻鐩稿叧鍙橀噺
       totalStockSum: 0,
       totalStockCount: 0,
       uniqueUnit: '',
       sumLoading: false,
       sumError: '',
-      // 浠撳簱鐩稿叧鍙橀噺
       warehouseTypes: [],
       warehouseLoading: false,
-      // 浠撳簱鍖哄煙鐩稿叧鍙橀噺
       locationTypes: [],
       locationLoading: false,
       form: {
@@ -239,12 +238,12 @@
             trigger: 'change'
           }
         ],
-        trayBarcode:[
+        trayBarcode: [
           {
             pattern: this.trayBarcodeReg,
             message: '鎵樼洏鍙锋牸寮忛敊璇紙闇�涓�1涓ぇ鍐欏瓧姣�+9涓暟瀛楋紝濡侫000008024锛�',
             trigger: 'blur'
-         }
+          }
         ],
         warehouseType: [
           {
@@ -252,95 +251,130 @@
             trigger: 'change'
           }
         ]
-      }
+      },
+      
+      // 鏂板锛氶敭鐩樹簨浠剁洃鍚爣璁�
+      keyPressListenerAdded: false,
+      isDialogClosing: false
     }
   },
+
   computed: {
-    groupPalletVisible: {
-      get() { return this.visible; },
-      set(newVal) { this.$emit('update:visible', newVal); }
-    },
-    currentDocNo() { return this.docNo; },
-    // 褰撳墠閫夋嫨鐨勪粨搴撳悕绉�
     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: {
+    // 鐩戝惉show鍙橀噺鍙樺寲
+    show(newVal) {
+      if (newVal === true) {
+        console.log('寮规鎵撳紑锛岄噸缃暟鎹�');
+        this.isDialogClosing = false;
+        this.resetData();
+        this.$nextTick(() => {
+          setTimeout(() => {
+            this.fetchUnpalletMaterialDetails();
+            this.addKeyPressListener(); // 娣诲姞閿洏浜嬩欢鐩戝惉
+          }, 300);
+        });
+      } else if (newVal === false && !this.isDialogClosing) {
+        console.log('寮规鍏抽棴锛岀Щ闄や簨浠剁洃鍚�');
+        this.isDialogClosing = true;
+        this.removeKeyPressListener(); // 绉婚櫎閿洏浜嬩欢鐩戝惉
+        this.resetData();
+      }
+    },
+    
     visible(newVal, oldVal) {
       this.palletVisible = newVal;
 
-      // 褰撲粠 false 鍙樹负 true 鏃讹紝琛ㄧず寮规鎵撳紑
       if (newVal === true && oldVal === false) {
         console.log('寮规鎵撳紑锛岄噸缃暟鎹�');
         this.resetData();
         this.$nextTick(() => {
           setTimeout(() => {
-            // this.focusTrayInput();
-            this.initwarehouseTypes(); // 鍒濆鍖栦粨搴�
-            this.initLocationTypes(); // 鍒濆鍖栦粨搴撳尯鍩�
-            this.fetchStockStatistics(); // 鍔犺浇缁熻鏁版嵁
             this.fetchUnpalletMaterialDetails();
           }, 300);
         });
       }
 
-      // 褰撲粠 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: '' };
         this.backData = [];
         this.$refs.palletForm?.reset();
-        this.fetchStockStatistics(); // 鍗曟嵁鍙峰彉浜嗭紝鍒锋柊缁熻
         this.fetchUnpalletMaterialDetails();
       }
     }
   },
-  'form.warehouseType'(newVal) {
-    if (newVal) {
-      this.form.locationType = null;
-    } else {
-      this.locationTypes = [];
-    }
-  },
-
+  
   mounted() {
-
-    // 娣诲姞鍏ㄥ眬閿洏鐩戝惉
-    document.addEventListener('keypress', this.handleKeyPress);
-
-    // 浣跨敤setTimeout纭繚DOM瀹屽叏娓叉煋鍚庡啀鑱氱劍
-    setTimeout(() => {
-      // this.focusTrayInput();
-      this.focusLocationSelect();
-    }, 300);
+    // 涓嶅湪mounted鏃舵坊鍔犵洃鍚紝鍦ㄥ脊绐楁墦寮�鏃舵坊鍔�
   },
+  
   beforeDestroy() {
-    // 娓呯悊浜嬩欢鐩戝惉
-    document.removeEventListener('keypress', this.handleKeyPress);
+    // 纭繚缁勪欢閿�姣佹椂绉婚櫎鐩戝惉
+    this.removeKeyPressListener();
     this.clearAllTimers();
   },
+  
   methods: {
-    /**
-* 鑷畾涔変粨搴撳尯鍩熼獙璇�
-* 鍏佽鍊间负0锛屽洜涓�0鏄悎娉曠殑locationType
-*/
+    // 娣诲姞閿洏浜嬩欢鐩戝惉
+    addKeyPressListener() {
+      if (!this.keyPressListenerAdded) {
+        document.addEventListener('keypress', this.handleKeyPress);
+        this.keyPressListenerAdded = true;
+        console.log('閿洏浜嬩欢鐩戝惉宸叉坊鍔�');
+      }
+    },
+    
+    // 绉婚櫎閿洏浜嬩欢鐩戝惉
+    removeKeyPressListener() {
+      if (this.keyPressListenerAdded) {
+        document.removeEventListener('keypress', this.handleKeyPress);
+        this.keyPressListenerAdded = false;
+        console.log('閿洏浜嬩欢鐩戝惉宸茬Щ闄�');
+      }
+    },
+    
+    open() {
+      this.show = true;
+      this.orderNo = "";
+      this.resetData();
+      this.initLocationTypes();
+      this.initwarehouseTypes();
+      this.fetchUnpalletMaterialDetails();
+      
+      // 寮圭獥鎵撳紑鏃舵坊鍔犻敭鐩樹簨浠剁洃鍚�
+      this.$nextTick(() => {
+        setTimeout(() => {
+          this.addKeyPressListener();
+        }, 100);
+      });
+    },
+    
     validateLocationType(rule, value, callback) {
-      // 妫�鏌ュ�兼槸鍚︿负null銆乽ndefined鎴栫┖瀛楃涓诧紝浣嗗厑璁告暟瀛�0
       if (!this.form.warehouseType) {
         callback(new Error('璇峰厛閫夋嫨浠撳簱'));
       } else if (value === null || value === undefined || value === '') {
@@ -349,194 +383,105 @@
         callback();
       }
     },
-    
-    // 鏍规嵁鏉$爜鍒楄〃鑾峰彇璇︾粏鏁版嵁
-    async fetchUnpalletMaterialDetails() {
-      try {
-        // 灏濊瘯璋冪敤鎺ュ彛鑾峰彇璇︾粏鏁版嵁
-        // 娉ㄦ剰锛氬鏋滆繖涓帴鍙d笉瀛樺湪锛屽彲浠ユ敞閲婃帀鎴栨牴鎹疄闄匒PI璋冩暣
-        const response = await http.post('/api/InboundOrder/UnPalletGroupBarcode?orderNo='+this.docNo, {
-          
+
+    // 鑾峰彇鏈粍鐩樼墿鏂欒鎯�
+    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;
         });
-
-        console.log('鏈粍鐩樻暟鎹�:', response.data);
-
-
-        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 {
-          // 濡傛灉鎺ュ彛杩斿洖鏍煎紡涓嶅悓锛屽皾璇曞叾浠栨柟寮�
-          // 濡傛灉鎺ュ彛涓嶅瓨鍦紝杩欓噷浼氳繘鍏atch锛岃缃负绌烘暟缁�
-          this.unpalletMaterials = [];
-        }
-      } catch (err) {
-        console.warn('鑾峰彇鏈粍鐩樿缁嗘暟鎹帴鍙e彲鑳戒笉瀛樺湪锛屼娇鐢ㄦ潯鐮佸垪琛ㄦ樉绀猴細', err);
-        // 濡傛灉鎺ュ彛涓嶅瓨鍦紝灏嗘潯鐮佸垪琛ㄨ浆鎹负绠�鍗曠殑鏄剧ず鏍煎紡
-        // 鎴栬�呬繚鎸佷负绌猴紝璁╃敤鎴风煡閬撻渶瑕侀�夋嫨浠撳簱鍜屽尯鍩熸潵鏌ョ湅璇︾粏鏁版嵁
-        this.unpalletMaterials = this.unpalletBarcodes.map(barcode => ({
-          barcode: barcode,
-          materielCode: '-',
-          batchNo: '-',
-          stockQuantity: '-',
-          unit: '-',
-          supplyCode: '-',
-          warehouseType: '-'
-        }));
-      }
     },
-    /**
-    * 鍒濆鍖栦粨搴撳尯鍩熸暟鎹�
-    */
-    async initLocationTypes() {
+    
+    // 鍒濆鍖栦粨搴撳尯鍩熺被鍨�
+    initLocationTypes() {
       this.locationLoading = true;
-      this.error = '';
-
-      try {
-        const response = await http.post('/api/LocationInfo/GetLocationTypes');
-
-        if (response.status && Array.isArray(response.data)) {
-          this.locationTypes = response.data;
-          if (this.locationTypes.length === 0) {
-            this.error = '鏈幏鍙栧埌浠撳簱鍖哄煙鏁版嵁';
-          } else {
-            // 濡傛灉鏈夐粯璁ゅ尯鍩燂紝鍙互鍦ㄨ繖閲岃缃�
-            // this.form.locationType = this.locationTypes[0].locationType;
-          }
-        } else {
-          this.error = '鑾峰彇浠撳簱鍖哄煙鏁版嵁澶辫触';
-        }
-      } catch (error) {
-        console.error('鑾峰彇浠撳簱鍖哄煙澶辫触:', error);
-        this.error = `鑾峰彇浠撳簱鍖哄煙澶辫触: ${error.message || '缃戠粶閿欒'}`;
-      } finally {
-        this.locationLoading = false;
-      }
+      
+      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() {
+    
+    // 鍒濆鍖栦粨搴撶被鍨�
+    initwarehouseTypes() {
       this.warehouseLoading = true;
-      this.error = '';
-
-      try {
-        const response = await http.post('/api/Warehouse/GetwarehouseTypes');
-
-        if (response.status && Array.isArray(response.data)) {
-          this.warehouseTypes = response.data;
-          if (this.warehouseTypes.length === 0) {
-            this.error = '鏈幏鍙栧埌浠撳簱鏁版嵁';
-          } else {
-            // 濡傛灉鏈夐粯璁ゅ尯鍩燂紝鍙互鍦ㄨ繖閲岃缃�
-            // this.form.locationType = this.locationTypes[0].locationType;
-          }
-        } else {
-          this.error = '鑾峰彇浠撳簱鏁版嵁澶辫触';
-        }
-      } catch (error) {
-        console.error('鑾峰彇浠撳簱澶辫触:', error);
-        this.error = `鑾峰彇浠撳簱澶辫触: ${error.message || '缃戠粶閿欒'}`;
-      } finally {
-        this.warehouseLoading = false;
-      }
+      
+      this.http.post("api/Warehouse/GetwarehouseTypes")
+        .then(({ data }) => {
+          this.warehouseTypes = data;
+        })
+        .catch(e => {
+          console.error('鑾峰彇浠撳簱绫诲瀷澶辫触:', e);
+          this.$message.error('鑾峰彇浠撳簱绫诲瀷澶辫触');
+        })
+        .finally(() => {
+          this.warehouseLoading = false;
+        });
     },
 
-
-    /**
-    * 浠撳簱鍖哄煙鍙樻洿澶勭悊
-    */
-    handleLocationChange(value) {
-      console.log('閫夋嫨浠撳簱鍖哄煙:', value, '绫诲瀷:', typeof value, this.currentLocationDesc);
-
-      // 绔嬪嵆娓呴櫎閿欒淇℃伅
-      this.error = '';
-
-      // 鎵嬪姩瑙﹀彂琛ㄥ崟楠岃瘉鏇存柊
-      this.$nextTick(() => {
-        if (this.$refs.locationForm) {
-          // 娓呴櫎璇ュ瓧娈电殑楠岃瘉鐘舵�侊紝鐒跺悗閲嶆柊楠岃瘉
-          this.$refs.locationForm.clearValidate('locationType');
-
-          // 鐭殏寤惰繜鍚庨噸鏂伴獙璇侊紝纭繚DOM宸叉洿鏂�
-          setTimeout(() => {
-            this.$refs.locationForm.validateField('locationType', (errorMsg) => {
-              if (!errorMsg && (value === 0 || value)) {
-                console.log('浠撳簱鍖哄煙楠岃瘉閫氳繃:', value);
-                // 鍖哄煙閫夋嫨鍚庯紝鑷姩鑱氱劍鍒版墭鐩樿緭鍏ユ
-                this.focusLocationSelect();
-                // 鍒锋柊鏈粍鐩樻暟鎹紙鏍规嵁閫夋嫨鐨勪粨搴撳拰鍖哄煙杩囨护锛�
-              }
-            });
-          }, 100);
-        }
-      });
-    },
-
-    /**
-     * 浠撳簱鍙樻洿澶勭悊
-     */
-    handleWarehouseChange(value) {
-      console.log('閫夋嫨浠撳簱:', value, '绫诲瀷:', typeof value, this.currentWarehouseName);
-
-      // 绔嬪嵆娓呴櫎閿欒淇℃伅
-      this.error = '';
-
-      // 鎵嬪姩瑙﹀彂琛ㄥ崟楠岃瘉鏇存柊
-      this.$nextTick(() => {
-        if (this.$refs.locationForm) {
-          // 娓呴櫎璇ュ瓧娈电殑楠岃瘉鐘舵�侊紝鐒跺悗閲嶆柊楠岃瘉
-          this.$refs.locationForm.clearValidate('warehouseType');
-
-          // 鐭殏寤惰繜鍚庨噸鏂伴獙璇侊紝纭繚DOM宸叉洿鏂�
-          setTimeout(() => {
-            this.$refs.locationForm.validateField('warehouseType', (errorMsg) => {
-              if (!errorMsg && (value === 0 || value)) {
-                console.log('浠撳簱楠岃瘉閫氳繃:', value);
-                this.focusLocationSelect();
-              }
-            });
-          }, 100);
-        }
-      });
-    },
-
-    async fetchStockStatistics() {
-      // 鍗曟嵁鍙蜂负绌烘椂涓嶆煡璇�
-      if (!this.docNo) {
+    // 鑾峰彇搴撳瓨缁熻
+    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=' + this.docNo, {
-
+      
+      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;
         });
-
-        // 缁戝畾鏁版嵁锛堝尮閰� PalletSumQuantityDTO 缁撴瀯锛�
-        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;
-        console.error('搴撳瓨缁熻鏌ヨ寮傚父锛�', err);
-      } finally {
-        this.sumLoading = false;
-      }
     },
-    /**
-     * 琛ㄥ崟楠岃瘉
-     */
-    async validateForm() {
+
+    // 琛ㄥ崟楠岃瘉
+    validateForm() {
       return new Promise((resolve) => {
         if (!this.$refs.locationForm) {
           this.error = '琛ㄥ崟鏈垵濮嬪寲';
@@ -550,15 +495,11 @@
             this.error = '';
             resolve(true);
           } else {
-            // 鎵嬪姩妫�鏌ocationType锛屾纭鐞嗗�间负0鐨勬儏鍐�
-            if (!this.from.warehouseType) {
+            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 = '璇峰厛閫夋嫨浠撳簱鍖哄煙';
-              //this.$message.warning('璇峰厛閫夋嫨浠撳簱鍖哄煙');
             } else {
-              // 濡傛灉鍊煎瓨鍦紙鍖呮嫭0锛夛紝浣嗛獙璇佷笉閫氳繃锛屽彲鑳芥槸鍏朵粬楠岃瘉閿欒
               this.error = '璇锋鏌ヨ〃鍗曞~鍐欐槸鍚︽纭�';
             }
             resolve(false);
@@ -566,26 +507,7 @@
         });
       });
     },
-    focusWarehouseSelect() {
-      if (this.$refs.locationForm) {
-        const selectEl = this.$el.querySelector('.location-select:first-child .el-input__inner');
-        if (selectEl) {
-          selectEl.focus();
-          this.currentFocus = 'warehouse';
-        }
-      }
-    },
-    // 鑱氱劍鍒颁粨搴撳尯鍩熼�夋嫨
-    focusLocationSelect() {
-      if (this.$refs.locationForm) {
-        const selectEl = this.$el.querySelector('.location-select:nth-child(2) .el-input__inner');
-        if (selectEl) {
-          selectEl.focus();
-          this.currentFocus = 'location';
-        }
-      }
-    },
-    // 鑱氱劍鍒版墭鐩樿緭鍏ユ
+    
     focusTrayInput() {
       if (this.$refs.trayInput && this.$refs.trayInput.$el) {
         const inputEl = this.$refs.trayInput.$el.querySelector('input');
@@ -598,7 +520,6 @@
       }
     },
 
-    // 鑱氱劍鍒扮墿鏂欒緭鍏ユ
     focusBarcodeInput() {
       if (this.$refs.barcodeInput && this.$refs.barcodeInput.$el) {
         const inputEl = this.$refs.barcodeInput.$el.querySelector('input');
@@ -606,21 +527,14 @@
           inputEl.focus();
           this.currentFocus = 'material';
           this.scanTarget = 'material';
-          
-          
-            inputEl.select();
-            console.log('鐗╂枡杈撳叆妗嗗唴瀹瑰凡閫変腑');
-          
+          inputEl.select();
         }
       }
     },
-
-     
     
-    
-    // 閲嶇疆鎵�鏈夋暟鎹�
     resetData() {
-      console.log('閲嶇疆寮规鏁版嵁');
+      this.palletGroupedBarcodes = {};
+      this.isSubmitting = false;
       this.trayBarcode = '';
       this.barcode = '';
       this.materials = [];
@@ -642,10 +556,10 @@
       this.form = {
         warehouseType: null,
         locationType: null
-      }
+      };
       this.warehouseTypes = [];
       this.locationTypes = [];
-      // 娓呴櫎琛ㄥ崟楠岃瘉鐘舵��
+      
       this.$nextTick(() => {
         if (this.$refs.locationForm) {
           this.$refs.locationForm.clearValidate();
@@ -653,7 +567,6 @@
       });
     },
 
-    // 娓呴櫎鎵�鏈夎鏃跺櫒
     clearAllTimers() {
       if (this.manualInputTimer) {
         clearTimeout(this.manualInputTimer);
@@ -664,148 +577,110 @@
         this.scanTimer = null;
       }
     },
-
-    // 寮规鎵撳紑鏃堕噸缃暟鎹�
-    handleDialogOpen() {
-      console.log('寮规鎵撳紑锛岄噸缃暟鎹�');
-      this.resetData();
-      // 浣跨敤setTimeout纭繚DOM瀹屽叏娓叉煋鍚庡啀鑱氱劍
-      this.$nextTick(() => {
-        setTimeout(() => {
-          this.initwarehouseTypes();
-          this.initLocationTypes(); // 鍒濆鍖栦粨搴撳尯鍩�
-          // 纭繚琛ㄥ崟寮曠敤瀛樺湪鍚庡啀鑱氱劍
-          if (this.$refs.locationForm) {
-            this.focusWarehouseSelect();
-          } else {
-            // 濡傛灉琛ㄥ崟寮曠敤杩樹笉瀛樺湪锛岀◢鍚庨噸璇�
-            setTimeout(() => {
-              this.focusWarehouseSelect();
-            }, 500);
-          }
-        }, 300);
-      });
-    },
-
-    // 寮规鍏抽棴鏃堕噸缃暟鎹�
+    
     handleDialogClose() {
-      console.log('寮规鍏抽棴锛岄噸缃暟鎹�');
+      // 鍏堢Щ闄ら敭鐩樹簨浠剁洃鍚�
+      this.removeKeyPressListener();
+      this.show = false;
       this.resetData();
-    },
-
-    // 鍙栨秷鎸夐挳
-    handleCancel() {
-      this.palletVisible = false;
     },
 
     // 纭鎸夐挳
-    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() {
-      // 鍏堢洿鎺ユ鏌ocationType锛岄伩鍏嶈〃鍗曢獙璇佺殑寮傛闂
+    handleTraySubmit() {
+      this.barcode = '';
+      this.materials = [];
+      this.error = '';
+
       if (!this.form.warehouseType) {
         this.error = '璇峰厛閫夋嫨浠撳簱';
         return;
       }
       if (!this.form.locationType) {
         this.error = '璇峰厛閫夋嫨浠撳簱鍖哄煙';
-        //this.$message.warning('璇峰厛閫夋嫨浠撳簱鍖哄煙');
         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)){
-        ElMessage.warning({
-          message: '鎵樼洏鍙锋牸寮忛敊璇�',
-          type: 'warning',
-          duration: 3000
-        })
-        this.focusTrayInput();
-        return;
-      }
-
-      // 璁剧疆鎵樼洏鏉$爜鍚庯紝鑷姩鑱氱劍鍒扮墿鏂欒緭鍏ユ
-      this.focusBarcodeInput();
-
-      this.$message({
-        message: `鎵樼洏鏉$爜宸茶缃�: ${currentTrayBarcode}`,
-        type: 'success',
-        duration: 2000
-      });
+          this.focusBarcodeInput();
+          this.$message.success(`鎵樼洏鏉$爜宸茶缃�: ${currentTrayBarcode}`);
+        });
     },
 
-    // 娓呴櫎鎵樼洏
     clearTray() {
       this.trayBarcode = '';
       this.materials = [];
@@ -817,65 +692,79 @@
       });
     },
 
-    // 娓呯┖鎵樼洏杈撳叆
     handleTrayClear() {
       this.error = '';
     },
 
-    // 娓呯┖杈撳叆
     handleClear() {
       this.error = '';
       this.scanCode = '';
       this.isManualInput = false;
       this.isScanning = false;
     },
-    
 
     // 澶勭悊鐗╂枡鏉$爜鎻愪氦
-    async handleBarcodeSubmit() {
-      if (!await this.validateForm()) return;
+    handleBarcodeSubmit() {
+      if (this.isSubmitting) {
+        this.$message.warning('姝e湪澶勭悊涓紝璇风◢鍊�');
+        return;
+      }
+
       const currentBarcode = this.barcode.trim();
-
-      if (!this.trayBarcode) {
-        this.error = '璇峰厛杈撳叆鎵樼洏鏉$爜';
-        this.focusTrayInput();
+      const currentTrayGrouped = this.palletGroupedBarcodes[this.trayBarcode] || [];
+      
+      if (currentTrayGrouped.includes(currentBarcode)) {
+        this.error = `鏉$爜 ${currentBarcode} 宸茶褰撳墠鎵樼洏缁勭洏锛岃鍕块噸澶嶆搷浣渀;
+        this.barcode = '';
+        this.focusBarcodeInput();
         return;
       }
 
-      if (!currentBarcode) {
-        this.error = '璇疯緭鍏ユ垨鎵弿鐗╂枡鏉$爜';
-        return;
-      }
-
-      this.focusBarcodeInput();
-      this.error = '';
-      this.loading = true;
-
-      try {
-        // 璋冪敤API鏌ヨ鐗╂枡淇℃伅
-        const materialData = await this.fetchMaterialData(currentBarcode);
-        if (!materialData || materialData.length === 0) {
-
-
-          return;
-        }
-        // 妫�鏌ユ槸鍚﹀凡瀛樺湪鐩稿悓鐗╂枡缂栫爜鐨勮褰�
-        const exists = this.materials.some(item =>
-          item.barcode === this.trayBarcode
-        );
-        console.log('API:', materialData)
-        if (exists) {
-          this.$message({
-            message: '璇ユ潯鐮佸凡瀛樺湪褰撳墠鎵樼洏鐨勫垪琛ㄤ腑',
-            type: 'warning',
-            duration: 2000
-          });
+      this.isSubmitting = true;
+      
+      this.validateForm()
+        .then(valid => {
+          if (!valid) {
+            this.isSubmitting = false;
+            return;
+          }
           
-        } else {
+          if (!this.trayBarcode) {
+            this.error = '璇峰厛杈撳叆鎵樼洏鏉$爜';
+            this.focusTrayInput();
+            this.isSubmitting = false;
+            return;
+          }
 
+          if (!currentBarcode) {
+            this.error = '璇疯緭鍏ユ垨鎵弿鐗╂枡鏉$爜';
+            this.isSubmitting = false;
+            return;
+          }
+
+          this.focusBarcodeInput();
+          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,
@@ -883,105 +772,107 @@
               locationDesc: this.currentLocationDesc,
               scanTime: this.formatTime(new Date())
             });
+            newBarcodes.push(item.barcode);
           });
-          
-          const removeIndex = this.unpalletMaterials.findIndex(item => item.barcode === currentBarcode);
-          if (removeIndex > -1) {
-            this.unpalletMaterials.splice(removeIndex, 1); // 鍒犻櫎鏈粍鐩樺搴旀暟鎹�
-            this.unpalletBarcodes = this.unpalletMaterials.map(item => item.barcode || ''); // 鏇存柊鏉$爜鏁扮粍 
-            this.totalStockCount = Math.max(0, this.totalStockCount - 1);
+
+          if (!this.palletGroupedBarcodes[this.trayBarcode]) {
+            this.palletGroupedBarcodes[this.trayBarcode] = [];
           }
+          this.palletGroupedBarcodes[this.trayBarcode] = [...new Set([...this.palletGroupedBarcodes[this.trayBarcode], ...newBarcodes])];
 
-          this.$message({
-            message: `鎴愬姛娣诲姞鏉$爜: ${currentBarcode}`,
-            type: 'success',
-            duration: 2000
-          });
-
-          this.fetchStockStatistics();
-          // 娓呯┖鐗╂枡杈撳叆妗嗗苟淇濇寔鑱氱劍
+          this.orderNo = materialData[0].orderNo;
+          
+          return Promise.all([
+            this.fetchStockStatistics(materialData[0].orderNo),
+            this.fetchUnpalletMaterialDetails()
+          ]);
+        })
+        .then(() => {
           this.barcode = '';
-          this.scanCode = ''; // 娓呯┖鎵爜缂撳瓨
+          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;
-      }
+        })
+        .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/InboundOrder/BarcodeMaterielGroup',
-          {
-            palletCode: this.trayBarcode,
-            orderNo: this.docNo,
-            barcodes: 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) {
-
+          
+          if (!response.status) {
+            this.error = response.message || '鏌ヨ鏉$爜淇℃伅澶辫触锛岃閲嶈瘯';
+            return [];
           }
-        } else {
-          // 濡傛灉杩斿洖鐨勬槸JSON瀵硅薄锛岀洿鎺ヤ娇鐢�
-          materialData = response.data;
-        }
-        if (!response.status) {
-          this.error = response.message || '鏌ヨ鏉$爜淇℃伅澶辫触锛岃閲嶈瘯';
-        }
-
-        return materialData;
-
-      } catch (error) {
-        console.error('API璋冪敤澶辫触:', error);
-
-
-      }
+          
+          return materialData || [];
+        })
+        .catch(error => {
+          console.error('API璋冪敤澶辫触:', error);
+          this.$message.error('鎺ュ彛璇锋眰澶辫触锛岃鑱旂郴绠$悊鍛�');
+          throw error;
+        });
     },
 
     // 澶勭悊鎵爜鏋緭鍏�
     handleKeyPress(event) {
-      // 濡傛灉鏄墜鍔ㄨ緭鍏ユā寮忥紝涓嶅鐞嗘壂鐮佹灙閫昏緫
-      if (this.isManualInput) {
+      // 妫�鏌ュ脊绐楁槸鍚︽樉绀�
+      if (!this.show || this.isDialogClosing) {
+        return;
+      }
+      
+      if (this.isManualInput || this.isSubmitting) {
         return;
       }
 
       const key = event.key;
       const currentTime = new Date().getTime();
 
-      // 蹇界暐鐩存帴鎸変笅鐨勫洖杞﹂敭锛堢敱handleBarcodeSubmit澶勭悊锛�
       if (key === 'Enter') {
+        event.preventDefault();
         if (this.scanCode.length > 0) {
-          // 闃绘榛樿鍥炶溅琛屼负锛岄伩鍏嶈〃鍗曟彁浜�
-          event.preventDefault();
+          if (this.scanTarget === 'material' && !this.trayBarcode) {
+            this.$message.warning('璇峰厛璁剧疆鎵樼洏鏉$爜');
+            this.scanCode = '';
+            this.lastKeyTime = null;
+            return;
+          }
 
-          // 鎵爜瀹屾垚锛岃嚜鍔ㄨЕ鍙戞煡璇�
           this.isScanning = false;
 
-          // 鏍规嵁褰撳墠鎵爜鐩爣璁剧疆鐩稿簲鐨勮緭鍏ユ鍊�
           if (this.scanTarget === 'tray') {
             this.trayBarcode = this.scanCode;
             this.handleTraySubmit();
@@ -995,7 +886,6 @@
         return;
       }
 
-      // 鏋勫缓鎵爜鍐呭锛堝揩閫熻繛缁緭鍏ヨ涓烘壂鐮侊級
       if (this.lastKeyTime && currentTime - this.lastKeyTime < 50) {
         this.scanCode += key;
         this.isScanning = true;
@@ -1004,7 +894,6 @@
         this.isScanning = true;
       }
 
-      // 璁剧疆璁℃椂鍣紝濡傛灉涓�娈垫椂闂村唴娌℃湁杈撳叆锛屽垯閲嶇疆鎵弿鐘舵��
       if (this.scanTimer) {
         clearTimeout(this.scanTimer);
       }
@@ -1013,44 +902,6 @@
       }, 100);
 
       this.lastKeyTime = currentTime;
-    },
-
-    // 鍒犻櫎鐗╂枡
-    removeMaterial(index) {
-      this.$confirm('纭畾瑕佸垹闄よ繖鏉$墿鏂欒褰曞悧?', '鎻愮ず', {
-        confirmButtonText: '纭畾',
-        cancelButtonText: '鍙栨秷',
-        type: 'warning'
-      }).then(() => {
-        this.materials.splice(index, 1);
-        this.$message({
-          type: 'success',
-          message: '鍒犻櫎鎴愬姛!'
-        });
-        this.fetchStockStatistics();
-
-      }).catch(() => {
-        // 鍙栨秷鍒犻櫎
-      });
-    },
-
-    // 娓呯┖鎵�鏈夌墿鏂�
-    clearAllMaterials() {
-      if (this.materials.length === 0) return;
-
-      this.$confirm('纭畾瑕佹竻绌烘墍鏈夌墿鏂欒褰曞悧?', '鎻愮ず', {
-        confirmButtonText: '纭畾',
-        cancelButtonText: '鍙栨秷',
-        type: 'warning'
-      }).then(() => {
-        this.materials = [];
-        this.$message({
-          type: 'success',
-          message: '宸叉竻绌烘墍鏈夎褰�!'
-        });
-      }).catch(() => {
-        // 鍙栨秷娓呯┖
-      });
     },
 
     // 鏍煎紡鍖栨椂闂�
@@ -1063,6 +914,23 @@
       const seconds = String(date.getSeconds()).padStart(2, '0');
 
       return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
+    },
+
+    // 浠撳簱鍒囨崲浜嬩欢
+    handleWarehouseChange() {
+      this.form.locationType = null;
+      this.trayBarcode = '';
+      this.barcode = '';
+      this.materials = [];
+      this.error = '';
+    },
+
+    // 鍖哄煙鍒囨崲浜嬩欢
+    handleLocationChange() {
+      this.trayBarcode = '';
+      this.barcode = '';
+      this.materials = [];
+      this.error = '';
     }
   }
 }
@@ -1377,35 +1245,35 @@
   }
 
   .unpallet-section.compact {
-  margin-bottom: 8px;
-  flex-shrink: 0;
-}
-
-.unpallet-card {
-  flex-shrink: 0;
-}
-
-.unpallet-barcode-list {
-  display: flex;
-  flex-wrap: wrap;
-  gap: 6px;
-  padding: 8px 0;
-  max-height: 180px;
-  overflow-y: auto;
-}
-
-.unpallet-barcode-list>>>.el-tag {
-  cursor: pointer;
-  max-width: calc(33.333% - 4px);
-  overflow: hidden;
-  text-overflow: ellipsis;
-  white-space: nowrap;
-}
-
-@media (max-width: 768px) {
-  .unpallet-barcode-list>>>.el-tag {
-    max-width: calc(50% - 4px);
+    margin-bottom: 8px;
+    flex-shrink: 0;
   }
-}
+
+  .unpallet-card {
+    flex-shrink: 0;
+  }
+
+  .unpallet-barcode-list {
+    display: flex;
+    flex-wrap: wrap;
+    gap: 6px;
+    padding: 8px 0;
+    max-height: 180px;
+    overflow-y: auto;
+  }
+
+  .unpallet-barcode-list>>>.el-tag {
+    cursor: pointer;
+    max-width: calc(33.333% - 4px);
+    overflow: hidden;
+    text-overflow: ellipsis;
+    white-space: nowrap;
+  }
+
+  @media (max-width: 768px) {
+    .unpallet-barcode-list>>>.el-tag {
+      max-width: calc(50% - 4px);
+    }
+  }
 }
 </style>
\ No newline at end of file

--
Gitblit v1.9.3