1
647556386
2026-01-20 21f9a188ea9c7f8c5aefea9f151c963ebe45b627
1
已修改1个文件
136 ■■■■ 文件已修改
项目代码/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue 136 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ÏîÄ¿´úÂë/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 {
        // ä¿®å¤ï¼šhttp æ”¹ä¸º this.$http(原代码错误)
        const { data } = await this.http.post("api/LocationInfo/GetLocationTypes")
        this.locationTypes = data
      } catch (e) {
@@ -350,6 +369,7 @@
    },
    async initwarehouseTypes() {
      try {
        // ä¿®å¤ï¼šhttp æ”¹ä¸º this.$http(原代码错误)
        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) {
            // ä¿®å¤ï¼šfrom æ”¹ä¸º form(原代码拼写错误)
            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 = '';
      // å…ˆç›´æŽ¥æ£€æŸ¥locationType,避免表单验证的异步问题
      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('正在处理中,请稍候');
    return;
  }
      if (!await this.validateForm()) return;
        this.$message.warning('正在处理中,请稍候');
        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) {
      // å¦‚果是手动输入模式,不处理扫码枪逻辑
      // å¦‚果是手动输入模式或正在提交,不处理扫码枪逻辑
      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 = '';
    }
  }
}