Bladeren bron

fix(productionPlan): 计划分解BOM勾选全量回显到计划列表并回填BOM绑定工艺路线

lihaiting 5 dagen geleden
bovenliggende
commit
4e283df6c6
1 gewijzigde bestanden met toevoegingen van 37 en 18 verwijderingen
  1. 37 18
      src/views/productionPlan/components/disassemblePlanPop.vue

+ 37 - 18
src/views/productionPlan/components/disassemblePlanPop.vue

@@ -59,6 +59,7 @@
         <!--      @update:selection="handleSelectionChange" -->
         <ele-pro-table
           ref="table"
+          row-key="rowKey"
           :needPage="false"
           :columns="columns"
           :datasource="bomList"
@@ -174,7 +175,7 @@
 <script>
   import { deepClone } from '@/utils';
   import { getBom, batchSave } from '@/api/productionPlan/index.js';
-  import { routeList } from '@/api/saleOrder';
+  import { routeList, bomRoutingList } from '@/api/saleOrder';
   import EquipmentDialog from './EquipmentDialog.vue';
   import { start } from 'nprogress';
 
@@ -390,14 +391,14 @@
         // 说明是全选
         if (selection.length > 0) {
           this.bomList.forEach((el) => {
-            this.bomListMap[el.id] = true;
+            this.bomListMap[el.rowKey] = true;
             this.handleSelectionChange(el);
           });
         } else {
           // 取消全选
           this.bomList.forEach((el) => {
-            delete this.bomListMap[el.id];
-            this.deleteJhData(el.id);
+            delete this.bomListMap[el.rowKey];
+            this.deleteJhData(el.rowKey);
           });
         }
       },
@@ -405,26 +406,27 @@
       // 勾选 取消勾选
       select(selection, row) {
         // 存在说明已勾选
-        if (this.bomListMap[row.id]) {
-          delete this.bomListMap[row.id];
-          this.deleteJhData(row.id);
+        if (this.bomListMap[row.rowKey]) {
+          delete this.bomListMap[row.rowKey];
+          this.deleteJhData(row.rowKey);
         } else {
-          this.bomListMap[row.id] = true;
+          this.bomListMap[row.rowKey] = true;
           this.handleSelectionChange(row);
         }
       },
       // 计划列表数据 BOM信息删除
-      deleteJhData(id) {
-        let index = this.jhList.findIndex((el) => el.id === id);
+      deleteJhData(rowKey) {
+        let index = this.jhList.findIndex((el) => el.rowKey === rowKey);
         if (index != -1) {
           this.jhList.splice(index, 1);
         }
       },
       // 计划列表数据 BOM信息添加
       handleSelectionChange(m) {
+        // 后端 id 可能重复/为空,勾选联动统一用前端生成的 rowKey 去重
         for (let i = 0; i < this.jhList.length; i++) {
           let item = this.jhList[i];
-          if (item.id == m.id) {
+          if (m.rowKey != null && item.rowKey === m.rowKey) {
             return;
           }
         }
@@ -438,6 +440,7 @@
         }
         let _num = this.getRequiredFormingNum(m);
         let data = {
+          rowKey: m.rowKey,
           id: m.id,
           categoryId: m.categoryId,
           productCode: m.productCode,
@@ -456,6 +459,16 @@
         };
         this.jhList.push(data);
         // this.jhList = _arr;
+        // 回填 BOM 绑定的工艺路线(默认取第一条,与临时计划选择BOM后的逻辑一致)
+        if (m.id != null) {
+          bomRoutingList(m.id).then((res) => {
+            const arr = res || [];
+            if (arr.length > 0 && !data.produceRoutingId) {
+              this.$set(data, 'produceRoutingId', arr[0].id);
+              this.$set(data, 'produceRoutingName', arr[0].name);
+            }
+          });
+        }
       },
       // 数量正则
       handleQuantityInput(e, row) {
@@ -506,14 +519,14 @@
       // 删除计划信息
       removeRow(row, index) {
         // 如果删除的是当前列表BOM信息的数据 就将它的勾选去掉
-        let data = this.bomList.find((el) => el.id == row.id);
-        if (data && data.id) {
+        let data = this.bomList.find((el) => el.rowKey == row.rowKey);
+        if (data) {
           this.$refs.table.toggleRowSelection(data);
         }
 
         // 删除对应的存储数据
-        if (this.bomListMap[row.id]) {
-          delete this.bomListMap[row.id];
+        if (this.bomListMap[row.rowKey]) {
+          delete this.bomListMap[row.rowKey];
         }
         this.jhList.splice(index, 1);
       },
@@ -545,7 +558,11 @@
           size: -1
         };
         getBom(params).then((res) => {
-          this.bomList = res?.bomList || [];
+          // 后端返回的 id 可能重复/为空,前端生成唯一 rowKey 供勾选联动使用
+          this.bomList = (res?.bomList || []).map((el, index) => ({
+            ...el,
+            rowKey: `${this.formData.produceType || ''}_${el.id || ''}_${index}`
+          }));
           let ids = Object.keys(this.bomListMap);
           if (ids.length > 0) {
             this.checkBoxData();
@@ -565,7 +582,7 @@
             return;
           }
           this.bomList.forEach((row) => {
-            if (this.bomListMap[row.id]) {
+            if (this.bomListMap[row.rowKey]) {
               this.$refs.table.toggleRowSelection(row);
             }
           });
@@ -654,8 +671,10 @@
           return this.$message.warning('请填写正确的生产数量');
         }
 
+        // rowKey 仅用于前端勾选联动,提交给后端前去掉
+        const addPOList = this.jhList.map(({ rowKey, ...rest }) => rest);
         let param = {
-          addPOList: this.jhList,
+          addPOList: addPOList,
           produceType: this.formData.produceType,
           id: this.formData.id
         };