张诺
2026-04-07 5995b83b40e979d391a903822095a23353a74283
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) {
                     // 确保类型匹配(item.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('未找到匹配的指标选项,testStandardId:', 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) {