diff --git a/frontend/src/api/plan/plan.ts b/frontend/src/api/plan/plan.ts index a1bcbd8..dbe434d 100644 --- a/frontend/src/api/plan/plan.ts +++ b/frontend/src/api/plan/plan.ts @@ -148,4 +148,9 @@ export const importSubPlanCheckData = (params: Plan.ResPlan) => { // 合并子检测计划检测结果数据 export const mergeSubPlanCheckData = (params: Plan.ResPlan) => { return http.upload(`/adPlan/mergePlanCheckData?planId=${params.id}`) +} + +//根据误差体系id获取测试项 +export const getPqErrSysTestItemList = (params: Plan.ResPlan) => { + return http.get(`/pqErrSys/getTestItems?id=${params.errorSysId}`) } \ No newline at end of file diff --git a/frontend/src/views/plan/planList/components/planPopup.vue b/frontend/src/views/plan/planList/components/planPopup.vue index 75f8582..6a0c81d 100644 --- a/frontend/src/views/plan/planList/components/planPopup.vue +++ b/frontend/src/views/plan/planList/components/planPopup.vue @@ -122,6 +122,7 @@ clearable filterable placeholder="请选择误差体系" + @change="handleErrorSysChange" > { // 打开弹窗,可能是新增,也可能是编辑 const open = async (sign: string, data: Plan.ReqPlan, currentMode: string, plan: number) => { + unboundPqDevList.value = [] boundPqDevList.value = [] //处理异步调用 @@ -715,27 +719,6 @@ const open = async (sign: string, data: Plan.ReqPlan, currentMode: string, plan: titleType.value = sign isSelectDisabled.value = false planType.value = plan - console.log('planType.value', planType.value) - //比对式测试项下拉框 - if (mode.value == '比对式') { - const dictCode = 'Script_Error' - const resDictTree: Dict.ResDictTree = { - name: '', - id: '', - pid: '', - pids: '', - code: dictCode, - sort: 0 - } - const result = await getDictTreeByCode(resDictTree) - const allOptions = convertToOptions(result.data as Dict.ResDictTree[]) - // 提取第二层节点 - allOptions.forEach(option => { - if (option.children && option.children.length > 0) { - secondLevelOptions.push(...option.children) - } - }) - } if (sign == 'add') { resetFormContent() @@ -810,6 +793,9 @@ const open = async (sign: string, data: Plan.ReqPlan, currentMode: string, plan: formContent.sourceIds = pqSourceList.value[0]?.id ?? '' formContent.datasourceIds = dictStore.getDictData('Datasource')[0]?.code ?? '' formContent.dataRule = dictStore.getDictData('Data_Rule')[0]?.id ?? '' + + + } else { //编辑时先给表单赋值(这会没接收被检设备),需要手动再给被检设备复制后整体表单赋值 @@ -925,6 +911,16 @@ const open = async (sign: string, data: Plan.ReqPlan, currentMode: string, plan: pqToArray() //将对象转为数组 + + //比对式测试项下拉框 + if (mode.value == '比对式') { + // 如果是编辑模式且已有误差体系ID,则加载对应的测试项 + if (formContent.errorSysId) { + await loadTestItemsForErrorSys(formContent.errorSysId); + } + } + + if (mode.value != '比对式') { selectByMode.value = false // 将 formContent.sourceIds 从数组转换为字符串 @@ -961,6 +957,63 @@ const open = async (sign: string, data: Plan.ReqPlan, currentMode: string, plan: dialogVisible.value = true } +// 误差体系选择变化时的处理函数 +const handleErrorSysChange = async (value: string) => { + // 清空测试项选择 + formContent.testItems = []; + + // 如果是比对式模式且选择了误差体系 + if (mode.value === '比对式' && value) { + try { + const res = await getPqErrSysTestItemList({ errorSysId: value }); + // 清空原有选项 + secondLevelOptions.length = 0; + + if (res.data) { + // 将返回的键值对对象转换为下拉选项格式 + Object.keys(res.data).forEach(key => { + secondLevelOptions.push({ + value: key, + label: res.data[key] + }); + }); + } + } catch (error) { + console.error('获取测试项失败:', error); + // 发生错误时清空选项 + secondLevelOptions.length = 0; + } + } else { + // 如果没有选择误差体系,清空测试项选项 + secondLevelOptions.length = 0; + } +} + + +// 根据误差体系ID加载测试项(用于初始化) +const loadTestItemsForErrorSys = async (errorSysId: string) => { + if (!errorSysId) return; + + try { + const res = await getPqErrSysTestItemList({ errorSysId: errorSysId }); + // 清空原有选项 + secondLevelOptions.length = 0; + + if (res.data) { + // 将返回的键值对对象转换为下拉选项格式 + Object.keys(res.data).forEach(key => { + secondLevelOptions.push({ + value: key, + label: res.data[key] + }); + }); + } + } catch (error) { + console.error('获取测试项失败:', error); + secondLevelOptions.length = 0; + } +} + // 转换函数 const convertToOptions = (dictTree: Dict.ResDictTree[]): CascaderOption[] => { return dictTree.map(item => ({