From ca3e4977395bc02c5d147dffdff7381333fdfbca Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期四, 09 四月 2026 14:39:37 +0800
Subject: [PATCH] 空箱跨区域移库

---
 项目代码/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue | 2132 ++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 1,475 insertions(+), 657 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 baa1fdc..1fe40a9 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,115 +1,205 @@
 <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="tray-info" v-if="trayBarcode">
-        <i class="el-icon-s-management"></i> 褰撳墠鏂欑: {{ trayBarcode }}
-       <!--  <el-button 
-          class="small-button"
-          type="text" 
-          @click="clearTray"
-          style="float: right;"
+    <div class="barcode-scanner-container">
+      <!-- 浠撳簱閫夋嫨 - 绱у噾甯冨眬 -->
+      <div class="location-section compact">
+        <el-form
+          :model="form"
+          :rules="rules"
+          ref="locationForm"
+          class="compact-form"
         >
-          娓呴櫎鎵樼洏
-        </el-button> -->
+          <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"
+                :value="item.warehouseType"
+              />
+            </el-select>
+          </el-form-item>
+        </el-form>
       </div>
-      
-      <!-- 鎵爜鎴栨墜鍔ㄨ緭鍏ュ尯鍩� -->
-      <div class="input-section">
-        <el-card shadow="hover">
-          <div slot="header">
-            <span><i class="el-icon-scanner"></i> </span>
+
+      <!-- 浠撳簱鍖哄煙閫夋嫨 - 绱у噾甯冨眬 -->
+      <div class="location-section compact">
+        <el-form
+          :model="form"
+          :rules="rules"
+          ref="locationForm"
+          class="compact-form"
+        >
+          <el-form-item
+            label="浠撳簱鍖哄煙"
+            prop="locationType"
+            class="location-select compact-item"
+          >
+            <el-select
+              v-model="form.locationType"
+              placeholder="鑷姩鑾峰彇浠撳簱鍖哄煙"
+              clearable
+              filterable
+              @change="handleLocationChange"
+              style="width: 100%"
+              :loading="locationLoading"
+              size="medium"
+              :disabled="true"
+            >
+              <el-option
+                v-for="item in locationTypes"
+                :key="item.locationType"
+                :label="item.locationTypeDesc"
+                :value="item.locationType"
+              />
+            </el-select>
+          </el-form-item>
+        </el-form>
+      </div>
+
+      <!-- 鎵樼洏淇℃伅鏄剧ず - 绱у噾甯冨眬 -->
+      <div class="tray-info compact" v-if="trayBarcode">
+        <i class="el-icon-s-management"></i> 褰撳墠鏂欑: {{ trayBarcode }}
+        <span class="location-info" v-if="form.warehouseType">
+          | 浠撳簱: {{ currentWarehouseName }}
+        </span>
+        <span class="location-info" v-if="form.locationType">
+          | 浠撳簱鍖哄煙: {{ currentLocationDesc }}
+        </span>
+      </div>
+
+      <!-- 鎵爜鍖哄煙 - 绱у噾甯冨眬 -->
+      <div class="input-section compact">
+        <el-card shadow="hover" class="compact-card">
+          <div slot="header" class="compact-header">
+            <span><i class="el-icon-scanner"></i> 鎵爜鍖哄煙</span>
             <span class="scan-status">
-              <span class="scan-indicator"></span>鎵爜灏辩华
+              <span class="scan-indicator"></span>
+              {{
+                form.locationType && form.warehouseType
+                  ? "鎵爜灏辩华"
+                  : "璇峰厛閫夋嫨浠撳簱鍜屼粨搴撳尯鍩�"
+              }}
             </span>
           </div>
-          
+
           <!-- 鎵樼洏鏉$爜杈撳叆 -->
-          <div class="input-wrapper custom-input-group">
-    <div class="input-label">鏂欑鐮�</div>
+          <div class="input-wrapper custom-input-group compact-input">
+            <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"
+              class="custom-input"
+              size="medium"
             >
-              <template slot="prepend">
-                <span> 鏂欑鏉$爜</span>
-              </template>
               <template slot="append">
-                <el-button 
+                <el-button
                   @click="handleTraySubmit"
                   type="primary"
                   icon="el-icon-position"
+                  :disabled="
+                    !form.locationType || !trayBarcode || !form.warehouseType
+                  "
+                  size="medium"
                 >
                   纭
                 </el-button>
               </template>
             </el-input>
           </div>
-          
+
           <!-- 鐗╂枡鏉$爜杈撳叆 -->
-          <div class="input-wrapper custom-input-group">
+          <div class="input-wrapper custom-input-group compact-input">
             <div class="input-label">鐗╂枡鏉$爜</div>
             <el-input
               ref="barcodeInput"
               v-model="barcode"
               placeholder="璇锋壂鎻忔垨杈撳叆鐗╂枡鏉$爜鍚庢寜鍥炶溅閿�"
               clearable
-              :disabled="!trayBarcode"
-              @keyup.enter.native="handleBarcodeSubmit"
+              :disabled="
+                !form.locationType || !trayBarcode || !form.warehouseType
+              "
+              @keyup.enter.native="debounceHandleBarcodeSubmit"
               @clear="handleClear"
               @input="handleBarcodeInput"
-                    class="custom-input"
+              class="custom-input"
+              size="medium"
             >
-              <template slot="prepend">
-                <span>鐗╂枡鏉$爜</span>
-              </template>
               <template slot="append">
-                <el-button 
-                  :loading="loading" 
-                  @click="handleBarcodeSubmit"
+                <el-button
+                  :loading="loading"
+                  @click="debounceHandleBarcodeSubmit"
                   type="primary"
                   icon="el-icon-search"
-                  :disabled="!trayBarcode"
+                  :disabled="
+                    !form.locationType ||
+                    !trayBarcode ||
+                    !barcode ||
+                    !form.warehouseType
+                  "
+                  size="medium"
                 >
-                  {{ loading ? '鏌ヨ涓�...' : '鏌ヨ' }}
+                  {{ loading ? "鏌ヨ涓�..." : "鏌ヨ" }}
                 </el-button>
               </template>
             </el-input>
           </div>
-          
-          <div class="input-tips">
-            <p>鎻愮ず锛氬厛杈撳叆鏂欑鐮侊紝鐒跺悗杈撳叆鐗╂枡鏉$爜</p>
-       
+
+          <div class="input-tips compact-tips">
+            <p>鎻愮ず锛氳鍏堥�夋嫨浠撳簱 鈫� 閫夋嫨浠撳簱鍖哄煙 鈫� 杈撳叆鏂欑鐮� 鈫� 杈撳叆鐗╂枡鏉$爜</p>
+            <p v-if="!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>
-        
         </el-card>
       </div>
 
       <!-- 鍔犺浇鐘舵�� -->
