heshaofeng
2026-02-05 6dbcd7df8e116cb83dbbd34d0acd6508f9b99991
ÏîÄ¿´úÂë/WIDESEA_WMSClient/src/extension/check/extend/ReCheckGroupPallet.vue
@@ -19,8 +19,8 @@
      <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">
            <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>
@@ -74,7 +74,7 @@
              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">
                  :disabled="!form.locationType || !trayBarcode || !barcode || !form.warehouseType" size="medium">
                  {{ loading ? '查询中...' : '查询' }}
                </el-button>
              </template>
@@ -240,7 +240,11 @@
            trigger: 'change'
          }
        ]
      }
      },
      // æ–°å¢žï¼šé”®ç›˜äº‹ä»¶ç›‘听标记
      keyPressListenerAdded: false,
      isDialogClosing: false
    }
  },
@@ -256,7 +260,29 @@
      return location ? location.locationTypeDesc : ''
    }
  },
  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;
@@ -289,14 +315,36 @@
      }
    }
  },
  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 = "";
@@ -304,7 +352,15 @@
      this.initLocationTypes();
      this.initwarehouseTypes();
      this.fetchUnpalletMaterialDetails();
      // å¼¹çª—打开时添加键盘事件监听
      this.$nextTick(() => {
        setTimeout(() => {
          this.addKeyPressListener();
        }, 100);
      });
    },
    validateLocationType(rule, value, callback) {
      if (!this.form.warehouseType) {
        callback(new Error('请先选择仓库'));
@@ -338,6 +394,7 @@
        }));
      }
    },
    async initLocationTypes() {
      try {
        const { data } = await this.http.post("api/LocationInfo/GetLocationTypes")
@@ -346,6 +403,7 @@
        this.$message.error('获取区域类型失败')
      }
    },
    async initwarehouseTypes() {
      try {
        const { data } = await this.http.post("api/Warehouse/GetwarehouseTypes")
@@ -355,6 +413,33 @@
      }
    },
    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;
        });
    },
    async fetchStockStatistics(orderNo) {
      // å•据号为空时不查询
      if (!orderNo) {
@@ -394,7 +479,8 @@
            this.error = '';
            resolve(true);
          } else {
            if (!this.from.warehouseType) {
            // ä¿®å¤æ‹¼å†™é”™è¯¯ï¼šthis.from.warehouseType åº”该是 this.form.warehouseType
            if (!this.form.warehouseType) {
              this.error = '请先选择仓库';
            }
            else if (this.form.locationType === null || this.form.locationType === undefined || this.form.locationType === '') {
@@ -407,6 +493,7 @@
        });
      });
    },
    // èšç„¦åˆ°æ‰˜ç›˜è¾“入框
    focusTrayInput() {
      if (this.$refs.trayInput && this.$refs.trayInput.$el) {
@@ -432,8 +519,12 @@
        }
      }
    },
    // é‡ç½®æ‰€æœ‰æ•°æ®
    resetData() {
      // å…ˆç§»é™¤é”®ç›˜äº‹ä»¶ç›‘听
      this.removeKeyPressListener();
      this.trayBarcode = '';
      this.barcode = '';
      this.materials = [];
@@ -458,6 +549,9 @@
      }
      this.warehouseTypes = [];
      this.locationTypes = [];
      this.isDialogClosing = false;
      this.keyPressListenerAdded = false;
      // æ¸…除表单验证状态
      this.$nextTick(() => {
        if (this.$refs.locationForm) {
@@ -477,7 +571,10 @@
        this.scanTimer = null;
      }
    },
    handleDialogClose() {
      // å…ˆç§»é™¤é”®ç›˜äº‹ä»¶ç›‘听
      this.removeKeyPressListener();
      this.show = false;
      this.resetData();
    },
@@ -510,6 +607,7 @@
      this.$emit('back-success', result);
      this.palletVisible = false;
    },
    // å¤„理托盘输入
    handleTrayInput() {
      // æ ‡è®°ä¸ºæ‰‹åŠ¨è¾“å…¥æ¨¡å¼
@@ -715,6 +813,11 @@
    // å¤„理扫码枪输入
    handleKeyPress(event) {
      // æ£€æŸ¥å¼¹çª—是否显示
      if (!this.show || this.isDialogClosing) {
        return;
      }
      // å¦‚果是手动输入模式,不处理扫码枪逻辑
      if (this.isManualInput) {
        return;
@@ -776,6 +879,24 @@
      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 = '';
    }
  }
}