张诺
2026-04-07 5995b83b40e979d391a903822095a23353a74283
src/views/qualityManagement/processInspection/components/formDia.vue
@@ -43,8 +43,21 @@
        </el-row>
        <el-row :gutter="30">
          <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">
@@ -141,7 +154,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 {productProcessListPage} from "@/api/basicData/productProcess.js";
import {qualityInspectAdd, qualityInspectUpdate} from "@/api/qualityManagement/rawMaterialInspection.js";
import {qualityInspectDetailByProductId, getQualityTestStandardParamByTestStandardId} from "@/api/qualityManagement/metricMaintenance.js";
@@ -159,6 +172,7 @@
    checkName: "",
    productName: "",
    productId: "",
    productModelId: "",
    model: "",
    testStandardId: "",
    unit: "",
@@ -171,6 +185,7 @@
    processId: [{ required: true, message: "请选择工序", trigger: "change" }],
    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" }],
@@ -211,6 +226,7 @@
const tableLoading = ref(false);
const currentProductId = ref(0);
const processOptions = ref([]); // 工序下拉框数据
const modelOptions = ref([]); // 规格型号下拉框数据
const testStandardOptions = ref([]); // 指标选择下拉框数据
// 获取工序列表
@@ -241,6 +257,7 @@
   form.value = {}
   testStandardOptions.value = [];
   tableData.value = [];
   modelOptions.value = [];
   getProductOptions();
   // 先加载工序列表
   await getProcessList();
@@ -260,6 +277,10 @@
      currentProductId.value = row.productId || 0
      // 编辑模式下,先加载指标选项,然后加载参数列表
      if (currentProductId.value) {
         // 加载规格型号选项
         modelList({ id: currentProductId.value }).then((res) => {
            modelOptions.value = res;
         });
         // 先加载指标选项
         let params = {
            productId: currentProductId.value,
@@ -271,26 +292,20 @@
            // 使用 nextTick 和 setTimeout 确保选项已经渲染到 DOM
            nextTick(() => {
               setTimeout(() => {
                  // 如果编辑数据中有 testStandardId,则设置并加载对应的参数
                  if (savedTestStandardId) {
                     // 确保类型匹配(item.id 可能是数字或字符串)
                     const matchedOption = testStandardOptions.value.find(item => 
                        item.id == savedTestStandardId || String(item.id) === String(savedTestStandardId)
                     );
                     if (matchedOption) {
                        // 确保使用匹配项的 id(保持类型一致)
                        form.value.testStandardId = matchedOption.id;
                        handleTestStandardChange(matchedOption.id);
                     } else {
                        // 如果找不到匹配项,尝试直接使用原值
                        console.warn('未找到匹配的指标选项,testStandardId:', savedTestStandardId, '可用选项:', testStandardOptions.value);
                        form.value.testStandardId = savedTestStandardId;
                        handleTestStandardChange(savedTestStandardId);
                     }
                  } else {
                     // 否则使用旧的逻辑
                     getQualityInspectParamList(row.id);
                  }
                  // 编辑时始终加载保存的检验参数
                  getQualityInspectParamList(row.id);
               }, 100);
            });
         });
@@ -307,10 +322,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) {