gaoluyang
2026-07-01 3b430f42c1412422aa32412463533385bf4dd44e
src/views/basicData/mdm/data.ts
@@ -5,6 +5,7 @@
import { getDictOptions } from '#/packages/effects/hooks/src';
import { z } from '#/adapter/form';
import { getUnitPage } from '#/api/mdm/unit';
/** 物料类型选项 */
export const ITEM_TYPE_OPTIONS = [
@@ -13,6 +14,22 @@
  { label: '成品', value: 3 },
  { label: '辅料', value: 4 },
];
/** 物料类型映射 */
export const ITEM_TYPE_MAP: Record<number, string> = {
  1: '原料',
  2: '半成品',
  3: '成品',
  4: '辅料',
};
/** 物料类型颜色映射 */
export const ITEM_TYPE_COLOR_MAP: Record<number, string> = {
  1: 'green',
  2: 'orange',
  3: 'blue',
  4: 'purple',
};
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
@@ -44,63 +61,39 @@
      rules: 'required',
    },
    {
      component: 'RadioGroup',
      fieldName: 'itemType',
      label: '物料类型',
      componentProps: {
        options: ITEM_TYPE_OPTIONS,
        buttonStyle: 'solid',
        optionType: 'button',
      },
      rules: 'required',
    },
    {
      component: 'ApiSelect',
      fieldName: 'unitMeasureId',
      label: '计量单位',
      rules: 'required',
      componentProps: {
        placeholder: '请选择计量单位',
        allowClear: true,
        api: async () => {
          const res = await getUnitPage({ pageNo: 1, pageSize: 100, status: 0 });
          return res.list || [];
        },
        labelField: 'name',
        valueField: 'id',
      },
    },
    {
      component: 'Input',
      fieldName: 'barCode',
      label: '条码',
      componentProps: {
        placeholder: '请输入条码',
      },
    },
    {
      component: 'Input',
      fieldName: 'specification',
      label: '规格型号',
      componentProps: {
        placeholder: '请输入规格型号',
      },
    },
    {
      component: 'TreeSelect',
      fieldName: 'categoryId',
      label: '物料分类',
      componentProps: {
        placeholder: '请选择物料分类',
        allowClear: true,
        treeData: [],
        fieldNames: { label: 'name', value: 'id', children: 'children' },
      },
    },
    {
      component: 'Select',
      fieldName: 'unitMeasureId',
      label: '计量单位',
      componentProps: {
        placeholder: '请选择计量单位',
        allowClear: true,
        options: [],
        fieldNames: { label: 'name', value: 'id' },
      },
    },
    {
      component: 'Select',
      fieldName: 'brandId',
      label: '品牌',
      componentProps: {
        placeholder: '请选择品牌',
        allowClear: true,
        options: [],
        fieldNames: { label: 'name', value: 'id' },
      },
    },
    {
      component: 'Select',
      fieldName: 'itemType',
      label: '物料类型',
      componentProps: {
        placeholder: '请选择物料类型',
        options: ITEM_TYPE_OPTIONS,
      },
      rules: 'required',
    },
    {
      component: 'InputNumber',
@@ -177,7 +170,7 @@
        checkedChildren: '是',
        unCheckedChildren: '否',
      },
      rules: z.boolean().default(false),
      rules: z.boolean().default(true),
    },
    {
      component: 'InputNumber',
@@ -235,17 +228,6 @@
      },
    },
    {
      fieldName: 'categoryId',
      label: '物料分类',
      component: 'TreeSelect',
      componentProps: {
        placeholder: '请选择物料分类',
        allowClear: true,
        treeData: [],
        fieldNames: { label: 'name', value: 'id', children: 'children' },
      },
    },
    {
      fieldName: 'itemType',
      label: '物料类型',
      component: 'Select',
@@ -288,11 +270,6 @@
      minWidth: 150,
    },
    {
      field: 'categoryName',
      title: '分类',
      minWidth: 100,
    },
    {
      field: 'unitMeasureName',
      title: '单位',
      minWidth: 80,
@@ -301,10 +278,7 @@
      field: 'itemType',
      title: '物料类型',
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.MDM_ITEM_TYPE },
      },
      slots: { default: 'itemType' },
    },
    {
      field: 'purchasePrice',