-      <div v-if="loading" class="loading">
+      <div v-if="loading" class="loading compact">
         <el-progress :percentage="100" status="success" :show-text="false" />
         <p>姝e湪鏌ヨ鐗╂枡淇℃伅...</p>
       </div>
 
       <!-- 閿欒鎻愮ず -->
-      <div v-if="error" class="error-message">
+      <div v-if="error" class="error-message compact">
         <el-alert
           :title="error"
           type="error"
@@ -119,188 +209,696 @@
         />
       </div>
 
-      <!-- 鐗╂枡鍒楄〃 -->
-      <div class="material-list">
-        <el-card shadow="hover">
-          <div slot="header">
-            <span><i class="el-icon-tickets"></i> 缁勭洏鏁版嵁</span>
+      <!-- 鏈粍鐩樺垪琛� -->
+      <div class="unpallet-section compact">
+        <el-card shadow="hover" class="compact-card unpallet-card">
+          <div slot="header" class="compact-header">
+            <span><i class="el-icon-tickets"></i> 鏈粍鐩樻潯鐮�</span>
             <span class="list-actions">
-              <el-tag type="primary">鍏� {{ materials.length }} 鏉¤褰�</el-tag>
-              <el-tag v-if="trayBarcode" type="success">鎵樼洏: {{ trayBarcode }}</el-tag>
-    <!--           <el-button 
-                v-if="materials.length > 0"
-                class="small-button clear-all-btn"
-                type="danger" 
-                icon="el-icon-delete" 
-                @click="clearAllMaterials"
+              <el-tag type="primary" size="small"
+                >鏈粍鐩� {{ totalStockCount }}</el-tag
               >
-                娓呯┖鍒楄〃
-              </el-button> -->
-          <!--     <el-button 
-                class="small-button clear-all-btn"
-                @click="debugMode = !debugMode"
-              >
-                {{ debugMode ? '闅愯棌璋冭瘯' : '鏄剧ず璋冭瘯' }}
-              </el-button> -->
             </span>
           </div>
-          
-          <div v-if="materials.length === 0" class="empty-state">
+
+          <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>
+              <el-table-column
+                prop="batchNo"
+                label="鎵规"
+                min-width="150"
+                show-overflow-tooltip
+              ></el-table-column>
+              <el-table-column
+                prop="orderQuantity"
+                label="鏁伴噺"
+                min-width="130"
+                align="right"
+              ></el-table-column>
+              <el-table-column
+                prop="unit"
+                label="鍗曚綅"
+                width="80"
+                align="center"
+              ></el-table-column>
+              <el-table-column
+                prop="supplyCode"
+                label="渚涘簲鍟�"
+                min-width="130"
+                show-overflow-tooltip
+              ></el-table-column>
+            </el-table>
+          </div>
+        </el-card>
+      </div>
+
+      <!-- 鐗╂枡鍒楄〃 - 鍥哄畾楂樺害甯︽粴鍔ㄦ潯 -->
+      <div class="material-list compact">
+        <el-card shadow="hover" class="compact-card">
+          <div slot="header" class="compact-header">
+            <span><i class="el-icon-tickets"></i> 缁勭洏鏁版嵁</span>
+            <span class="list-actions">
+              <el-tag type="primary" size="small"
+                >鍏� {{ materials.length }} 鏉�</el-tag
+              >
+              <el-tag type="primary" size="small"
+                >鏈叆搴撴暟閲� {{ totalStockSum }}{{ uniqueUnit }}</el-tag
+              >
+              <el-tag v-if="trayBarcode" type="success" size="small"
+                >鎵樼洏: {{ trayBarcode }}</el-tag
+              >
+              <el-tag v-if="form.warehouseType" type="info" size="small"
+                >浠撳簱: {{ currentWarehouseName }}</el-tag
+              >
+              <el-tag v-if="form.locationType" type="info" size="small"
+                >鍖哄煙: {{ currentLocationDesc }}</el-tag
+              >
+            </span>
+          </div>
+
+          <div v-if="materials.length === 0" class="empty-state compact">
             <i class="el-icon-document"></i>
-            <p v-if="!trayBarcode">璇峰厛杈撳叆鏂欑鏉$爜</p>
+            <p v-if="!form.warehouseType">璇峰厛閫夋嫨浠撳簱</p>
+            <p v-if="form.warehouseType && !form.locationType">
+              璇峰厛閫夋嫨浠撳簱鍖哄煙
+            </p>
+            <p v-else-if="!trayBarcode">璇峰厛杈撳叆鏂欑鏉$爜</p>
             <p v-else>鏆傛棤鐗╂枡鏁版嵁锛岃鎵弿鎴栬緭鍏ョ墿鏂欐潯鐮�</p>
           </div>
-          
-          <el-table
-            v-else
-            :data="materials"
-            stripe
-            style="width: 100%"
-          >
-            <el-table-column type="index" label="搴忓彿" width="60" align="center"></el-table-column>
-              <el-table-column prop="barcode" label="鏉$爜" min-width="140"></el-table-column>
-            <el-table-column prop="materielCode" label="鐗╂枡缂栫爜" min-width="150"></el-table-column>
-            <el-table-column prop="batchNo" label="鎵规" min-width="150"></el-table-column>
-            <el-table-column prop="stockQuantity" label="鏁伴噺" min-width="130"></el-table-column>
-            <el-table-column prop="unit" label="鍗曚綅" width="80" align="center"></el-table-column>
-            <el-table-column prop="supplyCode" label="渚涘簲鍟�" min-width="130"></el-table-column>
-            <el-table-column prop="warehouseCode" label="浠撳簱" min-width="120"></el-table-column>
-         
-     <!--        <el-table-column label="鎿嶄綔" width="100" align="center">
-              <template slot-scope="scope">
-                <el-button
-                  v-if="scope"
-                  class="small-button"
-                  type="danger"
-                  icon="el-icon-delete"
-                  circle
-                  @click="removeMaterial(scope.$index)"
-                ></el-button>
-              </template>
-            </el-table-column> -->
-          </el-table>
+
+          <div class="table-container" v-else>
+            <el-table
+              :data="materials"
+              stripe
+              style="width: 100%"
+              height="100%"
+              size="small"
+            >
+              <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>
+              <el-table-column
+                prop="batchNo"
+                label="鎵规"
+                min-width="150"
+                show-overflow-tooltip
+              ></el-table-column>
+              <el-table-column
+                prop="stockQuantity"
+                label="鏁伴噺"
+                min-width="130"
+                align="right"
+              ></el-table-column>
+              <el-table-column
+                prop="unit"
+                label="鍗曚綅"
+                width="80"
+                align="center"
+              ></el-table-column>
+              <el-table-column
+                prop="supplyCode"
+                label="渚涘簲鍟�"
+                min-width="130"
+                show-overflow-tooltip
+              ></el-table-column>
+              <el-table-column
+                prop="warehouseType"
+                label="浠撳簱"
+                min-width="120"
+                show-overflow-tooltip
+              ></el-table-column>
+            </el-table>
+          </div>
         </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> -->
