From 28c8ef8428f51b41e8f1e34a08bd83bf305bd0c0 Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期六, 16 五月 2026 14:48:01 +0800
Subject: [PATCH] feat(qualityManagement): 质量数量拆分出 合格数量以及不合格数量

---
 src/views/productionManagement/productStructure/Detail/index.vue |   64 ++++++++++++++++++++++++++++---
 1 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/src/views/productionManagement/productStructure/Detail/index.vue b/src/views/productionManagement/productStructure/Detail/index.vue
index 6fbe21b..a7f6b6b 100644
--- a/src/views/productionManagement/productStructure/Detail/index.vue
+++ b/src/views/productionManagement/productStructure/Detail/index.vue
@@ -86,6 +86,7 @@
                                      :step="1"
                                      controls-position="right"
                                      style="width: 100%"
+                                     @change="handleUnitQuantityChange"
                                      :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)" />
                   </el-form-item>
                 </template>
@@ -103,7 +104,7 @@
                                      :step="1"
                                      controls-position="right"
                                      style="width: 100%"
-                                     :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)" />
+                                     :disabled="true" />
                   </el-form-item>
                 </template>
               </el-table-column>
@@ -163,7 +164,10 @@
     reactive,
     ref,
   } from "vue";
-  import { queryList, addBomDetail } from "@/api/productionManagement/productStructure.js";
+  import {
+    queryList,
+    addBomDetail,
+  } from "@/api/productionManagement/productStructure.js";
   import { listProcessBom } from "@/api/productionManagement/productionOrder.js";
   import { list } from "@/api/productionManagement/productionProcess";
   import { ElMessage } from "element-plus";
@@ -228,9 +232,11 @@
     if (id === undefined || id === null || id === "") {
       return null;
     }
-    return normalizeListData(dataValue.processOptions).find(
-      option => String(option.id) === String(id)
-    ) || null;
+    return (
+      normalizeListData(dataValue.processOptions).find(
+        option => String(option.id) === String(id)
+      ) || null
+    );
   };
 
   const syncProcessOperationFields = (item: any) => {
@@ -263,6 +269,42 @@
     });
   };
 
+  const toQuantityNumber = (value: any) => {
+    const numberValue = Number(value);
+    if (!Number.isFinite(numberValue)) {
+      return 0;
+    }
+    return Number(numberValue.toFixed(2));
+  };
+
+  const syncDemandedQuantityTree = (
+    items: any[],
+    parentDemandedQuantity: number | null = null
+  ) => {
+    items.forEach((item: any) => {
+      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 (!isOrderPage.value) {
+      return;
+    }
+
+    syncDemandedQuantityTree(dataValue.dataList);
+  };
+
   const buildSubmitTree = (items: any[]) => {
     return items.map((item: any) => {
       const current = { ...item };
@@ -277,6 +319,10 @@
   const handleProcessChange = (row: any, value: any) => {
     row.processId = value || "";
     syncProcessOperationFields(row);
+  };
+
+  const handleUnitQuantityChange = () => {
+    recalculateDemandedQuantities();
   };
 
   const tableData = reactive([
@@ -299,6 +345,7 @@
       const { data } = await listProcessBom({ orderId: routeOrderId.value });
       dataValue.dataList = (data as any) || [];
       normalizeTreeData(dataValue.dataList);
+      recalculateDemandedQuantities();
     } else {
       // 闈炶鍗曟儏鍐碉細浣跨敤鍘熸潵鐨勬帴鍙�
       const { data } = await queryList(routeId.value);
@@ -432,6 +479,7 @@
   const submit = () => {
     dataValue.loading = true;
     normalizeTreeData(dataValue.dataList);
+    recalculateDemandedQuantities();
 
     // 鍏堣繘琛岃〃鍗曟牎楠�
     const valid = validateAll();
@@ -502,13 +550,14 @@
           processName: "",
           operationId: "",
           operationName: "",
-          unitQuantity: 0,
+          unitQuantity: 1,
           demandedQuantity: 0,
           unit: "",
           children: [],
 
           tempId: new Date().getTime(),
         });
+        recalculateDemandedQuantities();
         return;
       }
       addchildItem(item, tempId);
@@ -531,12 +580,13 @@
         processName: "",
         operationId: "",
         operationName: "",
-        unitQuantity: 0,
+        unitQuantity: 1,
         demandedQuantity: 0,
         children: [],
         unit: "",
         tempId: new Date().getTime(),
       });
+      recalculateDemandedQuantities();
       return true;
     }
     if (item.children && item.children.length > 0) {

--
Gitblit v1.9.3