From 8682d24dfc6a962f5dc8566857e8760bac838cc9 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期四, 15 一月 2026 13:34:02 +0800
Subject: [PATCH] fix: 完成工艺路线变更

---
 src/views/productionManagement/processRoute/New.vue |  165 ++++++++++++++++++++++++++++++++----------------------
 1 files changed, 98 insertions(+), 67 deletions(-)

diff --git a/src/views/productionManagement/processRoute/New.vue b/src/views/productionManagement/processRoute/New.vue
index 5c56fd4..62c6873 100644
--- a/src/views/productionManagement/processRoute/New.vue
+++ b/src/views/productionManagement/processRoute/New.vue
@@ -7,29 +7,46 @@
         @close="closeModal"
     >
       <el-form label-width="140px" :model="formState" label-position="top" ref="formRef">
-        <el-form-item label="浜у搧澶х被锛�" prop="productId">
-          <el-tree-select
-              v-model="formState.productId"
-              placeholder="璇烽�夋嫨"
-              clearable
-              check-strictly
-              @change="getModels"
-              :data="productOptions"
-              :render-after-expand="false"
-              style="width: 100%"
-          />
+        <el-form-item
+            label="浜у搧鍚嶇О"
+            prop="productModelId"
+            :rules="[
+                {
+                required: true,
+                message: '璇烽�夋嫨浜у搧',
+                trigger: 'change',
+              }
+            ]"
+        >
+          <el-button type="primary" @click="showProductSelectDialog = true">
+            {{ formState.productName && formState.productModelName 
+              ? `${formState.productName} - ${formState.productModelName}` 
+              : '閫夋嫨浜у搧' }}
+          </el-button>
         </el-form-item>
 
-        <el-form-item label="瑙勬牸鍨嬪彿锛�" prop="productModelId">
+        <el-form-item
+            label="BOM"
+            prop="bomId"
+            :rules="[
+                {
+                required: true,
+                message: '璇烽�夋嫨BOM',
+                trigger: 'change',
+              }
+            ]"
+        >
           <el-select
-              v-model="formState.productModelId"
-              placeholder="璇烽�夋嫨"
+              v-model="formState.bomId"
+              placeholder="璇烽�夋嫨BOM"
               clearable
+              :disabled="!formState.productModelId || bomOptions.length === 0"
+              style="width: 100%"
           >
             <el-option
-                v-for="item in productModelsOptions"
+                v-for="item in bomOptions"
                 :key="item.id"
-                :label="item.model"
+                :label="item.bomNo || `BOM-${item.id}`"
                 :value="item.id"
             />
           </el-select>
@@ -39,6 +56,13 @@
           <el-input v-model="formState.description" type="textarea" />
         </el-form-item>
       </el-form>
+      
+      <!-- 浜у搧閫夋嫨寮圭獥 -->
+      <ProductSelectDialog
+          v-model="showProductSelectDialog"
+          @confirm="handleProductSelect"
+          single
+      />
       <template #footer>
         <div class="dialog-footer">
           <el-button type="primary" @click="handleSubmit">纭</el-button>
@@ -50,9 +74,10 @@
 </template>
 
 <script setup>
-import {ref, computed, getCurrentInstance, onMounted} from "vue";
+import {ref, computed, getCurrentInstance} from "vue";
 import {add} from "@/api/productionManagement/processRoute.js";
-import {modelList, productTreeList} from "@/api/basicData/product.js";
+import {getByModel} from "@/api/productionManagement/productBom.js";
+import ProductSelectDialog from "@/views/basicData/product/ProductSelectDialog.vue";
 
 const props = defineProps({
   visible: {
@@ -67,6 +92,9 @@
 const formState = ref({
   productId: undefined,
   productModelId: undefined,
+  productName: "",
+  productModelName: "",
+  bomId: undefined,
   description: '',
 });
 
@@ -79,66 +107,73 @@
   },
 });
 
-const productModelsOptions = ref([])
-const productOptions = ref([])
+const showProductSelectDialog = ref(false);
+const bomOptions = ref([]);
 
 let { proxy } = getCurrentInstance()
 
 const closeModal = () => {
+  // 閲嶇疆琛ㄥ崟鏁版嵁
+  formState.value = {
+    productId: undefined,
+    productModelId: undefined,
+    productName: "",
+    productModelName: "",
+    bomId: undefined,
+    description: '',
+  };
+  bomOptions.value = [];
   isShow.value = false;
 };
 
