heshaofeng
2026-02-03 c18d2a118251c644f90dffa8cda1f9c8fb9baca1
ÏîÄ¿´úÂë/WIDESEA_WMSClient/src/extension/inbound/extend/AllcatedPallet.vue
@@ -175,7 +175,7 @@
import http from '@/api/http.js';
import VolBox from '@/components/basic/VolBox.vue';
// é˜²æŠ–函数保持不变
// é˜²æŠ–函数
function debounce(func, wait) {
  let timeout;
  return function () {
@@ -251,7 +251,11 @@
            trigger: 'change'
          }
        ]
      }
      },
      // æ–°å¢žï¼šé”®ç›˜äº‹ä»¶ç›‘听标记
      keyPressListenerAdded: false,
      isDialogClosing: false
    }
  },
@@ -272,6 +276,26 @@
  },
  
  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;
@@ -306,15 +330,34 @@
  },
  
  mounted() {
    document.addEventListener('keypress', this.handleKeyPress);
    // ä¸åœ¨mounted时添加监听,在弹窗打开时添加
  },
  
  beforeDestroy() {
    document.removeEventListener('keypress', this.handleKeyPress);
    // ç¡®ä¿ç»„件销毁时移除监听
    this.removeKeyPressListener();
    this.clearAllTimers();
  },
  
  methods: {
    // æ·»åŠ é”®ç›˜äº‹ä»¶ç›‘å¬
    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 = "";
@@ -322,6 +365,13 @@
      this.initLocationTypes();
      this.initwarehouseTypes();
      this.fetchUnpalletMaterialDetails();
      // å¼¹çª—打开时添加键盘事件监听
      this.$nextTick(() => {
        setTimeout(() => {
          this.addKeyPressListener();
        }, 100);
      });
    },
    
    validateLocationType(rule, value, callback) {
@@ -483,6 +533,9 @@
    },
    
    resetData() {
      // å…ˆç§»é™¤é”®ç›˜äº‹ä»¶ç›‘听
      this.removeKeyPressListener();
      this.palletGroupedBarcodes = {};
      this.isSubmitting = false;
      this.trayBarcode = '';
@@ -509,6 +562,8 @@
      };
      this.warehouseTypes = [];
      this.locationTypes = [];
      this.isDialogClosing = false;
      this.keyPressListenerAdded = false;
      
      this.$nextTick(() => {
        if (this.$refs.locationForm) {
@@ -529,6 +584,8 @@
    },
    
    handleDialogClose() {
      // å…ˆç§»é™¤é”®ç›˜äº‹ä»¶ç›‘听
      this.removeKeyPressListener();
      this.show = false;
      this.resetData();
    },
@@ -568,6 +625,10 @@
      this.isManualInput = true;
      this.isScanning = false;
      if (this.trayBarcode) {
        this.trayBarcode = this.trayBarcode.replace(/\s+/g, "");
      }
      if (this.manualInputTimer) {
        clearTimeout(this.manualInputTimer);
      }
@@ -581,6 +642,9 @@
      this.isManualInput = true;
      this.isScanning = false;
      if (this.barcode) {
        this.barcode = this.barcode.replace(/\s+/g, "");
      }
      if (this.manualInputTimer) {
        clearTimeout(this.manualInputTimer);
      }
@@ -609,7 +673,9 @@
        .then(valid => {
          if (!valid) return;
          
          const currentTrayBarcode = this.trayBarcode.trim();
          let currentTrayBarcode = (this.trayBarcode || "").replace(/\s+/g, "").trim();
         this.trayBarcode = currentTrayBarcode;
          if (!currentTrayBarcode) {
            this.error = '请输入或扫描托盘条码';
@@ -759,7 +825,7 @@
        });
    },
    // API请求
    // API请求 - æ³¨æ„è¿™é‡Œä¿®æ”¹äº†API地址为/AllGroupPallet
    fetchMaterialData(barcode) {
      return http.post('/api/Inbound/AllGroupPallet', {
        palletCode: this.trayBarcode,
@@ -797,6 +863,11 @@
    // å¤„理扫码枪输入
    handleKeyPress(event) {
      // æ£€æŸ¥å¼¹çª—是否显示
      if (!this.show || this.isDialogClosing) {
        return;
      }
      if (this.isManualInput || this.isSubmitting) {
        return;
      }