diff --git a/src/views/is/project/index.vue b/src/views/is/project/index.vue index 35dab00..3a65c7a 100644 --- a/src/views/is/project/index.vue +++ b/src/views/is/project/index.vue @@ -334,7 +334,7 @@ @@ -425,6 +425,10 @@ const data = reactive({ trademark: null, modelSpec: null, quantity: null, + entrustUnit: null, + productionUnit: null, + sampleDate: null, + productionDate: null, }, queryParams: { pageNum: 1, @@ -522,8 +526,10 @@ function reset() { trademark: null, modelSpec: null, quantity: null, - status: null, - remark: null, + entrustUnit: null, + productionUnit: null, + sampleDate: null, + productionDate: null, createBy: null, createTime: null, updateBy: null, @@ -560,32 +566,39 @@ function handleAdd() { const formRef = ref(); -const submitForm = () => { - if (!formRef.value) return; +const submitting = ref(false); +const submitForm = async () => { + if (!formRef.value || submitting.value) return; - formRef.value.validate((valid) => { - if (!valid) { - return - } - form.value.testFuncIds = JSON.stringify(form.value.testFuncIds) - if (isAdd.value) { - addProject(form.value).then(res => { - if (res.code === 200) { - ElMessage.success("添加成功"); - getList(); - } - }) - } else { - updateProject(form.value).then(res => { - if (res.code === 200) { - ElMessage.success("修改成功"); - getList(); - } - }) + const valid = await formRef.value.validate().catch(() => false); + if (!valid) return; + + const testFuncIds = Array.isArray(form.value.testFuncIds) + ? form.value.testFuncIds + : []; + const payload = { + ...form.value, + testFuncIds: JSON.stringify(testFuncIds), + }; + + submitting.value = true; + try { + const res = isAdd.value + ? await addProject(payload) + : await updateProject(payload); + if (res.code !== 200) { + ElMessage.error(res.msg || (isAdd.value ? "添加失败" : "修改失败")); + return; } + ElMessage.success(isAdd.value ? "添加成功" : "修改成功"); open.value = false; reset(); - }); + getList(); + } catch (err) { + console.error(isAdd.value ? "添加项目异常:" : "修改项目异常:", err); + } finally { + submitting.value = false; + } }; const handleUpdate = (row) => { @@ -593,7 +606,7 @@ const handleUpdate = (row) => { open.value = true; isAdd.value = false; title.value = "修改测试项目"; - form.value = row; + form.value = { ...row }; let arr = [] try { arr = JSON.parse(form.value.testFuncIds); @@ -644,24 +657,32 @@ const vehicleConfigChange = (value) => { getFuncList(value) } -const getFuncList = (value) => { - getFunction({ - pageNum: 1, - pageSize: 10000, - vehicleConfigId: value - }).then((res) => { - if (res.code === 200) { - funcIdOptions.value = (res.rows || []).map(item => { - const label = ti_function_config.value.find(func => { - return func.value === item.funcKey - }).label - return { - label: label, - value: item.id - } - }) +const getFuncList = async (value) => { + if (!value) return; + try { + const res = await getFunction({ + pageNum: 1, + pageSize: 10000, + vehicleConfigId: value + }); + if (res.code !== 200) { + ElMessage.error(res.msg || "加载功能列表失败"); + return; } - }) + const dictItems = ti_function_config.value || []; + funcIdOptions.value = (res.rows || []).map(item => { + const dictItem = dictItems.find(func => { + return String(func.value) === String(item.funcKey) + }); + return { + label: dictItem?.label || item.funcKey || `功能 ${item.id}`, + value: item.id + }; + }); + } catch (err) { + console.error("加载功能列表异常:", err); + ElMessage.error("网络异常,加载功能列表失败"); + } } const executeOpen = ref(false);