spring
12 小时以前 bd6032cf49ff7be0a48544e9bcdc6818a0d5d450
src/views/qualityManagement/processInspection/components/formDia.vue
@@ -9,21 +9,8 @@
      <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="工序:" prop="processId">
              <el-select
                v-model="form.processId"
                placeholder="请选择工序"
                clearable
                @change="handleProcessChange"
                style="width: 100%"
              >
                <el-option
                  v-for="item in processOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            <el-form-item label="工序:" prop="process">
              <el-input v-model="form.process" placeholder="请输入工序" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
@@ -142,7 +129,6 @@
import {ref, reactive, toRefs, getCurrentInstance, nextTick} from "vue";
import {getOptions} from "@/api/procurementManagement/procurementLedger.js";
import {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";
import {userListNoPage} from "@/api/system/user.js";
@@ -155,7 +141,7 @@
const data = reactive({
  form: {
    checkTime: "",
    processId: "",
    process: "",
    checkName: "",
    productName: "",
    productId: "",
@@ -168,11 +154,11 @@
  },
  rules: {
    checkTime: [{ required: true, message: "请输入", trigger: "blur" },],
    processId: [{ required: true, message: "请选择工序", trigger: "change" }],
    process: [{ required: true, message: "请输入工序", trigger: "blur" }],
    checkName: [{ required: false, message: "请输入", trigger: "blur" }],
    productId: [{ required: true, message: "请输入", trigger: "blur" }],
    model: [{ required: false, message: "请输入", trigger: "blur" }],
    testStandardId: [{required: true, message: "请选择指标", trigger: "change"}],
    testStandardId: [{required: false, message: "请选择指标", trigger: "change"}],
    unit: [{ required: false, message: "请输入", trigger: "blur" }],
    quantity: [{ required: true, message: "请输入", trigger: "blur" }],
    checkCompany: [{ required: false, message: "请输入", trigger: "blur" }],
@@ -210,24 +196,7 @@
const tableData = ref([]);
const tableLoading = ref(false);
const currentProductId = ref(0);
const processOptions = ref([]); // 工序下拉框数据
const testStandardOptions = ref([]); // 指标选择下拉框数据
// 获取工序列表
const getProcessList = async () => {
   try {
      const res = await productProcessListPage({ current: 1, size: 1000 })
      if (res?.code === 200) {
         const records = res?.data?.records || []
         processOptions.value = records.map(item => ({
            label: item.processName || item.name || item.label,
            value: item.id || item.processId || item.value
         }))
      }
   } catch (error) {
      console.error('获取工序列表失败:', error)
   }
}
// 打开弹框
const openDialog = async (type, row) => {
@@ -242,21 +211,11 @@
   testStandardOptions.value = [];
   tableData.value = [];
   getProductOptions();
   // 先加载工序列表
   await getProcessList();
   if (operationType.value === 'edit') {
      // 先保存 testStandardId,避免被清空
      const savedTestStandardId = row.testStandardId;
      // 先设置表单数据,但暂时清空 testStandardId,等选项加载完成后再设置
      form.value = {...row, testStandardId: ''}
      // 兼容旧数据:如果 row 中有 process 字段,转换为 processId
      if (row.process && !row.processId) {
         // 尝试从 processOptions 中查找匹配的工序
         const processOption = processOptions.value.find(p => p.label === row.process);
         if (processOption) {
            form.value.processId = processOption.value;
         }
      }
      currentProductId.value = row.productId || 0
      // 编辑模式下,先加载指标选项,然后加载参数列表
      if (currentProductId.value) {
@@ -264,7 +223,7 @@
         let params = {
            productId: currentProductId.value,
            inspectType: 1,
            process: form.value.processId ? processOptions.value.find(p => p.value === form.value.processId)?.label : ''
            process: form.value.process || ''
         }
         qualityInspectDetailByProductId(params).then(res => {
            testStandardOptions.value = res.data || [];
@@ -280,12 +239,13 @@
                     if (matchedOption) {
                        // 确保使用匹配项的 id(保持类型一致)
                        form.value.testStandardId = matchedOption.id;
                        handleTestStandardChange(matchedOption.id);
                        // 编辑保留原检验值,直接拉取原参数数据
                        getQualityInspectParamList(row.id);
                     } else {
                        // 如果找不到匹配项,尝试直接使用原值
                        console.warn('未找到匹配的指标选项,testStandardId:', savedTestStandardId, '可用选项:', testStandardOptions.value);
                        form.value.testStandardId = savedTestStandardId;
                        handleTestStandardChange(savedTestStandardId);
                        getQualityInspectParamList(row.id);
                     }
                  } else {
                     // 否则使用旧的逻辑
@@ -340,20 +300,12 @@
  });
}
// 工序变化处理
const handleProcessChange = () => {
   // 工序变化时,如果已选择产品,重新加载指标列表
   if (currentProductId.value) {
      getList();
   }
}
// 提交产品表单
const submitForm = () => {
  proxy.$refs.formRef.validate(valid => {
    if (valid) {
      form.value.inspectType = 1
         // 将 processId 转换为 process 名称(如果后端需要 process 字段)
         const processName = form.value.processId ? processOptions.value.find(p => p.value === form.value.processId)?.label : '';
         const processName = form.value.process || '';
         if (operationType.value === "add") {
            tableData.value.forEach((item) => {
               delete item.id
@@ -384,8 +336,7 @@
      tableData.value = [];
      return;
   }
   // 获取工序名称
   const processName = form.value.processId ? processOptions.value.find(p => p.value === form.value.processId)?.label : '';
   const processName = form.value.process || '';
   let params = {
      productId: currentProductId.value,
      inspectType: 1,