From 5995b83b40e979d391a903822095a23353a74283 Mon Sep 17 00:00:00 2001
From: 张诺 <zhang_12370@163.com>
Date: 星期二, 07 四月 2026 16:02:06 +0800
Subject: [PATCH] fix: 优化编辑时检验参数加载逻辑

---
 src/views/qualityManagement/finalInspection/components/formDia.vue |   54 ++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/src/views/qualityManagement/finalInspection/components/formDia.vue b/src/views/qualityManagement/finalInspection/components/formDia.vue
index 5bd847f..837b53c 100644
--- a/src/views/qualityManagement/finalInspection/components/formDia.vue
+++ b/src/views/qualityManagement/finalInspection/components/formDia.vue
@@ -23,8 +23,21 @@
             </el-form-item>
           </el-col>
           <el-col :span="12">
-            <el-form-item label="瑙勬牸鍨嬪彿锛�" prop="model">
-              <el-input v-model="form.model" placeholder="璇疯緭鍏�" clearable/>
+            <el-form-item label="瑙勬牸鍨嬪彿锛�" prop="productModelId">
+              <el-select
+                v-model="form.productModelId"
+                placeholder="璇烽�夋嫨"
+                clearable
+                @change="getProductModel"
+                style="width: 100%"
+              >
+                <el-option
+                  v-for="item in modelOptions"
+                  :key="item.id"
+                  :label="item.model"
+                  :value="item.id"
+                />
+              </el-select>
             </el-form-item>
           </el-col>
           <el-col :span="12">
@@ -121,7 +134,7 @@
 <script setup>
 import {ref, reactive, toRefs, getCurrentInstance, nextTick} from "vue";
 import {getOptions} from "@/api/procurementManagement/procurementLedger.js";
-import {productTreeList} from "@/api/basicData/product.js";
+import {modelList, productTreeList} from "@/api/basicData/product.js";
 import {qualityInspectAdd, qualityInspectUpdate} from "@/api/qualityManagement/rawMaterialInspection.js";
 import {userListNoPage} from "@/api/system/user.js";
 import {qualityInspectDetailByProductId, getQualityTestStandardParamByTestStandardId} from "@/api/qualityManagement/metricMaintenance.js";
@@ -138,6 +151,7 @@
     checkName: "",
     productName: "",
     productId: "",
+    productModelId: "",
     model: "",
     testStandardId: "",
     unit: "",
@@ -150,6 +164,7 @@
     process: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
     checkName: [{ required: false, message: "璇疯緭鍏�", trigger: "blur" }],
     productId: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
+    productModelId: [{required: true, message: "璇烽�夋嫨瑙勬牸鍨嬪彿", trigger: "change"}],
     model: [{ required: false, message: "璇疯緭鍏�", trigger: "blur" }],
     testStandardId: [{required: true, message: "璇烽�夋嫨鎸囨爣", trigger: "change"}],
     unit: [{ required: false, message: "璇疯緭鍏�", trigger: "blur" }],
@@ -188,6 +203,7 @@
 const tableData = ref([]);
 const tableLoading = ref(false);
 const userList = ref([]);
+const modelOptions = ref([]); // 瑙勬牸鍨嬪彿涓嬫媺妗嗘暟鎹�
 const currentProductId = ref(0);
 const testStandardOptions = ref([]); // 鎸囨爣閫夋嫨涓嬫媺妗嗘暟鎹�
 
@@ -203,6 +219,7 @@
 	form.value = {}
   testStandardOptions.value = [];
   tableData.value = [];
+  modelOptions.value = [];
   getProductOptions();
   if (operationType.value === 'edit') {
     // 鍏堜繚瀛� testStandardId锛岄伩鍏嶈娓呯┖
@@ -212,6 +229,10 @@
 		currentProductId.value = row.productId || 0
 		// 缂栬緫妯″紡涓嬶紝鍏堝姞杞芥寚鏍囬�夐」锛岀劧鍚庡姞杞藉弬鏁板垪琛�
 		if (currentProductId.value) {
+      // 鍔犺浇瑙勬牸鍨嬪彿閫夐」
+      modelList({ id: currentProductId.value }).then((res) => {
+        modelOptions.value = res;
+      });
 			// 鍏堝姞杞芥寚鏍囬�夐」
 			let params = {
 				productId: currentProductId.value,
@@ -222,27 +243,20 @@
 				// 浣跨敤 nextTick 鍜� setTimeout 纭繚閫夐」宸茬粡娓叉煋鍒� DOM
 				nextTick(() => {
 					setTimeout(() => {
-						// 濡傛灉缂栬緫鏁版嵁涓湁 testStandardId锛屽垯璁剧疆骞跺姞杞藉搴旂殑鍙傛暟
 						if (savedTestStandardId) {
 							// 纭繚绫诲瀷鍖归厤锛坕tem.id 鍙兘鏄暟瀛楁垨瀛楃涓诧級
 							const matchedOption = testStandardOptions.value.find(item => 
 								item.id == savedTestStandardId || String(item.id) === String(savedTestStandardId)
 							);
 							if (matchedOption) {
-								// 纭繚浣跨敤鍖归厤椤圭殑 id锛堜繚鎸佺被鍨嬩竴鑷达級
 								form.value.testStandardId = matchedOption.id;
-                console.log(22222,form.value.testStandardId);
-								handleTestStandardChange(matchedOption.id);
 							} else {
-								// 濡傛灉鎵句笉鍒板尮閰嶉」锛屽皾璇曠洿鎺ヤ娇鐢ㄥ師鍊�
 								console.warn('鏈壘鍒板尮閰嶇殑鎸囨爣閫夐」锛宼estStandardId:', savedTestStandardId, '鍙敤閫夐」:', testStandardOptions.value);
 								form.value.testStandardId = savedTestStandardId;
-								handleTestStandardChange(savedTestStandardId);
 							}
-						} else {
-							// 鍚﹀垯浣跨敤鏃х殑閫昏緫
-							getQualityInspectParamList(row.id);
 						}
+						// 缂栬緫鏃跺缁堝姞杞戒繚瀛樼殑妫�楠屽弬鏁�
+						getQualityInspectParamList(row.id);
 					}, 100);
 				});
 			});
@@ -259,10 +273,26 @@
 const getModels = (value) => {
 	currentProductId.value = value
   form.value.productName = findNodeById(productOptions.value, value);
+  modelOptions.value = [];
+  form.value.productModelId = "";
+  form.value.model = "";
 	if (currentProductId.value) {
+    modelList({ id: value }).then((res) => {
+      modelOptions.value = res;
+    });
 		getList();
 	}
 };
+const getProductModel = (value) => {
+  const index = modelOptions.value.findIndex((item) => item.id === value);
+  if (index !== -1) {
+    form.value.model = modelOptions.value[index].model;
+    form.value.unit = modelOptions.value[index].unit;
+  } else {
+    form.value.model = "";
+    form.value.unit = "";
+  }
+};
 const findNodeById = (nodes, productId) => {
   for (let i = 0; i < nodes.length; i++) {
     if (nodes[i].value === productId) {

--
Gitblit v1.9.3