From 93b8ceac34e2fbd5c57fe5ab4f5bac32c85408aa Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期五, 22 五月 2026 15:37:09 +0800
Subject: [PATCH] fix(hr): 修正岗位字段映射

---
 src/views/productionManagement/productStructure/Detail/index.vue |  134 +++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 124 insertions(+), 10 deletions(-)

diff --git a/src/views/productionManagement/productStructure/Detail/index.vue b/src/views/productionManagement/productStructure/Detail/index.vue
index 6fbe21b..5cb08e8 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 };
@@ -274,9 +316,40 @@
     });
   };
 
+  const findSiblings = (items: any[], tempId: string): any[] | null => {
+    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 handleProcessChange = (row: any, value: any) => {
     row.processId = value || "";
     syncProcessOperationFields(row);
+    
+    // 妫�鏌ュ悓涓�灞傜骇鏄惁宸茬粡鏈夊叾浠栦笉鍚岀殑宸ュ簭琚�変腑
+    const siblings = findSiblings(dataValue.dataList, row.tempId);
+    if (siblings && value) {
+      const hasDifferentProcess = siblings.some(sibling => {
+        return sibling.tempId !== row.tempId && sibling.processId && sibling.processId !== value;
+      });
+      if (hasDifferentProcess) {
+        ElMessage.warning("鍚屼竴灞傜骇宸插瓨鍦ㄤ笉鍚岀殑宸ュ簭锛岃鍏堢粺涓�宸ュ簭鍚庡啀杩涜淇敼");
+      }
+    }
+  };
+
+  const handleUnitQuantityChange = () => {
+    recalculateDemandedQuantities();
   };
 
   const tableData = reactive([
@@ -299,6 +372,7 @@
       const { data } = await listProcessBom({ orderId: routeOrderId.value });
       dataValue.dataList = (data as any) || [];
       normalizeTreeData(dataValue.dataList);
+      recalculateDemandedQuantities();
     } else {
       // 闈炶鍗曟儏鍐碉細浣跨敤鍘熸潵鐨勬帴鍙�
       const { data } = await queryList(routeId.value);
@@ -384,8 +458,41 @@
   const validateAll = () => {
     let isValid = true;
 
+    // 鏍¢獙涓�缁勫厔寮熻妭鐐圭殑宸ュ簭鏄惁閮界浉鍚�
+    const checkProcessUniqueness = (items: any[]) => {
+      if (!items || items.length === 0 || !isValid) return;
+
+      // 鑾峰彇绗竴涓潪绌虹殑宸ュ簭ID浣滀负鍙傝��
+      const firstProcessId = items.find(item => item.processId)?.processId;
+      
+      // 濡傛灉鏈夊伐搴廔D锛屾鏌ユ墍鏈夐」鏄惁閮戒娇鐢ㄧ浉鍚岀殑宸ュ簭
+      if (firstProcessId) {
+        for (const item of items) {
+          if (item.processId && item.processId !== firstProcessId) {
+            const option1 = getProcessOptionById(firstProcessId);
+            const option2 = getProcessOptionById(item.processId);
+            const processName1 = option1?.name || "鏈煡宸ュ簭";
+            const processName2 = option2?.name || "鏈煡宸ュ簭";
+            ElMessage.error(
+              `褰撳墠灞傜骇涓嬪伐搴忎笉涓�鑷达紝璇蜂娇鐢ㄧ浉鍚岀殑宸ュ簭銆傚瓨鍦ㄣ��${processName1}銆嶅拰銆�${processName2}銆峘
+            );
+            isValid = false;
+            return;
+          }
+        }
+      }
+
+      // 閫掑綊鏍¢獙瀛愮骇鐨勫厔寮熻妭鐐�
+      for (const item of items) {
+        if (item.children && item.children.length > 0) {
+          checkProcessUniqueness(item.children);
+        }
+      }
+    };
+
     // 鏍¢獙鍑芥暟
     const validateItem = (item: any, isTopLevel = false) => {
+      if (!isValid) return;
       // 鏍¢獙褰撳墠椤圭殑蹇呭~瀛楁
       if (!item.model) {
         ElMessage.error("璇烽�夋嫨瑙勬牸");
@@ -413,7 +520,7 @@
       //   return;
       // }
 
-      // 閫掑綊鏍¢獙瀛愰」
+      // 閫掑綊鏍¢獙瀛愰」瀛楁
       if (item.children && item.children.length > 0) {
         item.children.forEach(child => {
           validateItem(child, false);
@@ -421,7 +528,11 @@
       }
     };
 
-    // 閬嶅巻鎵�鏈夐《灞傞」
+    // 1. 棣栧厛鏍¢獙鍚屼竴鐖剁骇涓嬬殑鍚屽眰娑堣�楀伐搴忔槸鍚﹀敮涓�
+    checkProcessUniqueness(dataValue.dataList);
+    if (!isValid) return false;
+
+    // 2. 鐒跺悗閬嶅巻鏍¢獙鎵�鏈夐《灞傞」鐨勫瓧娈靛繀濉儏鍐�
     dataValue.dataList.forEach(item => {
       validateItem(item, true);
     });
@@ -432,6 +543,7 @@
   const submit = () => {
     dataValue.loading = true;
     normalizeTreeData(dataValue.dataList);
+    recalculateDemandedQuantities();
 
     // 鍏堣繘琛岃〃鍗曟牎楠�
     const valid = validateAll();
@@ -502,13 +614,14 @@
           processName: "",
           operationId: "",
           operationName: "",
-          unitQuantity: 0,
+          unitQuantity: 1,
           demandedQuantity: 0,
           unit: "",
           children: [],
 
           tempId: new Date().getTime(),
         });
+        recalculateDemandedQuantities();
         return;
       }
       addchildItem(item, tempId);
@@ -531,12 +644,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) {
@@ -582,4 +696,4 @@
     await fetchProcessOptions();
     await fetchData();
   });
-</script>
+</script>
\ No newline at end of file

--
Gitblit v1.9.3