昨天 c1a9bd81744474027abc73abcc778fd2798ec7ec
src/views/mes/qc/indicatorresult/components/form.vue
@@ -6,7 +6,7 @@
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { MesQcResultValueType } from '@vben/constants';
import { MesQcIndicatorItemType, MesQcResultValueType } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import {
@@ -43,11 +43,49 @@
const items = ref<MesQcIndicatorResultApi.IndicatorResultDetail[]>([]);
const ctxData = ref<CtxData>();
const getTitle = computed(() =>
  formType.value === 'update'
const isDetail = computed(() => formType.value === 'detail');
const getTitle = computed(() => {
  if (formType.value === 'detail') {
    return $t('ui.actionTitle.view', ['检验结果']);
  }
  return formType.value === 'update'
    ? $t('ui.actionTitle.edit', ['检验结果'])
    : $t('ui.actionTitle.create', ['检验结果']),
);
    : $t('ui.actionTitle.create', ['检验结果']);
});
/** 分组树平铺为录入项列表:分组节点不展示,仅展开其子项 */
function flattenRecordItems(
  nodes: MesQcIndicatorResultApi.IndicatorResultDetail[] | undefined,
  out: MesQcIndicatorResultApi.IndicatorResultDetail[],
) {
  (nodes ?? []).forEach((node) => {
    if (node.itemType === MesQcIndicatorItemType.GROUP) {
      flattenRecordItems(node.children, out);
      return;
    }
    out.push({
      ...node,
      valueNumber:
        (node.valueType === MesQcResultValueType.FLOAT ||
          node.valueType === MesQcResultValueType.INTEGER) &&
        node.value != null
          ? Number(node.value)
          : undefined,
    });
  });
}
/** 详情展示值:平行测量多批次顿号合并,兼容旧数据单值 */
function measureText(item: MesQcIndicatorResultApi.IndicatorResultDetail) {
  const vals = (item.measures ?? [])
    .map((m) => m.value)
    .filter((v) => v !== undefined && v !== null && v !== '');
  if (vals.length > 0) {
    return vals.join('、');
  }
  return item.value ?? '';
}
const [Form, formApi] = useVbenForm({
  commonConfig: {
@@ -135,6 +173,9 @@
    const data = modalApi.getData<CtxData>();
    ctxData.value = data;
    formType.value = data.formType;
    const detailMode = data.formType === 'detail';
    formApi.setDisabled(detailMode);
    modalApi.setState({ showConfirmButton: !detailMode });
    modalApi.lock();
    try {
      const detail = await getIndicatorResultDetail(
@@ -142,16 +183,10 @@
        data.qcType,
        data.id,
      );
      // 回填数值字段(用于 InputNumber 绑定)
      items.value = (detail.items ?? []).map((item) => ({
        ...item,
        valueNumber:
          (item.valueType === MesQcResultValueType.FLOAT ||
            item.valueType === MesQcResultValueType.INTEGER) &&
          item.value !== null
            ? Number(item.value)
            : undefined,
      }));
      // 分组树平铺 + 回填数值字段(用于 InputNumber 绑定)
      const flat: MesQcIndicatorResultApi.IndicatorResultDetail[] = [];
      flattenRecordItems(detail.items, flat);
      items.value = flat;
      // 设置到 values
      await formApi.setValues({
        id: detail.id,
@@ -179,10 +214,17 @@
          class="mb-2"
        >
          <AForm.Item
            :label="`检测项${index + 1}:${item.indicatorName ?? ''}`"
            :label="`检测项${index + 1}:${item.indicatorName ?? ''}${
              isDetail && item.unitText ? `(${item.unitText})` : ''
            }`"
          >
            <Input
              v-if="isDetail"
              :value="measureText(item) || '/'"
              disabled
            />
            <InputNumber
              v-if="
              v-else-if="
                item.valueType === MesQcResultValueType.FLOAT ||
                item.valueType === MesQcResultValueType.INTEGER
              "