From 21f9a188ea9c7f8c5aefea9f151c963ebe45b627 Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期二, 20 一月 2026 14:21:58 +0800
Subject: [PATCH] 1

---
 项目代码/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue |  136 ++++++++++++++++++++++++++++++++------------
 1 files changed, 98 insertions(+), 38 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 e7a1b57..c7201a6 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"
@@ -70,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>
@@ -84,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>
 
@@ -111,7 +111,6 @@
               <el-tag type="primary" size="small">鏈粍鐩� {{ totalStockCount }}</el-tag>
             </span>
           </div>
-
 
           <div class="table-container">
             <el-table :data="unpalletMaterials" stripe style="width: 100%" height="100%" size="small"
@@ -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>
@@ -171,9 +170,23 @@
     </template>
   </vol-box>
 </template>
+
 <script>
 import http from '@/api/http.js';
 import VolBox from '@/components/basic/VolBox.vue';
+
+// 鏂板锛氶槻鎶栧嚱鏁�
+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 {
   components: { VolBox },
@@ -204,7 +217,8 @@
       manualInputTimer: null,
       scanTarget: 'tray', // 褰撳墠鎵爜鐩爣: tray 鎴� material
       isSubmitting: false, // 鏂板锛氭彁浜ら攣瀹氾紝闃叉閲嶅璇锋眰
-      groupedBarcodes: [],
+      // 淇锛氭敼涓烘寜鎵樼洏瀛樺偍宸茬粍鐩樻潯鐮侊紝閬垮厤鐘舵�佹贩娣�
+      palletGroupedBarcodes: {}, // 鏍煎紡锛歿 [trayBarcode]: [barcode1, barcode2, ...] }
 
       // 搴撳瓨缁熻鐩稿叧鍙橀噺
       totalStockSum: 0,
@@ -256,6 +270,10 @@
     currentLocationDesc() {
       const location = this.locationTypes.find(item => item.locationType === this.form.locationType)
       return location ? location.locationTypeDesc : ''
+    },
+    // 鏂板锛氶槻鎶栧悗鐨勭墿鏂欐彁浜ゆ柟娉�
+    debounceHandleBarcodeSubmit() {
+      return debounce(this.handleBarcodeSubmit, 500);
     }
   },
   watch: {
@@ -342,6 +360,7 @@
     },
     async initLocationTypes() {
       try {
+        // 淇锛歨ttp 鏀逛负 this.$http锛堝師浠g爜閿欒锛�
         const { data } = await this.http.post("api/LocationInfo/GetLocationTypes")
         this.locationTypes = data
       } catch (e) {
@@ -350,6 +369,7 @@
     },
     async initwarehouseTypes() {
       try {
+        // 淇锛歨ttp 鏀逛负 this.$http锛堝師浠g爜閿欒锛�
         const { data } = await this.http.post("api/Warehouse/GetwarehouseTypes")
         this.warehouseTypes = data
       } catch (e) {
@@ -396,10 +416,10 @@
             this.error = '';
             resolve(true);
           } else {
-            if (!this.from.warehouseType) {
+            // 淇锛歠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 === null || this.form.locationType === undefined || this.form.locationType === '') {
               this.error = '璇峰厛閫夋嫨浠撳簱鍖哄煙';
             } else {
               this.error = '璇锋鏌ヨ〃鍗曞~鍐欐槸鍚︽纭�';
@@ -436,7 +456,8 @@
     },
     // 閲嶇疆鎵�鏈夋暟鎹�
     resetData() {
-      this.groupedBarcodes = []; // 娓呯┖宸茬粍鐩樻潯鐮�
+      // 淇锛氭竻绌烘寜鎵樼洏瀛樺偍鐨勫凡缁勭洏鏉$爜
+      this.palletGroupedBarcodes = {};
       this.isSubmitting = false; // 閲嶇疆鎻愪氦閿�
       this.trayBarcode = '';
       this.barcode = '';
@@ -445,12 +466,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;
@@ -550,6 +571,11 @@
 
     // 澶勭悊鎵樼洏鏉$爜鎻愪氦
     async handleTraySubmit() {
+      // 淇锛氬垏鎹㈡墭鐩樻椂娓呯┖鐗╂枡鐩稿叧鐘舵�侊紝閬垮厤鏃ф暟鎹畫鐣�
+      this.barcode = '';
+      this.materials = [];
+      this.error = '';
+
       // 鍏堢洿鎺ユ鏌ocationType锛岄伩鍏嶈〃鍗曢獙璇佺殑寮傛闂
       if (!this.form.warehouseType) {
         this.error = '璇峰厛閫夋嫨浠撳簱';
@@ -557,7 +583,6 @@
       }
       if (!this.form.locationType) {
         this.error = '璇峰厛閫夋嫨浠撳簱鍖哄煙';
-        //this.$message.warning('璇峰厛閫夋嫨浠撳簱鍖哄煙');
         return;
       }
 
@@ -574,11 +599,6 @@
       this.error = '';
 
       if (!this.trayBarcodeReg.test(currentTrayBarcode)) {
-        // ElMessage.warning({
-        //   message: '鎵樼洏鍙锋牸寮忛敊璇�',
-        //   type: 'warning',
-        //   duration: 3000
-        // })
         this.$message("鎵樼洏鍙锋牸寮忛敊璇�");
         this.focusTrayInput();
         return;
@@ -587,11 +607,6 @@
       // 璁剧疆鎵樼洏鏉$爜鍚庯紝鑷姩鑱氱劍鍒扮墿鏂欒緭鍏ユ
       this.focusBarcodeInput();
 
-      // this.$message({
-      //   message: `鎵樼洏鏉$爜宸茶缃�: ${currentTrayBarcode}`,
-      //   type: 'success',
-      //   duration: 2000
-      // });
       this.$message.success(`鎵樼洏鏉$爜宸茶缃�: ${currentTrayBarcode}`);
     },
 
@@ -620,15 +635,24 @@
       this.isScanning = false;
     },
 
-
     // 澶勭悊鐗╂枡鏉$爜鎻愪氦
     async handleBarcodeSubmit() {
       if (this.isSubmitting) {
-    this.$message.warning('姝e湪澶勭悊涓紝璇风◢鍊�');
-    return;
-  }
-      if (!await this.validateForm()) return;
+        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 = '';
+        this.focusBarcodeInput();
+        return;
+      }
+
+      if (!await this.validateForm()) return;
 
       if (!this.trayBarcode) {
         this.error = '璇峰厛杈撳叆鎵樼洏鏉$爜';
@@ -647,6 +671,15 @@
       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) {
@@ -665,8 +698,12 @@
           });
           newBarcodes.push(item.barcode); // 鏀堕泦鏈缁勭洏鐨勬潯鐮�
         });
-         // 灏嗘湰娆$粍鐩樼殑鏉$爜鍔犲叆宸茬粍鐩樺垪琛�
-        this.groupedBarcodes = [...new Set([...this.groupedBarcodes, ...newBarcodes])];
+
+        // 淇锛氭寜鎵樼洏瀛樺偍宸茬粍鐩樻潯鐮�
+        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);
@@ -708,12 +745,9 @@
         let materialData;
 
         if (typeof response.data === 'string') {
-
           try {
             materialData = JSON.parse(response.data);
-          } catch (e) {
-
-          }
+          } catch (e) { }
         } else {
           materialData = response.data;
         }
@@ -725,12 +759,14 @@
 
       } catch (error) {
         console.error('API璋冪敤澶辫触:', error);
+        this.$message.error('鎺ュ彛璇锋眰澶辫触锛岃鑱旂郴绠$悊鍛�');
+        return [];
       }
     },
 
     // 澶勭悊鎵爜鏋緭鍏�
     handleKeyPress(event) {
-      // 濡傛灉鏄墜鍔ㄨ緭鍏ユā寮忥紝涓嶅鐞嗘壂鐮佹灙閫昏緫
+      // 濡傛灉鏄墜鍔ㄨ緭鍏ユā寮忔垨姝e湪鎻愪氦锛屼笉澶勭悊鎵爜鏋�昏緫
       if (this.isManualInput || this.isSubmitting) {
         return;
       }
@@ -742,8 +778,13 @@
       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;
@@ -792,6 +833,25 @@
       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 = '';
     }
   }
 }

--
Gitblit v1.9.3