diff --git a/src/api/mes/qc/indicatorresult/index.ts b/src/api/mes/qc/indicatorresult/index.ts index e169ccf92..113c2f500 100644 --- a/src/api/mes/qc/indicatorresult/index.ts +++ b/src/api/mes/qc/indicatorresult/index.ts @@ -10,13 +10,6 @@ export interface QcIndicatorResultVO { sn: string // 物资SN remark: string // 备注 createTime: Date // 创建时间 - // 关联查询字段 - qcCode: string // 质检单编号 - qcName: string // 质检单名称 - itemCode: string // 产品物料编码 - itemName: string // 产品物料名称 - itemSpecification: string // 规格型号 - unitName: string // 单位名称 // 子表 items: QcIndicatorResultDetailVO[] // 检验结果明细列表 } @@ -28,18 +21,10 @@ export interface QcIndicatorResultDetailVO { indicatorId: number // 检测指标ID value: string // 检测值(统一存为字符串) remark: string // 备注 - // 关联查询字段 - indicatorCode: string // 检测指标编码 + // 关联查询字段(来自 indicator) indicatorName: string // 检测指标名称 - indicatorType: string // 检测指标类型 - valueType: number // 质检值类型(关联查询) - valueSpecification: string // 值属性(关联查询) - toolName: string // 检测工具名称 - checkMethod: string // 检测方法 - standardValue: number // 标准值 - unitMeasureName: string // 计量单位名称 - maxThreshold: number // 误差上限 - minThreshold: number // 误差下限 + valueType: number // 质检值类型 + valueSpecification: string // 值属性 } // MES 检验结果 API @@ -49,9 +34,9 @@ export const QcIndicatorResultApi = { return await request.get({ url: `/mes/qc/indicator-result/page`, params }) }, - // 查询检验结果详情(含明细) - getResult: async (id: number) => { - return await request.get({ url: `/mes/qc/indicator-result/get?id=` + id }) + // 查询检验结果明细(含检测项模板):编辑传 id,新增不传 + getDetail: async (qcId: number, qcType: number, id?: number) => { + return await request.get({ url: `/mes/qc/indicator-result/get-detail`, params: { id, qcId, qcType } }) }, // 新增检验结果 @@ -67,10 +52,5 @@ export const QcIndicatorResultApi = { // 删除检验结果 deleteResult: async (id: number) => { return await request.delete({ url: `/mes/qc/indicator-result/delete?id=` + id }) - }, - - // 获取空值检测项模板(新建结果时用) - getDetailTemplate: async (qcId: number, qcType: number) => { - return await request.get({ url: `/mes/qc/indicator-result/detail-template`, params: { qcId, qcType } }) } } diff --git a/src/views/mes/qc/indicatorresult/components/QcIndicatorResultForm.vue b/src/views/mes/qc/indicatorresult/components/QcIndicatorResultForm.vue index e64fabc2f..0180587bf 100644 --- a/src/views/mes/qc/indicatorresult/components/QcIndicatorResultForm.vue +++ b/src/views/mes/qc/indicatorresult/components/QcIndicatorResultForm.vue @@ -39,23 +39,16 @@ - - - - - + @@ -66,10 +59,9 @@ - import { QcIndicatorResultApi } from '@/api/mes/qc/indicatorresult' -import { getDictOptions } from '@/utils/dict' +import { getStrDictOptions } from '@/utils/dict' import { MesQcResultValueType } from '@/views/mes/utils/constants' defineOptions({ name: 'QcIndicatorResultForm' }) @@ -109,16 +101,13 @@ const props = defineProps<{ qcType: number }>() -// TODO @AI:补全注释,参考 system user form.vue - const { t } = useI18n() const message = useMessage() -const dialogVisible = ref(false) -const dialogTitle = ref('') -const formLoading = ref(false) -const formType = ref('') - +const dialogVisible = ref(false) // 弹窗的是否展示 +const dialogTitle = ref('') // 弹窗的标题 +const formLoading = ref(false) // 表单的加载中 +const formType = ref('') // 表单的类型:create - 新增;update - 修改 const formData = ref({ id: undefined as number | undefined, code: undefined as string | undefined, @@ -127,11 +116,11 @@ const formData = ref({ sn: undefined as string | undefined, remark: undefined as string | undefined, items: [] as any[] -}) +}) // 表单数据 const formRules = reactive({ code: [{ required: true, message: '样品编号不能为空', trigger: 'blur' }] -}) -const formRef = ref() +}) // 表单校验规则 +const formRef = ref() // 表单 Ref /** 打开弹窗 */ const open = async (type: string, id?: number) => { @@ -139,34 +128,23 @@ const open = async (type: string, id?: number) => { dialogTitle.value = t('action.' + type) formType.value = type resetForm() - formData.value.qcId = props.qcId - formData.value.qcType = props.qcType - - if (type === 'update' && id) { - // 修改时加载已有数据(含明细) - formLoading.value = true - try { - formData.value = await QcIndicatorResultApi.getResult(id) - // 回填浮点/整数值用于 el-input-number 绑定 - // TODO @AI:是不是可以 include 判断,这样转化简单点; - formData.value.items?.forEach((item: any) => { - if (item.valueType === MesQcResultValueType.FLOAT && item.value != null) { - item.valueFloat = Number(item.value) - } else if (item.valueType === MesQcResultValueType.INTEGER && item.value != null) { - item.valueInteger = Number(item.value) - } - }) - } finally { - formLoading.value = false - } - } else { - // 新增时加载空值检测项模板 - formLoading.value = true - try { - formData.value.items = await QcIndicatorResultApi.getDetailTemplate(props.qcId, props.qcType) - } finally { - formLoading.value = false - } + // 加载数据 + formLoading.value = true + try { + formData.value = await QcIndicatorResultApi.getDetail(props.qcId, props.qcType, id) + formData.value.qcId = props.qcId + formData.value.qcType = props.qcType + // 回填数值用于 el-input-number 绑定 + formData.value.items?.forEach((item: any) => { + if ( + [MesQcResultValueType.FLOAT, MesQcResultValueType.INTEGER].includes(item.valueType) && + item.value != null + ) { + item.valueNumber = Number(item.value) + } + }) + } finally { + formLoading.value = false } } defineExpose({ open }) @@ -174,13 +152,13 @@ defineExpose({ open }) /** 提交表单 */ const emit = defineEmits(['success']) const submitForm = async () => { + // 校验表单 if (!formRef) return const valid = await formRef.value.validate() if (!valid) return formLoading.value = true try { - // 提交前将浮点/整数值统一转为 string value - // TODO @AI:不用转换,直接存储看看;后端自己来转换! + // 构建请求 const data = { ...formData.value } data.items = data.items.map((item: any) => { const submitItem: any = { @@ -188,15 +166,14 @@ const submitForm = async () => { indicatorId: item.indicatorId, remark: item.remark } - if (item.valueType === MesQcResultValueType.FLOAT) { - submitItem.value = item.valueFloat != null ? String(item.valueFloat) : undefined - } else if (item.valueType === MesQcResultValueType.INTEGER) { - submitItem.value = item.valueInteger != null ? String(item.valueInteger) : undefined + if ([MesQcResultValueType.FLOAT, MesQcResultValueType.INTEGER].includes(item.valueType)) { + submitItem.value = item.valueNumber != null ? String(item.valueNumber) : undefined } else { submitItem.value = item.value } return submitItem }) + // 提交请求 if (formType.value === 'create') { await QcIndicatorResultApi.createResult(data) message.success(t('common.createSuccess'))