From f38a383fee2a1484948d9c5a66078c31e0a5e43a Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 19 五月 2026 15:51:13 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_NEW_pro' into dev_NEW_pro

---
 src/views/productionManagement/processRoute/processRouteItem/index.vue |  100 ++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 85 insertions(+), 15 deletions(-)

diff --git a/src/views/productionManagement/processRoute/processRouteItem/index.vue b/src/views/productionManagement/processRoute/processRouteItem/index.vue
index 8abef17..92a2fa1 100644
--- a/src/views/productionManagement/processRoute/processRouteItem/index.vue
+++ b/src/views/productionManagement/processRoute/processRouteItem/index.vue
@@ -315,7 +315,7 @@
                                      :step="1"
                                      controls-position="right"
                                      style="width: 100%"
-                                     @change="handleUnitQuantityChange(row)"
+                                     @change="handleUnitQuantityChange"
                                      :disabled="!bomDataValue.isEdit || bomDataValue.dataList.some(item => (item).tempId === row.tempId)" />
                   </el-form-item>
                 </template>
@@ -333,7 +333,7 @@
                                      :step="1"
                                      controls-position="right"
                                      style="width: 100%"
-                                     :disabled="!bomDataValue.isEdit || bomDataValue.dataList.some(item => (item).tempId === row.tempId)" />
+                                     :disabled="true" />
                   </el-form-item>
                 </template>
               </el-table-column>
@@ -1089,6 +1089,53 @@
       }
     });
   };
+
+  const toQuantityNumber = value => {
+    const numberValue = Number(value);
+    if (!Number.isFinite(numberValue)) {
+      return 0;
+    }
+    return Number(numberValue.toFixed(2));
+  };
+
+  const syncDemandedQuantityTree = (items, parentDemandedQuantity = null) => {
+    items.forEach(item => {
+      if (parentDemandedQuantity !== null) {
+        item.demandedQuantity = toQuantityNumber(
+          parentDemandedQuantity * toQuantityNumber(item.unitQuantity)
+        );
+      }
+
+      if (Array.isArray(item.children) && item.children.length > 0) {
+        syncDemandedQuantityTree(
+          item.children,
+          toQuantityNumber(item.demandedQuantity)
+        );
+      }
+    });
+  };
+
+  const recalculateDemandedQuantities = () => {
+    if (pageType.value !== "order") {
+      return;
+    }
+
+    const rootDemandedQuantity = routeInfo.value.quantity;
+    if (
+      rootDemandedQuantity === undefined ||
+      rootDemandedQuantity === null ||
+      rootDemandedQuantity === ""
+    ) {
+      syncDemandedQuantityTree(bomDataValue.value.dataList);
+      return;
+    }
+
+    syncDemandedQuantityTree(
+      bomDataValue.value.dataList,
+      toQuantityNumber(rootDemandedQuantity)
+    );
+  };
+
   const processChange = value => {
     processOptions.value.forEach(item => {
       if (item.id == value) {
@@ -1099,9 +1146,36 @@
     });
   };
 
+  const findSiblings = (items, tempId) => {
+    if (!items || items.length === 0) return null;
+    // 妫�鏌ュ綋鍓嶅眰绾�
+    if (items.some(item => item.tempId === tempId)) {
+      return items;
+    }
+    // 閫掑綊鏌ユ壘瀛愮骇
+    for (const item of items) {
+      if (item.children && item.children.length > 0) {
+        const result = findSiblings(item.children, tempId);
+        if (result) return result;
+      }
+    }
+    return null;
+  };
+
   const handleBomProcessChange = (row, value) => {
     row.processId = value || "";
     syncProcessOperationFields(row);
+    
+    // 鍚屼竴灞傜骇鍙兘閫変竴鏍风殑宸ュ簭
+    const siblings = findSiblings(bomDataValue.value.dataList, row.tempId);
+    if (siblings && value) {
+      siblings.forEach(sibling => {
+        if (sibling.tempId !== row.tempId) {
+          sibling.processId = value;
+          syncProcessOperationFields(sibling);
+        }
+      });
+    }
   };
 
   const openBomDialog = tempId => {
@@ -1117,6 +1191,7 @@
       );
       bomDataValue.value.dataList = data || [];
       normalizeTreeData(bomDataValue.value.dataList);
+      recalculateDemandedQuantities();
     } catch (err) {
       console.error("鑾峰彇BOM鏁版嵁澶辫触锛�", err);
     }
@@ -1212,10 +1287,8 @@
     });
   };
 
-  const handleUnitQuantityChange = row => {
-    if (routeInfo.value.quantity && routeInfo.value.quantity !== 0) {
-      row.demandedQuantity = (row.unitQuantity || 0) * routeInfo.value.quantity;
-    }
+  const handleUnitQuantityChange = () => {
+    recalculateDemandedQuantities();
   };
 
   const addchildItem = (item, tempId) => {
@@ -1236,14 +1309,12 @@
           "",
         operationName: "",
         unitQuantity: 1,
-        demandedQuantity:
-          routeInfo.value.quantity && routeInfo.value.quantity !== 0
-            ? 1 * routeInfo.value.quantity
-            : 0,
+        demandedQuantity: 0,
         children: [],
         unit: "",
         tempId: new Date().getTime(),
       });
+      recalculateDemandedQuantities();
       return true;
     }
     if (item.children && item.children.length > 0) {
@@ -1275,14 +1346,12 @@
             "",
           operationName: "",
           unitQuantity: 1,
-          demandedQuantity:
-            routeInfo.value.quantity && routeInfo.value.quantity !== 0
-              ? 1 * routeInfo.value.quantity
-              : 0,
+          demandedQuantity: 0,
           unit: "",
           children: [],
           tempId: new Date().getTime(),
         });
+        recalculateDemandedQuantities();
         return;
       }
       addchildItem(item, tempId);
@@ -1350,6 +1419,7 @@
     console.log(bomDataValue.value.dataList, "bomDataValue.value.dataList");
 
     normalizeTreeData(bomDataValue.value.dataList);
+    recalculateDemandedQuantities();
 
     const valid = validateAllBom();
     if (valid) {
@@ -1649,4 +1719,4 @@
     line-height: 1.5;
     word-break: break-all;
   }
-</style>
+</style>
\ No newline at end of file

--
Gitblit v1.9.3