-const getProductOptions = () => {
-  productTreeList().then((res) => {
-    productOptions.value = convertIdToValue(res);
-  });
-};
-const getModels = (value) => {
-  formState.value.productId = undefined;
-  formState.value.productModelId = undefined;
-  productModelsOptions.value = [];
-
-  if (value) {
-    formState.value.productId = findNodeById(productOptions.value, value) || undefined;
-    modelList({ id: value }).then((res) => {
-      productModelsOptions.value = res;
-    });
-  }
-};
-
-const findNodeById = (nodes, productId) => {
-  for (let i = 0; i < nodes.length; i++) {
-    if (nodes[i].value === productId) {
-      return nodes[i].label; // 鎵惧埌鑺傜偣锛岃繑鍥炶鑺傜偣鐨刲abel
-    }
-    if (nodes[i].children && nodes[i].children.length > 0) {
-      const foundNode = findNodeById(nodes[i].children, productId);
-      if (foundNode) {
-        return foundNode; // 鍦ㄥ瓙鑺傜偣涓壘鍒帮紝鐩存帴杩斿洖锛堝凡缁忔槸label瀛楃涓诧級
+// 浜у搧閫夋嫨澶勭悊
+const handleProductSelect = async (products) => {
+  if (products && products.length > 0) {
+    const product = products[0];
+    // 鍏堟煡璇OM鍒楄〃锛堝繀閫夛級
+    try {
+      const res = await getByModel(product.id);
+      // 澶勭悊杩斿洖鐨凚OM鏁版嵁锛氬彲鑳芥槸鏁扮粍銆佸璞℃垨鍖呭惈data瀛楁
+      let bomList = [];
+      if (Array.isArray(res)) {
+        bomList = res;
+      } else if (res && res.data) {
+        bomList = Array.isArray(res.data) ? res.data : [res.data];
+      } else if (res && typeof res === 'object') {
+        bomList = [res];
       }
+      
+      if (bomList.length > 0) {
+        formState.value.productModelId = product.id;
+        formState.value.productName = product.productName;
+        formState.value.productModelName = product.model;
+        formState.value.bomId = undefined; // 閲嶇疆BOM閫夋嫨
+        bomOptions.value = bomList;
+        showProductSelectDialog.value = false;
+        // 瑙﹀彂琛ㄥ崟楠岃瘉鏇存柊
+        proxy.$refs["formRef"]?.validateField('productModelId');
+      } else {
+        proxy.$modal.msgError("璇ヤ骇鍝佹病鏈塀OM锛岃鍏堝垱寤築OM");
+      }
+    } catch (error) {
+      // 濡傛灉鎺ュ彛杩斿洖404鎴栧叾浠栭敊璇紝璇存槑娌℃湁BOM
+      proxy.$modal.msgError("璇ヤ骇鍝佹病鏈塀OM锛岃鍏堝垱寤築OM");
     }
   }
-  return null; // 娌℃湁鎵惧埌鑺傜偣锛岃繑鍥瀗ull
 };
-
-function convertIdToValue(data) {
-  return data.map((item) => {
-    const { id, children, ...rest } = item;
-    const newItem = {
-      ...rest,
-      value: id, // 灏� id 鏀逛负 value
-    };
-    if (children && children.length > 0) {
-      newItem.children = convertIdToValue(children);
-    }
-
-    return newItem;
-  });
-}
 
 const handleSubmit = () => {
   proxy.$refs["formRef"].validate(valid => {
     if (valid) {
+      // 楠岃瘉鏄惁閫夋嫨浜嗕骇鍝佸拰BOM
+      if (!formState.value.productModelId) {
+        proxy.$modal.msgError("璇烽�夋嫨浜у搧");
+        return;
+      }
+      if (!formState.value.bomId) {
+        proxy.$modal.msgError("璇烽�夋嫨BOM");
+        return;
+      }
       add(formState.value).then(res => {
         // 鍏抽棴妯℃�佹
         isShow.value = false;
@@ -156,8 +191,4 @@
   handleSubmit,
   isShow,
 });
-
-onMounted(() => {
-  getProductOptions()
-})
 </script>

--
Gitblit v1.9.3