zhangwencui
2026-07-10 5783abee4e8c6ba1fc525545cf2a41ffe3e01926
src/views/basicData/mdm/data.ts
@@ -5,6 +5,8 @@
import { getDictOptions } from '#/packages/effects/hooks/src';
import { z } from '#/adapter/form';
import { getUnitPage } from '#/api/mdm/unit';
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';
/** 物料类型选项 */
export const ITEM_TYPE_OPTIONS = [
@@ -13,6 +15,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,12 +62,15 @@
      rules: 'required',
    },
    {
      component: 'Input',
      fieldName: 'barCode',
      label: '条码',
      component: 'RadioGroup',
      fieldName: 'itemType',
      label: '物料类型',
      componentProps: {
        placeholder: '请输入条码',
        options: ITEM_TYPE_OPTIONS,
        buttonStyle: 'solid',
        optionType: 'button',
      },
      rules: 'required',
    },
    {
      component: 'Input',
@@ -60,47 +81,97 @@
      },
    },
    {
      component: 'TreeSelect',
      fieldName: 'categoryId',
      label: '物料分类',
      componentProps: {
        placeholder: '请选择物料分类',
        allowClear: true,
        treeData: [],
        fieldNames: { label: 'name', value: 'id', children: 'children' },
      },
    },
    {
      component: 'Select',
      component: 'ApiSelect',
      fieldName: 'unitMeasureId',
      label: '计量单位',
      rules: 'required',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请选择计量单位',
        allowClear: true,
        options: [],
        fieldNames: { label: 'name', value: 'id' },
        api: async () => {
          const res = await getUnitPage({ pageNo: 1, pageSize: 100, status: 0 });
          return res.list || [];
        },
        labelField: 'name',
        valueField: 'id',
      },
    },
    {
      component: 'Select',
      fieldName: 'brandId',
      label: '品牌',
      component: 'ApiSelect',
      fieldName: 'unitMeasureId2',
      label: '辅单位1',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请选择品牌',
        placeholder: '请选择辅单位1',
        allowClear: true,
        options: [],
        fieldNames: { label: 'name', value: 'id' },
        api: async () => {
          const res = await getUnitPage({ pageNo: 1, pageSize: 100, status: 0 });
          return res.list || [];
        },
        labelField: 'name',
        valueField: 'id',
      },
    },
    {
      component: 'Select',
      fieldName: 'itemType',
      label: '物料类型',
      component: 'InputNumber',
      fieldName: 'unitMeasureRate1',
      label: '辅单位1换算比率',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请选择物料类型',
        options: ITEM_TYPE_OPTIONS,
        class: '!w-full',
        min: 0,
        precision: 6,
        placeholder: '请输入换算比率',
      },
      rules: 'required',
    },
    {
      component: 'ApiSelect',
      fieldName: 'unitMeasureId3',
      label: '辅单位2',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请选择辅单位2',
        allowClear: true,
        api: async () => {
          const res = await getUnitPage({ pageNo: 1, pageSize: 100, status: 0 });
          return res.list || [];
        },
        labelField: 'name',
        valueField: 'id',
      },
    },
    {
      component: 'InputNumber',
      fieldName: 'unitMeasureRate2',
      label: '辅单位2换算比率',
      formItemClass: 'col-span-1',
      componentProps: {
        class: '!w-full',
        min: 0,
        precision: 6,
        placeholder: '请输入换算比率',
      },
    },
    {
      component: 'ApiSelect',
      fieldName: 'warehouseId',
      label: '默认仓库',
      componentProps: {
        placeholder: '请选择默认仓库',
        allowClear: true,
        api: getWarehouseSimpleList,
        labelField: 'name',
        valueField: 'id',
      },
    },
    {
      component: 'Input',
      fieldName: 'barCode',
      label: '条码',
      componentProps: {
        placeholder: '请输入条码',
      },
    },
    {
      component: 'InputNumber',
@@ -173,10 +244,11 @@
      fieldName: 'isBatchManaged',
      label: '批次管理',
      componentProps: {
        class: 'w-auto',
        checkedChildren: '是',
        unCheckedChildren: '否',
      },
      rules: z.boolean().default(false),
      rules: z.boolean().default(true),
    },
    {
      component: 'InputNumber',
@@ -203,6 +275,7 @@
      component: 'Textarea',
      fieldName: 'remark',
      label: '备注',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入备注',
        rows: 3,
@@ -230,17 +303,6 @@
      componentProps: {
        placeholder: '请输入物料名称',
        allowClear: true,
      },
    },
    {
      fieldName: 'categoryId',
      label: '物料分类',
      component: 'TreeSelect',
      componentProps: {
        placeholder: '请选择物料分类',
        allowClear: true,
        treeData: [],
        fieldNames: { label: 'name', value: 'id', children: 'children' },
      },
    },
    {
@@ -286,23 +348,40 @@
      minWidth: 150,
    },
    {
      field: 'categoryName',
      title: '分类',
      minWidth: 100,
    },
    {
      field: 'unitMeasureName',
      title: '单位',
      minWidth: 80,
    },
    {
      field: 'unitMeasureName2',
      title: '辅单位1',
      minWidth: 80,
    },
    {
      field: 'unitMeasureRate1',
      title: '辅单位1换算比率',
      minWidth: 130,
    },
    {
      field: 'unitMeasureName3',
      title: '辅单位2',
      minWidth: 80,
    },
    {
      field: 'unitMeasureRate2',
      title: '辅单位2换算比率',
      minWidth: 130,
    },
    {
      field: 'warehouseName',
      title: '默认仓库',
      minWidth: 100,
    },
    {
      field: 'itemType',
      title: '物料类型',
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.MDM_ITEM_TYPE },
      },
      slots: { default: 'itemType' },
    },
    {
      field: 'purchasePrice',
@@ -348,4 +427,4 @@
      slots: { default: 'actions' },
    },
  ];
}
}