From f372a30a711a1f7d7bc764d2060d5719a47c7c4c Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 23 一月 2026 15:37:07 +0800
Subject: [PATCH] fix: 最外层应当不能被编辑修改

---
 src/views/productionManagement/productStructure/Detail/index.vue |  208 +++++++++++++++------------------------------------
 1 files changed, 62 insertions(+), 146 deletions(-)

diff --git a/src/views/productionManagement/productStructure/Detail/index.vue b/src/views/productionManagement/productStructure/Detail/index.vue
index 7e9e176..c56b247 100644
--- a/src/views/productionManagement/productStructure/Detail/index.vue
+++ b/src/views/productionManagement/productStructure/Detail/index.vue
@@ -2,10 +2,6 @@
   <div class="app-container">
     <PageHeader content="浜у搧缁撴瀯璇︽儏">
       <template #right-button>
-        <el-button v-if="dataValue.isEdit && !isOrderPage"
-                   type="primary"
-                   @click="addItem">娣诲姞
-        </el-button>
         <el-button v-if="!dataValue.isEdit && !isOrderPage"
                    type="primary"
                    @click="dataValue.isEdit = true">缂栬緫
@@ -47,7 +43,7 @@
                     <el-select v-model="row.model"
                                placeholder="璇烽�夋嫨瑙勬牸"
                                clearable
-                               :disabled="!dataValue.isEdit"
+                               :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)"
                                style="width: 100%"
                                @visible-change="(v) => { if (v) openDialog(row.tempId) }">
                       <el-option v-if="row.model"
@@ -57,18 +53,18 @@
                   </el-form-item>
                 </template>
               </el-table-column>
-              <el-table-column prop="processId"
+              <el-table-column prop="processName"
                                label="娑堣�楀伐搴�">
                 <template #default="{ row, $index }">
                   <el-form-item v-if="dataValue.isEdit"
-                                :rules="[{ required: true, message: '璇烽�夋嫨娑堣�楀伐搴�', trigger: 'change' }]"
+                                :rules="dataValue.dataList.some(item => (item as any).tempId === row.tempId) ? [] : [{ required: true, message: '璇烽�夋嫨娑堣�楀伐搴�', trigger: 'change' }]"
                                 style="margin: 0">
                     <el-select v-model="row.processId"
                                placeholder="璇烽�夋嫨"
                                filterable
                                clearable
                                style="width: 100%"
-                               :disabled="!dataValue.isEdit">
+                               :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)">
                       <el-option v-for="item in dataValue.processOptions"
                                  :key="item.id"
                                  :label="item.name"
@@ -89,7 +85,7 @@
                                      :step="1"
                                      controls-position="right"
                                      style="width: 100%"
-                                     :disabled="!dataValue.isEdit" />
+                                     :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)" />
                   </el-form-item>
                 </template>
               </el-table-column>
@@ -106,7 +102,7 @@
                                      :step="1"
                                      controls-position="right"
                                      style="width: 100%"
-                                     :disabled="!dataValue.isEdit" />
+                                     :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)" />
                   </el-form-item>
                 </template>
               </el-table-column>
@@ -119,7 +115,7 @@
                     <el-input v-model="row.unit"
                               placeholder="璇疯緭鍏ュ崟浣�"
                               clearable
-                              :disabled="!dataValue.isEdit" />
+                               :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)" />
                   </el-form-item>
                 </template>
               </el-table-column>
@@ -127,7 +123,7 @@
                                fixed="right"
                                width="200">
                 <template #default="{ row, $index }">
-                  <el-button v-if="dataValue.isEdit"
+                  <el-button v-if="dataValue.isEdit && !dataValue.dataList.some(item => (item as any).tempId === row.tempId)"
                              type="danger"
                              text
                              @click="removeItem(row.tempId)">鍒犻櫎
@@ -178,6 +174,7 @@
   const ProductSelectDialog = defineAsyncComponent(
     () => import("@/views/basicData/product/ProductSelectDialog.vue")
   );
+  const emit = defineEmits(["update:router"]);
   const form = ref();
 
   const route = useRoute();
@@ -223,7 +220,7 @@
     },
   ]);
 