-    </vol-box>
+    <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 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 {
-  name: 'BarcodeScanner',
-  components: { VolBox, VolForm, VolTable },
-  props: {
-    docNo: { type: String, required: true, default: '' },
-    visible: { type: Boolean, required: true, default: false }
-  },
-
+  components: { VolBox },
   data() {
     return {
-        palletVisible: this.visible,
-         trayBarcode: '',
-          barcode: '',
-          materials: [],
-          loading: false,
-          error: '',
-          debugMode: false,
-          currentFocus: 'tray',
-          
-          // 鎵爜鏋浉鍏冲彉閲�
-          scanCode: '',
-          lastKeyTime: null,
-          isManualInput: false,
-          isScanning: false,
-          scanTimer: null,
-          manualInputTimer: null,
-          scanTarget: 'tray', // 褰撳墠鎵爜鐩爣: tray 鎴� material
-    }
-  },
-  computed: {
-    groupPalletVisible: {
-      get() { return this.visible; },
-      set(newVal) { this.$emit('update:visible', newVal); }
-    },
-    currentDocNo() { return this.docNo; }
-  },
-  watch: {
-    visible(newVal, oldVal) {
-    this.palletVisible = newVal;
-    
-    // 褰撲粠 false 鍙樹负 true 鏃讹紝琛ㄧず寮规鎵撳紑
-    if (newVal === true && oldVal === false) {
-      console.log('寮规鎵撳紑锛岄噸缃暟鎹�');
-      this.resetData();
-      this.$nextTick(() => {
-        setTimeout(() => {
-          this.focusTrayInput();
-        }, 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();
-      }
-    }
+      show: false,
+      orderNo: "",
+      palletVisible: this.visible,
+      trayBarcodeReg: /^[A-Z]\d{9}$/,
+      trayBarcode: "",
+      barcode: "",
+      materials: [],
+      loading: false,
+      error: "",
+      debugMode: false,
+      currentFocus: "warehouse",
+
+      unpalletBarcodes: [],
+      unpalletBarcodesLoading: false,
+      unpalletMaterials: [],
+
+      scanCode: "",
+      lastKeyTime: null,
+      isManualInput: false,
+      isScanning: false,
+      scanTimer: null,
+      manualInputTimer: null,
+      scanTarget: "tray",
+      isSubmitting: false,
+      palletGroupedBarcodes: {},
+
+      audioConfig: {
+        successPath: require("@/assets/audio/success.mp3"),
+        errorPath: require("@/assets/audio/error.mp3"),
+      },
+      // 缂撳瓨闊抽瀹炰緥锛岄伩鍏嶉噸澶嶅垱寤�
+      successAudio: null,
+      errorAudio: null,
+
+      totalStockSum: 0,
+      totalStockCount: 0,
+      uniqueUnit: "",
+      sumLoading: false,
+      sumError: "",
+      warehouseTypes: [],
+      warehouseLoading: false,
+      locationTypes: [],
+      locationLoading: false,
+      form: {
+        warehouseType: null,
+        locationType: null,
+      },
+      rules: {
+        locationType: [
+          {
+            validator: this.validateLocationType,
+            trigger: "change",
+          },
+        ],
+        trayBarcode: [
+          {
+            pattern: this.trayBarcodeReg,
+            message: "鎵樼洏鍙锋牸寮忛敊璇紙闇�涓�1涓ぇ鍐欏瓧姣�+9涓暟瀛楋紝濡侫000008024锛�",
+            trigger: "blur",
+          },
+        ],
+        warehouseType: [
+          {
+            message: "璇烽�夋嫨浠撳簱",
+            trigger: "change",
+          },
+        ],
+      },
+
+      // 鏂板锛氶敭鐩樹簨浠剁洃鍚爣璁�
+      keyPressListenerAdded: false,
+      isDialogClosing: false,
+    };
   },
 
- mounted() {
- 
-        // 娣诲姞鍏ㄥ眬閿洏鐩戝惉
-        document.addEventListener('keypress', this.handleKeyPress);
-        
-        // 浣跨敤setTimeout纭繚DOM瀹屽叏娓叉煋鍚庡啀鑱氱劍
+  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: {
+    // 鐩戝惉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;
+
+      if (newVal === true && oldVal === false) {
+        console.log("寮规鎵撳紑锛岄噸缃暟鎹�");
+        this.resetData();
+        this.$nextTick(() => {
+          setTimeout(() => {
+            this.fetchUnpalletMaterialDetails();
+          }, 300);
+        });
+      }
+
+      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.fetchUnpalletMaterialDetails();
+      }
+    },
+  },
+
+  mounted() {
+    // 涓嶅湪mounted鏃舵坊鍔犵洃鍚紝鍦ㄥ脊绐楁墦寮�鏃舵坊鍔�
+  },
+
+  beforeDestroy() {
+    // 纭繚缁勪欢閿�姣佹椂绉婚櫎鐩戝惉
+    this.removeKeyPressListener();
+    this.clearAllTimers();
+
+    this.removeKeyPressListener();
+    this.clearAllTimers();
+
+    //閿�姣侀煶棰戝疄渚�
+    this.successAudio = null;
+    this.errorAudio = null;
+  },
+
+  methods: {
+    /**
+     * 鍒濆鍖栭煶棰戝疄渚嬶紙鎳掑姞杞斤紝鍙垱寤轰竴娆★級
+     * @param {String} type - 闊抽绫诲瀷锛歴uccess/error
+     * @returns {Audio} 闊抽瀹炰緥
+     */
+    initAudioInstance(type) {
+      if (type === "success" && this.successAudio) {
+        return this.successAudio;
+      }
+      if (type === "error" && this.errorAudio) {
+        return this.errorAudio;
+      }
+
+      const audioPath =
+        type === "success"
+          ? this.audioConfig.successPath
+          : this.audioConfig.errorPath;
+
+      const audioInstance = new Audio(audioPath);
+
+      // 缂撳瓨闊抽瀹炰緥
+      if (type === "success") {
+        this.successAudio = audioInstance;
+      } else {
+        this.errorAudio = audioInstance;
+      }
+
+      // 闊抽鍔犺浇澶辫触鍥炶皟锛堝彲閫夛紝鐢ㄤ簬璋冭瘯锛�
+      audioInstance.onerror = (err) => {
+        console.error(`銆�${type} 闊抽銆戝姞杞藉け璐, err);
+      };
+
+      return audioInstance;
+    },
+
+    /**
+     * 鎾斁闊抽
+     * @param {String} type - 闊抽绫诲瀷锛歴uccess/error
+     */
+    playAudio(type) {
+      try {
+        const audioInstance = this.initAudioInstance(type);
+
+        // 閲嶇疆鎾斁杩涘害锛堥伩鍏嶉噸澶嶆挱鏀炬椂闊抽鏈粨鏉燂級
+        audioInstance.currentTime = 0;
+
+        // 鎾斁闊抽锛堣繑鍥� Promise 澶勭悊鎾斁缁撴灉锛屽吋瀹归儴鍒嗘祻瑙堝櫒闄愬埗锛�
+        audioInstance.play().catch((err) => {
+          console.warn("闊抽鎾斁澶辫触锛堝彲鑳芥槸娴忚鍣ㄨ嚜鍔ㄦ挱鏀剧瓥鐣ラ檺鍒讹級", err);
+        });
+      } catch (err) {
+        console.error("鎾斁闊抽鏃跺彂鐢熷紓甯�", err);
+      }
+    },
+
+    /**
+     * 鎾斁鎴愬姛闊抽
+     */
+    playSuccessAudio() {
+      this.playAudio("success");
+    },
+
+    /**
+     * 鎾斁澶辫触闊抽
+     */
+    playErrorAudio() {
+      this.playAudio("error");
+    },
+    // 娣诲姞閿洏浜嬩欢鐩戝惉
+    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.focusTrayInput();
-        }, 300);
-      },
-      beforeDestroy() {
-        // 娓呯悊浜嬩欢鐩戝惉
-        document.removeEventListener('keypress', this.handleKeyPress);
-         this.clearAllTimers();
-      },
-      methods: {
-         // 閲嶇疆鎵�鏈夋暟鎹�
+          this.addKeyPressListener();
+        }, 100);
+      });
+    },
+
+    validateLocationType(rule, value, callback) {
+      if (!this.form.warehouseType) {
+        callback(new Error("璇峰厛閫夋嫨浠撳簱"));
+      } else if (value === null || value === undefined || value === "") {
+        callback(new Error("璇烽�夋嫨浠撳簱鍖哄煙"));
+      } else {
+        callback();
+      }
+    },
+
+    // 鑾峰彇鏈粍鐩樼墿鏂欒鎯�
+    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;
+        });
+    },
+
+    // 鍒濆鍖栦粨搴撳尯鍩熺被鍨�
+    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;
+        });
+    },
+
+    // 鍒濆鍖栦粨搴撶被鍨�
+    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;
+        });
+    },
+
+    fetchLocationByWarehouse(warehouseCode) {
+      if (!warehouseCode) {
+        this.form.locationType = null;
+        return;
+      }
+      this.locationLoading = true;
+      http.post(`/api/InboundOrder/GetLocationType?code=${warehouseCode}`)
+        .then(({ data }) => {
+          if (data) {
+            this.form.locationType = data.locationType || data;
+            if (!this.locationTypes.find(item => item.locationType === this.form.locationType)) {
+              this.locationTypes.push({
+                locationType: this.form.locationType,
+                locationTypeDesc: this.form.locationType
+              });
+            }
+          }
+        })
+        .catch((err) => {
+          console.error("鑾峰彇浠撳簱鍖哄煙澶辫触:", err);
+          this.$message.error("鑾峰彇浠撳簱鍖哄煙澶辫触锛岃閲嶈瘯");
+          this.form.locationType = null;
+        })
+        .finally(() => {
+          this.locationLoading = false;
+        });
+    },
+    // 鑾峰彇搴撳瓨缁熻
+    fetchStockStatistics(orderNo) {
+      if (!orderNo) {
+        this.sumError = "鍗曟嵁鍙蜂负绌猴紝鏃犳硶缁熻";
+        return Promise.resolve(null);
+      }
+
+      this.sumLoading = true;
+      this.sumError = "";
+
+      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;
+        });
+    },
+
+    // 琛ㄥ崟楠岃瘉
+    validateForm() {
+      return new Promise((resolve) => {
+        if (!this.$refs.locationForm) {
+          this.error = "琛ㄥ崟鏈垵濮嬪寲";
+          this.$message.warning("璇峰厛閫夋嫨浠撳簱鍖哄煙");
+          resolve(false);
+          return;
+        }
+
+        this.$refs.locationForm.validate((valid) => {
+          if (valid) {
+            this.error = "";
+            resolve(true);
+          } else {
+            if (!this.form.warehouseType) {
+              this.error = "璇峰厛閫夋嫨浠撳簱";
+            } else if (!this.form.locationType) {
+              this.error = "璇峰厛閫夋嫨浠撳簱鍖哄煙";
+            } else {
+              this.error = "璇锋鏌ヨ〃鍗曞~鍐欐槸鍚︽纭�";
+            }
+            resolve(false);
+          }
+        });
+      });
+    },
+
+    focusTrayInput() {
+      if (this.$refs.trayInput && this.$refs.trayInput.$el) {
+        const inputEl = this.$refs.trayInput.$el.querySelector("input");
+        if (inputEl) {
+          inputEl.focus();
+          this.currentFocus = "tray";
+          this.scanTarget = "tray";
+          inputEl.select();
+        }
+      }
+    },
+
+    focusBarcodeInput() {
+      if (this.$refs.barcodeInput && this.$refs.barcodeInput.$el) {
+        const inputEl = this.$refs.barcodeInput.$el.querySelector("input");
+        if (inputEl) {
+          inputEl.focus();
+          this.currentFocus = "material";
+          this.scanTarget = "material";
+          inputEl.select();
+        }
+      }
+    },
+
     resetData() {
-      console.log('閲嶇疆寮规鏁版嵁');
-      this.trayBarcode = '';
-      this.barcode = '';
+      this.palletGroupedBarcodes = {};
+      this.isSubmitting = false;
+      this.trayBarcode = "";
+      this.barcode = "";
       this.materials = [];
+      this.unpalletBarcodes = [];
+      this.unpalletMaterials = [];
       this.loading = false;
-      this.error = '';
-      this.scanCode = '';
+      this.error = "";
+      this.scanCode = "";
       this.lastKeyTime = null;
       this.isManualInput = false;
       this.isScanning = false;
-      this.currentFocus = 'tray';
-      this.scanTarget = 'tray';
+      this.currentFocus = "warehouse";
+      this.scanTarget = "tray";
       this.clearAllTimers();
+      this.totalStockSum = 0;
+      this.totalStockCount = 0;
+      this.sumLoading = false;
+      this.sumError = "";
+      this.form = {
+        warehouseType: null,
+        locationType: null,
+      };
+      this.warehouseTypes = [];
+      this.locationTypes = [];
+
+      this.$nextTick(() => {
+        if (this.$refs.locationForm) {
+          this.$refs.locationForm.clearValidate();
+        }
+      });
     },
-    
-    // 娓呴櫎鎵�鏈夎鏃跺櫒
+
     clearAllTimers() {
       if (this.manualInputTimer) {
         clearTimeout(this.manualInputTimer);
@@ -311,488 +909,652 @@
         this.scanTimer = null;
       }
     },
-    
-    // 寮规鎵撳紑鏃堕噸缃暟鎹�
-    handleDialogOpen() {
-      console.log('寮规鎵撳紑锛岄噸缃暟鎹�');
-      this.resetData();
-      // 浣跨敤setTimeout纭繚DOM瀹屽叏娓叉煋鍚庡啀鑱氱劍
-      this.$nextTick(() => {
-        setTimeout(() => {
-          this.focusTrayInput();
-        }, 300);
-      });
-    },
-    
-    // 寮规鍏抽棴鏃堕噸缃暟鎹�
+
     handleDialogClose() {
-      console.log('寮规鍏抽棴锛岄噸缃暟鎹�');
+      // 鍏堢Щ闄ら敭鐩樹簨浠剁洃鍚�
+      this.removeKeyPressListener();
+      this.show = false;
       this.resetData();
     },
-    
-    // 鍙栨秷鎸夐挳
-    handleCancel() {
-      this.palletVisible = false;
-    },
-    
+
     // 纭鎸夐挳
     handleConfirm() {
-      if (this.materials.length === 0) {
-        this.$message.warning('璇疯嚦灏戞坊鍔犱竴涓墿鏂�');
-        return;
-      }
-      
-      if (!this.trayBarcode) {
-        this.$message.warning('璇疯緭鍏ユ墭鐩樻潯鐮�');
-        return;
-      }
-      
-      const result = {
-        trayBarcode: this.trayBarcode,
-        materials: this.materials,
-        docNo: this.docNo
-      };
-      
-      // 瑙﹀彂鐖剁粍浠剁殑 back-success 浜嬩欢
-      this.$emit('back-success', result);
-      this.palletVisible = false;
+      this.validateForm().then((valid) => {
+        if (!valid) return;
+
+        if (this.materials.length === 0) {
+          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,
+        };
+
+        this.$emit("back-success", result);
+        this.palletVisible = false;
+      });
     },
-        // 鑱氱劍鍒版墭鐩樿緭鍏ユ
-        focusTrayInput() {
-          if (this.$refs.trayInput && this.$refs.trayInput.$el) {
-            const inputEl = this.$refs.trayInput.$el.querySelector('input');
-            if (inputEl) {
-              inputEl.focus();
-              this.currentFocus = 'tray';
-              this.scanTarget = 'tray';
-            }
-          }
-        },
-        
-        // 鑱氱劍鍒扮墿鏂欒緭鍏ユ
-        focusBarcodeInput() {
-          if (this.$refs.barcodeInput && this.$refs.barcodeInput.$el) {
-            const inputEl = this.$refs.barcodeInput.$el.querySelector('input');
-            if (inputEl) {
-              inputEl.focus();
-              this.currentFocus = 'material';
-              this.scanTarget = 'material';
-            }
-          }
-        },
-        
-        // 澶勭悊鎵樼洏杈撳叆
-        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);
-        },
-        
-        // 澶勭悊鎵樼洏鏉$爜鎻愪氦
-        handleTraySubmit() {
-          const currentTrayBarcode = this.trayBarcode.trim();
-          
-          if (!currentTrayBarcode) {
-            this.error = '璇疯緭鍏ユ垨鎵弿鎵樼洏鏉$爜';
-            return;
-          }
 
-          this.error = '';
-          
-          // 璁剧疆鎵樼洏鏉$爜鍚庯紝鑷姩鑱氱劍鍒扮墿鏂欒緭鍏ユ
-          this.focusBarcodeInput();
-          
-          this.$message({
-            message: `鎵樼洏鏉$爜宸茶缃�: ${currentTrayBarcode}`,
-            type: 'success',
-            duration: 2000
-          });
-        },
+    handleTrayInput() {
+      this.isManualInput = true;
+      this.isScanning = false;
+
+       if (this.trayBarcode) {
+        this.trayBarcode = this.trayBarcode.replace(/\s+/g, "");
+      }
+
+      if (this.manualInputTimer) {
+        clearTimeout(this.manualInputTimer);
+      }
+
+      this.manualInputTimer = setTimeout(() => {
+        this.isManualInput = false;
+      }, 1000);
+    },
+
+    handleBarcodeInput() {
+      this.isManualInput = true;
+      this.isScanning = false;
+
+      if (this.barcode) {
+        this.barcode = this.barcode.replace(/\s+/g, "");
+      }
+      
+      if (this.manualInputTimer) {
+        clearTimeout(this.manualInputTimer);
+      }
+
+      this.manualInputTimer = setTimeout(() => {
+        this.isManualInput = false;
+      }, 1000);
+    },
+
+    // 澶勭悊鎵樼洏鏉$爜鎻愪氦
+    handleTraySubmit() {
+      this.barcode = "";
+      this.materials = [];
+      this.error = "";
+
+      if (!this.form.warehouseType) {
+        this.error = "璇峰厛閫夋嫨浠撳簱";
+        return;
+      }
+      if (!this.form.locationType) {
+        this.error = "璇峰厛閫夋嫨浠撳簱鍖哄煙";
+        return;
+      }
+
+      this.validateForm().then((valid) => {
+        if (!valid) return;
+
+        let currentTrayBarcode = (this.trayBarcode || "").replace(/\s+/g, "").trim();
         
-        // 娓呴櫎鎵樼洏
-        clearTray() {
-          this.trayBarcode = '';
-          this.materials = [];
+        this.trayBarcode = currentTrayBarcode;
+
+        if (!currentTrayBarcode) {
+          this.error = "璇疯緭鍏ユ垨鎵弿鎵樼洏鏉$爜";
+          return;
+        }
+
+        this.error = "";
+
+        if (!this.trayBarcodeReg.test(currentTrayBarcode)) {
+          this.$message("鎵樼洏鍙锋牸寮忛敊璇�");
           this.focusTrayInput();
-          this.$message({
-            message: '鎵樼洏鏉$爜宸叉竻闄�',
-            type: 'info',
-            duration: 2000
-          });
-        },
-        
-        // 娓呯┖鎵樼洏杈撳叆
-        handleTrayClear() {
-          this.error = '';
-        },
-        
-        // 娓呯┖杈撳叆
-        handleClear() {
-          this.error = '';
-          this.scanCode = '';
-          this.isManualInput = false;
-          this.isScanning = false;
-        },
-        
-        // 澶勭悊鐗╂枡鏉$爜鎻愪氦
-        async handleBarcodeSubmit() {
-          const currentBarcode = this.barcode.trim();
-          
-          if (!this.trayBarcode) {
-            this.error = '璇峰厛杈撳叆鎵樼洏鏉$爜';
-            this.focusTrayInput();
-            return;
-          }
-          
-          if (!currentBarcode) {
-            this.error = '璇疯緭鍏ユ垨鎵弿鐗╂枡鏉$爜';
+          return;
+        }
+
+        this.focusBarcodeInput();
+        this.$message.success(`鎵樼洏鏉$爜宸茶缃�: ${currentTrayBarcode}`);
+      });
+    },
+
+    clearTray() {
+      this.trayBarcode = "";
+      this.materials = [];
+      this.focusTrayInput();
+      this.$message({
+        message: "鎵樼洏鏉$爜宸叉竻闄�",
+        type: "info",
+        duration: 2000,
+      });
+    },
+
+    handleTrayClear() {
+      this.error = "";
+    },
+
+    handleClear() {
+      this.error = "";
+      this.scanCode = "";
+      this.isManualInput = false;
+      this.isScanning = false;
+    },
+
+    // 澶勭悊鐗╂枡鏉$爜鎻愪氦
+    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 = "";
+        this.focusBarcodeInput();
+        this.playErrorAudio();
+        return;
+      }
+
+      this.isSubmitting = true;
+
+      this.validateForm()
+        .then((valid) => {
+          if (!valid) {
+            this.isSubmitting = false;
             return;
           }
 
-          this.error = '';
+          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;
 
-          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
-              });
-            } else {
-
-                materialData.forEach(item => {
-    
-          // 濡傛灉涓嶅瓨鍦紝娣诲姞鏂扮墿鏂�
-          this.materials.push({
-            ...item, 
-             trayCode: this.trayBarcode,
-               scanTime: this.formatTime(new Date())
-          });
-        });
-            
-        
- 
-              
-              this.$message({
-                message: `鎴愬姛娣诲姞鏉$爜: ${currentBarcode}`,
-                type: 'success',
-                duration: 2000
-              });
-         
-            
-            // 娓呯┖鐗╂枡杈撳叆妗嗗苟淇濇寔鑱氱劍
-            this.barcode = '';
-            this.scanCode = ''; // 娓呯┖鎵爜缂撳瓨
-            this.isScanning = false;
-            
-            setTimeout(() => {
-              this.focusBarcodeInput();
-            }, 100);
-          }
-          } catch (err) {
-            this.error = err.message || '鏌ヨ鏉$爜淇℃伅澶辫触锛岃閲嶈瘯';
-          } finally {
-            this.loading = false;
-          }
-        },
-        
-        // API璇锋眰 - 鏇挎崲涓哄疄闄呯殑API璋冪敤
-      async  fetchMaterialData(barcode) {
-         try {
-        const response = await http.post('/api/InboundOrder/BarcodeMaterielGroup', 
-           {
+          console.log("缁勭洏璇锋眰鍙傛暟:", {
             palletCode: this.trayBarcode,
-            orderNo: this.docNo,
-            barcodes: barcode
-          } 
-        );
-        
-      
-        let materialData;
-        
-        if (typeof response.data === 'string') {
-      
-          try {
-            materialData = JSON.parse(response.data);
-          } catch (e) {
-        
-          }
-        } else {
-          // 濡傛灉杩斿洖鐨勬槸JSON瀵硅薄锛岀洿鎺ヤ娇鐢�
-          materialData = response.data;
-        }
- if(!response.status){
-   this.error = response.message || '鏌ヨ鏉$爜淇℃伅澶辫触锛岃閲嶈瘯';
- }
-        // 纭繚杩斿洖鐨勬暟鎹寘鍚墍鏈夊繀闇�鐨勫瓧娈�
-        return  materialData;
-        
-      } catch (error) {
-        console.error('API璋冪敤澶辫触:', error);
-        
- 
-      }
-        },
-        
-        // 澶勭悊鎵爜鏋緭鍏�
-        handleKeyPress(event) {
-          // 濡傛灉鏄墜鍔ㄨ緭鍏ユā寮忥紝涓嶅鐞嗘壂鐮佹灙閫昏緫
-          if (this.isManualInput) {
+            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;
           }
-          
-          const key = event.key;
-          const currentTime = new Date().getTime();
-          
-          // 蹇界暐鐩存帴鎸変笅鐨勫洖杞﹂敭锛堢敱handleBarcodeSubmit澶勭悊锛�
-          if (key === 'Enter') {
-            if (this.scanCode.length > 0) {
-              // 闃绘榛樿鍥炶溅琛屼负锛岄伩鍏嶈〃鍗曟彁浜�
-              event.preventDefault();
-              
-              // 鎵爜瀹屾垚锛岃嚜鍔ㄨЕ鍙戞煡璇�
-              this.isScanning = false;
-              
-              // 鏍规嵁褰撳墠鎵爜鐩爣璁剧疆鐩稿簲鐨勮緭鍏ユ鍊�
-              if (this.scanTarget === 'tray') {
-                this.trayBarcode = this.scanCode;
-                this.handleTraySubmit();
-              } else if (this.scanTarget === 'material') {
-                this.barcode = this.scanCode;
-                this.handleBarcodeSubmit();
-              }
+
+          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璇锋眰
+    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);
+              this.playErrorAudio(); // 瑙f瀽澶辫触鎾斁閿欒闊�
+              throw new Error("鍝嶅簲鏁版嵁鏍煎紡閿欒");
             }
-            this.scanCode = '';
+          } else {
+            materialData = response.data;
+          }
+
+          if (!response.status) {
+            this.error = response.message || "鏌ヨ鏉$爜淇℃伅澶辫触锛岃閲嶈瘯";
+            this.playErrorAudio(); // 鎺ュ彛杩斿洖澶辫触鎾斁閿欒闊�
+            return [];
+          }
+
+          this.playSuccessAudio(); // 鎺ュ彛杩斿洖鎴愬姛鎾斁鎴愬姛闊�
+          return materialData || [];
+        })
+        .catch((error) => {
+          console.error("API璋冪敤澶辫触:", error);
+          this.$message.error("鎺ュ彛璇锋眰澶辫触锛岃鑱旂郴绠$悊鍛�");
+          this.playErrorAudio(); // 璇锋眰寮傚父鎾斁閿欒闊�
+          throw error;
+        });
+    },
+
+    // 澶勭悊鎵爜鏋緭鍏�
+    handleKeyPress(event) {
+      // 妫�鏌ュ脊绐楁槸鍚︽樉绀�
+      if (!this.show || this.isDialogClosing) {
+        return;
+      }
+
+      if (this.isManualInput || this.isSubmitting) {
+        return;
+      }
+
+      const key = event.key;
+      const currentTime = new Date().getTime();
+
+      if (key === "Enter") {
+        event.preventDefault();
+        if (this.scanCode.length > 0) {
+          if (this.scanTarget === "material" && !this.trayBarcode) {
+            this.$message.warning("璇峰厛璁剧疆鎵樼洏鏉$爜");
+            this.scanCode = "";
             this.lastKeyTime = null;
             return;
           }
-          
-          // 鏋勫缓鎵爜鍐呭锛堝揩閫熻繛缁緭鍏ヨ涓烘壂鐮侊級
-          if (this.lastKeyTime && currentTime - this.lastKeyTime < 50) {
-            this.scanCode += key;
-            this.isScanning = true;
-          } else {
-            this.scanCode = key;
-            this.isScanning = true;
+
+          this.isScanning = false;
+
+          if (this.scanTarget === "tray") {
+            this.trayBarcode = this.scanCode;
+            this.handleTraySubmit();
+          } else if (this.scanTarget === "material") {
+            this.barcode = this.scanCode;
+            this.handleBarcodeSubmit();
           }
-          
-          // 璁剧疆璁℃椂鍣紝濡傛灉涓�娈垫椂闂村唴娌℃湁杈撳叆锛屽垯閲嶇疆鎵弿鐘舵��
-          if (this.scanTimer) {
-            clearTimeout(this.scanTimer);
-          }
-          this.scanTimer = setTimeout(() => {
-            this.isScanning = false;
-          }, 100);
-          
-          this.lastKeyTime = currentTime;
-        },
-        
-        // 鍒犻櫎鐗╂枡
-        removeMaterial(index) {
-          this.$confirm('纭畾瑕佸垹闄よ繖鏉$墿鏂欒褰曞悧?', '鎻愮ず', {
-            confirmButtonText: '纭畾',
-            cancelButtonText: '鍙栨秷',
-            type: 'warning'
-          }).then(() => {
-            this.materials.splice(index, 1);
-            this.$message({
-              type: 'success',
-              message: '鍒犻櫎鎴愬姛!'
-            });
-          }).catch(() => {
-            // 鍙栨秷鍒犻櫎
-          });
-        },
-        
-        // 娓呯┖鎵�鏈夌墿鏂�
-        clearAllMaterials() {
-          if (this.materials.length === 0) return;
-          
-          this.$confirm('纭畾瑕佹竻绌烘墍鏈夌墿鏂欒褰曞悧?', '鎻愮ず', {
-            confirmButtonText: '纭畾',
-            cancelButtonText: '鍙栨秷',
-            type: 'warning'
-          }).then(() => {
-            this.materials = [];
-            this.$message({
-              type: 'success',
-              message: '宸叉竻绌烘墍鏈夎褰�!'
-            });
-          }).catch(() => {
-            // 鍙栨秷娓呯┖
-          });
-        },
-        
-        // 鏍煎紡鍖栨椂闂�
-        formatTime(date) {
-          const year = date.getFullYear();
-          const month = String(date.getMonth() + 1).padStart(2, '0');
-          const day = String(date.getDate()).padStart(2, '0');
-          const hours = String(date.getHours()).padStart(2, '0');
-          const minutes = String(date.getMinutes()).padStart(2, '0');
-          const seconds = String(date.getSeconds()).padStart(2, '0');
-          
-          return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
         }
+        this.scanCode = "";
+        this.lastKeyTime = null;
+        return;
       }
-}
+
+      if (this.lastKeyTime && currentTime - this.lastKeyTime < 50) {
+        this.scanCode += key;
+        this.isScanning = true;
+      } else {
+        this.scanCode = key;
+        this.isScanning = true;
+      }
+
+      if (this.scanTimer) {
+        clearTimeout(this.scanTimer);
+      }
+      this.scanTimer = setTimeout(() => {
+        this.isScanning = false;
+      }, 100);
+
+      this.lastKeyTime = currentTime;
+    },
+
+    // 鏍煎紡鍖栨椂闂�
+    formatTime(date) {
+      const year = date.getFullYear();
+      const month = String(date.getMonth() + 1).padStart(2, "0");
+      const day = String(date.getDate()).padStart(2, "0");
+      const hours = String(date.getHours()).padStart(2, "0");
+      const minutes = String(date.getMinutes()).padStart(2, "0");
+      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 = "";
+      this.fetchLocationByWarehouse(this.form.warehouseType);
+    },
+
+    // 鍖哄煙鍒囨崲浜嬩欢
+    handleLocationChange() {
+      this.trayBarcode = "";
+      this.barcode = "";
+      this.materials = [];
+      this.error = "";
+    },
+  },
+};
 </script>
 
 <style scoped>
-    .barcode-scanner-container {
-      max-width: 1200px;
-      margin: 0 auto;
-      padding: 20px;
-    }
-    .page-title {
-      text-align: center;
-      margin-bottom: 30px;
-    }
-    .input-section {
-      margin-bottom: 30px;
-    }
-    .scan-status {
-      float: right;
-      font-size: 12px;
-      color: #67C23A;
-    }
-    .scan-indicator {
-      display: inline-block;
-      width: 10px;
-      height: 10px;
-      border-radius: 50%;
-      background-color: #67C23A;
-      margin-right: 5px;
-      animation: pulse 1.5s infinite;
-    }
-    @keyframes pulse {
-      0% { opacity: 1; }
-      50% { opacity: 0.4; }
-      100% { opacity: 1; }
-    }
-    .input-wrapper {
-      position: relative;
-      margin-bottom: 15px;
-    }
-    .input-tips {
-      margin-top: 10px;
-      font-size: 12px;
-      color: #909399;
-    }
-    .loading {
-      text-align: center;
-      margin: 20px 0;
-    }
-    .loading p {
-      margin-top: 10px;
-      color: #409EFF;
-    }
-    .error-message {
-      margin-bottom: 20px;
-    }
-    .material-list {
-      margin-top: 30px;
-    }
-    .list-actions {
-      float: right;
-    }
-    .clear-all-btn {
-      margin-left: 10px;
-    }
-    .empty-state {
-      text-align: center;
-      padding: 40px 0;
-      color: #909399;
-    }
-    .empty-state i {
-      font-size: 48px;
-      margin-bottom: 10px;
-    }
-    .material-code {
-      font-family: 'Courier New', monospace;
-      font-weight: bold;
-      color: #409EFF;
-    }
-    .tray-info {
-      background: #f0f9ff;
-      padding: 10px 15px;
-      border-radius: 4px;
-      margin-bottom: 15px;
-      border-left: 4px solid #409EFF;
-    }
-    .debug-info {
-      background: #f5f7fa;
-      padding: 10px;
-      border-radius: 4px;
-      margin-top: 10px;
-      font-size: 12px;
-      color: #909399;
-    }
-    .small-button {
-      padding: 7px 9px;
-      font-size: 12px;
-    }
+.barcode-scanner-container {
+  max-width: 1200px;
+  margin: 0 auto;
+  padding: 10px;
+  display: flex;
+  flex-direction: column;
+  height: 100%;
+  gap: 8px;
+}
+
+/* 绱у噾甯冨眬鏍峰紡 */
+.compact {
+  margin-bottom: 0;
+}
+
+.compact-form {
+  margin-bottom: 0;
+}
+
+.compact-item {
+  margin-bottom: 0;
+}
+
+.compact-card {
+  margin-bottom: 0;
+}
+
+.compact-card >>> .el-card__body {
+  padding: 12px;
+}
+
+.compact-header {
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  padding: 0 !important;
+}
+
+.compact-header >>> .el-card__header {
+  padding: 8px 12px;
+}
+
+.compact-input {
+  margin: 8px 0;
+}
+
+.compact-tips {
+  margin-top: 8px;
+  font-size: 11px;
+}
+
+/* 浠撳簱鍖哄煙閫夋嫨 - 绱у噾 */
+.location-section.compact {
+  margin-bottom: 8px;
+}
+
+.location-section.compact >>> .el-form-item {
+  margin-bottom: 0;
+}
+
+/* 鎵樼洏淇℃伅 - 绱у噾 */
+.tray-info.compact {
+  padding: 6px 10px;
+  margin-bottom: 8px;
+  font-size: 13px;
+}
+
+/* 鎵爜鍖哄煙 - 绱у噾 */
+.input-section.compact {
+  margin-bottom: 8px;
+  flex-shrink: 0;
+}
+
+/* 鐗╂枡鍒楄〃 - 鍥哄畾楂樺害甯︽粴鍔� */
+.material-list.compact {
+  flex: 1;
+  min-height: 0;
+  /* 閲嶈锛氬厑璁竑lex瀛愰」鏀剁缉 */
+  display: flex;
+  flex-direction: column;
+}
+
+.material-list.compact >>> .el-card {
+  display: flex;
+  flex-direction: column;
+  height: 100%;
+}
+
+.material-list.compact >>> .el-card__body {
+  flex: 1;
+  display: flex;
+  flex-direction: column;
+  padding: 0;
+  min-height: 0;
+}
+
+.table-container {
+  flex: 1;
+  min-height: 0;
+  overflow: hidden;
+}
+
+.material-list.compact >>> .el-table {
+  flex: 1;
+}
+
+.material-list.compact >>> .el-table__body-wrapper {
+  overflow-y: auto;
+}
+
+/* 绱у噾鐨勭┖鐘舵�� */
+.empty-state.compact {
+  padding: 20px 0;
+  flex: 1;
+  display: flex;
+  flex-direction: column;
+  justify-content: center;
+  align-items: center;
+}
+
+.empty-state.compact i {
+  font-size: 36px;
+  margin-bottom: 8px;
+}
+
+.empty-state.compact p {
+  font-size: 13px;
+}
+
+/* 鍏朵粬鍘熸湁鏍峰紡璋冩暣 */
+.page-title {
+  text-align: center;
+  margin-bottom: 15px;
+}
+
+.scan-status {
+  font-size: 12px;
+  color: #67c23a;
+}
+
+.scan-indicator {
+  display: inline-block;
+  width: 8px;
+  height: 8px;
+  border-radius: 50%;
+  background-color: #67c23a;
+  margin-right: 5px;
+  animation: pulse 1.5s infinite;
+}
+
+@keyframes pulse {
+  0% {
+    opacity: 1;
+  }
+
+  50% {
+    opacity: 0.4;
+  }
+
+  100% {
+    opacity: 1;
+  }
+}
+
+.input-wrapper {
+  position: relative;
+}
+
+.input-tips {
+  margin-top: 6px;
+  color: #909399;
+}
+
+.warning-text {
+  color: #e6a23c;
+  font-weight: bold;
+}
+
+.loading.compact {
+  text-align: center;
+  margin: 10px 0;
+  padding: 5px;
+}
+
+.loading.compact p {
+  margin-top: 5px;
+  color: #409eff;
+  font-size: 12px;
+}
+
+.error-message.compact {
+  margin: 5px 0;
+}
+
+.error-message.compact >>> .el-alert {
+  padding: 6px 12px;
+}
+
+.list-actions {
+  display: flex;
+  align-items: center;
+  gap: 4px;
+}
+
+.list-actions >>> .el-tag {
+  height: 24px;
+  line-height: 22px;
+  padding: 0 6px;
+}
+
+.clear-all-btn {
+  margin-left: 8px;
+}
+
+.material-code {
+  font-family: "Courier New", monospace;
+  font-weight: bold;
+  color: #409eff;
+}
+
+.location-info {
+  color: #606266;
+  font-weight: normal;
+}
+
+.debug-info {
+  background: #f5f7fa;
+  padding: 8px;
+  border-radius: 4px;
+  margin-top: 8px;
+  font-size: 11px;
+  color: #909399;
+}
+
+.small-button {
+  padding: 6px 8px;
+  font-size: 11px;
+}
+
+/* 杈撳叆妗嗙粍鏍峰紡璋冩暣 */
 .custom-input-group {
   display: flex;
   align-items: center;
   width: 100%;
-  margin: 20px 0;
-  border: 1px solid #DCDFE6;
+  margin: 8px 0;
+  border: 1px solid #dcdfe6;
   border-radius: 4px;
   overflow: hidden;
   background: #fff;
 }
 
 .input-label {
-  padding: 0 15px;
-  background: #F5F7FA;
-  border-right: 1px solid #DCDFE6;
+  padding: 0 12px;
+  background: #f5f7fa;
+  border-right: 1px solid #dcdfe6;
   color: #606266;
-  font-size: 14px;
+  font-size: 13px;
   white-space: nowrap;
-  height: 40px;
-  line-height: 40px;
+  height: 36px;
+  line-height: 36px;
   flex-shrink: 0;
+  min-width: 70px;
+  text-align: center;
 }
 
 .input-container {
@@ -805,12 +1567,68 @@
   flex: 1;
 }
 
-.custom-input ::v-deep .el-input__inner {
+.custom-input >>> .el-input__inner {
   border: none;
   border-radius: 0;
-  height: 40px;
-  line-height: 40px;
+  height: 36px;
+  line-height: 36px;
+  font-size: 13px;
 }
 
- 
+/* 鍝嶅簲寮忚皟鏁� */
+@media (max-width: 768px) {
+  .barcode-scanner-container {
+    padding: 5px;
+  }
+
+  .custom-input-group {
+    flex-direction: column;
+    border: none;
+  }
+
+  .input-label {
+    width: 100%;
+    border-right: none;
+    border-bottom: 1px solid #dcdfe6;
+    margin-bottom: 5px;
+  }
+
+  .input-container {
+    width: 100%;
+    border: 1px solid #dcdfe6;
+    border-radius: 4px;
+  }
+
+  .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);
+    }
+  }
+}
 </style>
\ No newline at end of file

--
Gitblit v1.9.3