Bläddra i källkod

fix(forecast-form): 改进物料导入的重复检查逻辑

yz 1 vecka sedan
förälder
incheckning
478b0b0fca
1 ändrade filer med 28 tillägg och 3 borttagningar
  1. 28 3
      src/components/forecast-form/forecast-form-mixin.js

+ 28 - 3
src/components/forecast-form/forecast-form-mixin.js

@@ -1163,7 +1163,7 @@ export default {
 
     /**
      * 导入所选物料到下方表格
-     * @description 仅在点击“导入物料”按钮后,将选择的物料行添加到表格,默认预测数量为 1
+     * @description 仅在点击"导入物料"按钮后,将选择的物料行添加到表格,默认预测数量为 1
      * @returns {void}
      * @this {ForecastFormMixinComponent & Vue}
      */
@@ -1179,13 +1179,30 @@ export default {
         this.$message.error('未找到所选物料数据,请重新选择')
         return
       }
-      // 防止重复导入(按 id 去重)
-      const exists = this.stockTableData.some(row => row.id === stock.id)
+      
+      // 防止重复导入 - 使用多个字段进行更全面的重复检查
+      const exists = this.stockTableData.some(row => {
+        // 优先使用 id 进行匹配
+        if (row.id && stock.id && row.id === stock.id) {
+          return true
+        }
+        // 使用 goodsId 进行匹配
+        if (row.goodsId && stock.goodsId && row.goodsId === stock.goodsId) {
+          return true
+        }
+        // 使用 code 进行匹配
+        if (row.code && stock.code && row.code === stock.code) {
+          return true
+        }
+        return false
+      })
+      
       if (exists) {
         this.$message.warning('该物料已在列表中')
         this.selectedStockId = null
         return
       }
+      
       // 添加到表格,默认预测数量为 1
       this.stockTableData.push({ ...stock, forecastQuantity: 1 })
       // 清空已选
@@ -1292,6 +1309,14 @@ export default {
         const stockList = (payload && payload.pjpfStockDescList) || []
         if (!Array.isArray(stockList) || stockList.length === 0) return
 
+        // 在编辑模式下,确保"导入物料"的选择器有数据可选
+        // 不修改现有表格数据,仅补齐选择来源
+        this.stockDescList = stockList
+        this.stockSelectOptions = stockList.map(item => ({
+          label: item.cname,
+          value: item.id
+        }))
+
         // 构建基于 goodsId 与 code 的索引映射
         /** @type {Map<string, string|undefined>} */
         const invByGoodsId = new Map()