-  const openDialog = tempId => {
+  const openDialog = (tempId: any) => {
     console.log(tempId, "tempId");
     dataValue.currentRowName = tempId;
     dataValue.showProductDialog = true;
@@ -233,15 +230,18 @@
     if (isOrderPage.value) {
       // 璁㈠崟鎯呭喌锛氫娇鐢ㄨ鍗曠殑浜у搧缁撴瀯鎺ュ彛
       const { data } = await listProcessBom({ orderId: routeOrderId.value });
-      dataValue.dataList = data || [];
+      dataValue.dataList = (data as any) || [];
     } else {
       // 闈炶鍗曟儏鍐碉細浣跨敤鍘熸潵鐨勬帴鍙�
       const { data } = await queryList(routeId.value);
-      dataValue.dataList = data || [];
+      dataValue.dataList = (data as any) || [];
       // 涓烘墍鏈夐」鍙婂叾瀛愰」璁剧疆name灞炴��
-      const setNameRecursively = items => {
-        items.forEach(item => {
+      const setNameRecursively = (items: any[]) => {
+        items.forEach((item: any) => {
           item.tempId = item.id;
+          item.processName =
+            dataValue.processOptions.find(option => option.id === item.processId)
+              ?.name || "";
           if (item.children && item.children.length > 0) {
             setNameRecursively(item.children);
           }
@@ -249,116 +249,37 @@
       };
       setNameRecursively(dataValue.dataList);
       console.log(dataValue.dataList, "dataValue.dataList");
-
-      // dataValue.dataList = [
-      //   {
-      //     id: 30,
-      //     productModelId: 220,
-      //     processId: 42,
-      //     unitQuantity: 0.0,
-      //     demandedQuantity: 0.0,
-      //     unit: "30",
-      //     tenantId: 100,
-      //     bomId: 5,
-      //     processName: "娴嬭瘯1",
-      //     productName: "1111",
-      //     productId: 264,
-      //     model: "1112233",
-      //     productStructureList: null,
-      //     children: [
-      //       {
-      //         id: 300,
-      //         productModelId: 220,
-      //         processId: 42,
-      //         unitQuantity: 0.0,
-      //         demandedQuantity: 0.0,
-      //         unit: "300",
-      //         tenantId: 100,
-      //         bomId: 5,
-      //         processName: "娴嬭瘯1",
-      //         productName: "1111",
-      //         productId: 264,
-      //         model: "1112233",
-      //         productStructureList: null,
-      //         children: [
-      //           {
-      //             id: 3000,
-      //             productModelId: 220,
-      //             processId: 42,
-      //             unitQuantity: 0.0,
-      //             demandedQuantity: 0.0,
-      //             unit: "3000",
-      //             tenantId: 100,
-      //             bomId: 5,
-      //             processName: "娴嬭瘯1",
-      //             productName: "1111",
-      //             productId: 264,
-      //             model: "1112233",
-      //             productStructureList: null,
-      //           },
-      //           {
-      //             id: 3200,
-      //             productModelId: 221,
-      //             processId: 43,
-      //             unitQuantity: 0.0,
-      //             demandedQuantity: 0.0,
-      //             unit: "3200",
-      //             tenantId: 100,
-      //             bomId: 5,
-      //             processName: "娴嬭瘯2",
-      //             productName: "xxx",
-      //             productId: 266,
-      //             model: "xxx",
-      //             productStructureList: null,
-      //           },
-      //         ],
-      //       },
-      //       {
-      //         id: 320,
-      //         productModelId: 221,
-      //         processId: 43,
-      //         unitQuantity: 0.0,
-      //         demandedQuantity: 0.0,
-      //         unit: "320",
-      //         tenantId: 100,
-      //         bomId: 5,
-      //         processName: "娴嬭瘯2",
-      //         productName: "xxx",
-      //         productId: 266,
-      //         model: "xxx",
-      //         productStructureList: null,
-      //       },
-      //     ],
-      //   },
-      //   {
-      //     id: 32,
-      //     productModelId: 221,
-      //     processId: 43,
-      //     unitQuantity: 0.0,
-      //     demandedQuantity: 0.0,
-      //     unit: "32",
-      //     tenantId: 100,
-      //     bomId: 5,
-      //     processName: "娴嬭瘯2",
-      //     productName: "xxx",
-      //     productId: 266,
-      //     model: "xxx",
-      //     productStructureList: null,
-      //   },
-      // ];
     }
   };
 
   const fetchProcessOptions = async () => {
-    const { data } = await list(routeId.value);
-    dataValue.processOptions = data;
+    const { data } = await list();
+    dataValue.processOptions = data as any;
   };
 
-  const handleProduct = row => {
+  const handleProduct = (row: any) => {
     if (row?.length > 1) {
       ElMessage.error("鍙兘閫夋嫨涓�涓骇鍝�");
     }
     const productData = row[0];
+
+    //  鏈�澶栧眰缁勪欢涓紝涓庡綋鍓嶄骇鍝佺浉鍚岀殑浜у搧鍙兘鏈変竴涓�
+    const isTopLevel = dataValue.dataList.some(item => (item as any).tempId === dataValue.currentRowName);
+    if (isTopLevel) {
+      if (productData.productName === tableData[0].productName &&
+        productData.model === tableData[0].model) {
+        //  鏌ユ壘鏄惁宸茬粡鏈夊叾浠栭《灞傝宸茬粡鏄繖涓骇鍝�
+        const hasOther = dataValue.dataList.some(item =>
+          (item as any).tempId !== dataValue.currentRowName &&
+          (item as any).productName === tableData[0].productName &&
+          (item as any).model === tableData[0].model
+        );
+        if (hasOther) {
+          ElMessage.warning("鏈�澶栧眰鍜屽綋鍓嶄骇鍝佷竴鏍风殑涓�绾у彧鑳芥湁涓�涓�");
+          return;
+        }
+      }
+    }
     // dataValue.dataList[dataValue.currentRowIndex].productName =
     //   row[0].productName;
     // dataValue.dataList[dataValue.currentRowIndex].model = row[0].model;
@@ -376,7 +297,7 @@
     });
     dataValue.showProductDialog = false;
   };
-  const childItem = (item, tempId, productData) => {
+  const childItem = (item: any, tempId: any, productData: any) => {
     if (item.tempId === tempId) {
       item.productName = productData.productName;
       item.model = productData.model;
@@ -399,14 +320,14 @@
     let isValid = true;
 
     // 鏍¢獙鍑芥暟
-    const validateItem = item => {
+    const validateItem = (item: any, isTopLevel = false) => {
       // 鏍¢獙褰撳墠椤圭殑蹇呭~瀛楁
       if (!item.model) {
         ElMessage.error("璇烽�夋嫨瑙勬牸");
         isValid = false;
         return;
       }
-      if (!item.processId) {
+      if (!isTopLevel && !item.processId) {
         ElMessage.error("璇烽�夋嫨娑堣�楀伐搴�");
         isValid = false;
         return;
@@ -430,14 +351,14 @@
       // 閫掑綊鏍¢獙瀛愰」
       if (item.children && item.children.length > 0) {
         item.children.forEach(child => {
-          validateItem(child);
+          validateItem(child, false);
         });
       }
     };
 
     // 閬嶅巻鎵�鏈夐《灞傞」
     dataValue.dataList.forEach(item => {
-      validateItem(item);
+      validateItem(item, true);
     });
 
     return isValid;
@@ -469,20 +390,7 @@
     }
   };
 
-  const addItem = () => {
-    dataValue.dataList.push({
-      productName: "",
-      productId: "",
-      model: undefined,
-      productModelId: undefined,
-      processId: "",
-      unitQuantity: 0,
-      demandedQuantity: 0,
-      unit: "",
-      tempId: new Date().getTime(),
-    });
-  };
-  const removeItem = tempId => {
+  const removeItem = (tempId:string) => {
     // 鍏堝皾璇曚粠椤跺眰鍒犻櫎
     const topIndex = dataValue.dataList.findIndex(item => item.tempId === tempId);
     if (topIndex !== -1) {
@@ -491,7 +399,7 @@
     }
 
     // 閫掑綊鍒犻櫎瀛愰」
-    const delchildItem = (items, tempId) => {
+    const delchildItem = (items: any[], tempId: any) => {
       for (let i = 0; i < items.length; i++) {
         const item = items[i];
         if (item.tempId === tempId) {
@@ -516,6 +424,9 @@
   const addItem2 = tempId => {
     dataValue.dataList.map(item => {
       if (item.tempId === tempId) {
+        if (!item.children) {
+          item.children = [];
+        }
         item.children.push({
           parentId: item.id || "",
           parentTempId: item.tempId || "",
@@ -524,6 +435,7 @@
           model: undefined,
           productModelId: undefined,
           processId: "",
+          processName: "",
           unitQuantity: 0,
           demandedQuantity: 0,
           unit: "",
@@ -536,10 +448,12 @@
       addchildItem(item, tempId);
     });
   };
-  const addchildItem = (item, tempId) => {
+  const addchildItem = (item: any, tempId: any) => {
     if (item.tempId === tempId) {
       console.log(item, "item");
-
+      if (!item.children) {
+        item.children = [];
+      }
       item.children.push({
         parentId: item.id || "",
         parentTempId: item.tempId || "",
@@ -580,21 +494,23 @@
 
   const cancelEdit = () => {
     dataValue.isEdit = false;
-    dataValue.dataList = dataValue.dataList.filter(item => item.id !== undefined);
+    // dataValue.dataList = dataValue.dataList.filter(item => item.id !== undefined);
+    fetchData();
   };
 
-  onMounted(() => {
+  onMounted(async () => {
     // 浠庤矾鐢卞弬鏁板洖鏄炬暟鎹�
-    tableData[0].productName = routeProductName.value;
-    tableData[0].model = routeProductModelName.value;
-    tableData[0].bomNo = routeBomNo.value;
+    tableData[0].productName = routeProductName.value as string;
+    tableData[0].model = routeProductModelName.value as string;
+    tableData[0].bomNo = routeBomNo.value as string;
 
     // 璁㈠崟鎯呭喌涓嬬鐢ㄧ紪杈�
     if (isOrderPage.value) {
       dataValue.isEdit = false;
     }
 
-    fetchData();
-    fetchProcessOptions();
+    // 鍏堝姞杞藉伐搴忛�夐」锛屽啀鍔犺浇鏁版嵁锛岀‘淇漞l-select鑳藉姝g‘鍥炴樉
+    await fetchProcessOptions();
+    await fetchData();
   });
 </script>
\ No newline at end of file

--
Gitblit v1.9.3