Kaynağa Gözat

fix(BOMmanage): 修复工序多归属工艺路线时的分组与工步加载

xieyong 3 gün önce
ebeveyn
işleme
e47413a2d9

+ 53 - 17
src/views/material/BOMmanage/components/workmanship.vue

@@ -683,8 +683,9 @@
           });
           return result;
         }
-        // 通过路由查询工序,建立 sourceTaskId -> routingId 的映射
-        const taskRouteMap = {};
+        // 通过路由查询工序,建立 sourceTaskId -> Set<routingId> 的多归属映射
+        // 一条工序可以同时属于多条工艺路线,不能再用一对一赋值(会覆盖)
+        const taskRouteMap = Object.create(null);
         await Promise.all(
           routes.map(async (r) => {
             try {
@@ -702,7 +703,10 @@
                     ? detail.sourceTaskId
                     : it.sourceTaskId;
                 if (stid != null) {
-                  taskRouteMap[stid] = r.id;
+                  if (!taskRouteMap[stid]) {
+                    taskRouteMap[stid] = new Set();
+                  }
+                  taskRouteMap[stid].add(r.id);
                 }
               });
             } catch (e) {
@@ -714,22 +718,37 @@
         const groups = routes.map((r) => ({ route: r, processes: [] }));
         const ungrouped = [];
         dataList.forEach((item) => {
-          const routeId =
-            taskRouteMap[item.sourceTaskId] != null
-              ? taskRouteMap[item.sourceTaskId]
-              : item.routingId != null
-              ? item.routingId
-              : null;
-          const matchedGroup = routeId
-            ? groups.find((g) => g.route.id === routeId)
-            : null;
-          if (matchedGroup) {
-            item._routeId = matchedGroup.route.id;
-            matchedGroup.processes.push(item);
-          } else {
+          // 收集本工序归属的全部 routeId:优先用 sourceTaskId 查表,回退到工序自带的 routingId
+          const routeIds = new Set();
+          const mapped = taskRouteMap[item.sourceTaskId];
+          if (mapped instanceof Set) {
+            mapped.forEach((id) => routeIds.add(id));
+          }
+          if (routeIds.size === 0 && item.routingId != null) {
+            routeIds.add(item.routingId);
+          }
+          if (routeIds.size === 0) {
             item._routeId = UNGROUPED_ROUTE_ID;
             ungrouped.push(item);
+            return;
           }
+          // 多归属:浅克隆一份给每个归属路线,避免 _rowKey 冲突、且不污染原对象
+          // 浅克隆的嵌套字段(categoryParamStepList / produceList)继续共享引用,
+          // 由 fillStepLists 的 id 级缓存保证工步数据一致。
+          routeIds.forEach((routeId) => {
+            const matchedGroup = groups.find((g) => g.route.id === routeId);
+            if (!matchedGroup) {
+              item._routeId = UNGROUPED_ROUTE_ID;
+              ungrouped.push(item);
+              return;
+            }
+            const cloned = {
+              ...item,
+              _routeId: matchedGroup.route.id,
+              _rowKey: `${item._rowKey}__r${matchedGroup.route.id}`
+            };
+            matchedGroup.processes.push(cloned);
+          });
         });
         const result = [];
         groups.forEach((group, gIdx) => {
@@ -909,10 +928,27 @@
         if (!Array.isArray(dataList) || !dataList.length) {
           return dataList;
         }
+        // 多归属场景下,同 item.id 会被多个浅克隆 wrapper 引用;
+        // 用 id -> Promise 缓存确保同一工序只发起一次工步请求,所有 wrapper 拿到同一份结果。
+        const cache = new Map();
+        const ensureStepList = (item) => {
+          const key = item && item.id != null ? String(item.id) : null;
+          if (key == null) {
+            return Promise.resolve(
+              Array.isArray(item.categoryParamStepList)
+                ? item.categoryParamStepList
+                : []
+            );
+          }
+          if (!cache.has(key)) {
+            cache.set(key, this.loadStepList(item));
+          }
+          return cache.get(key);
+        };
         await Promise.all(
           dataList.map(async (item) => {
             try {
-              item.categoryParamStepList = await this.loadStepList(item);
+              item.categoryParamStepList = await ensureStepList(item);
             } catch (e) {
               console.log(e, 'get step list err');
               item.categoryParamStepList = Array.isArray(