src/views/basicData/mdm/components/data.ts
@@ -2,8 +2,10 @@
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MdmItemApi } from '#/api/mdm/item';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { getItemTypeSimpleList } from '#/api/mes/md/item/type';
/** 物料选择弹窗搜索表单 */
export function useMdmItemSelectGridFormSchema(): VbenFormSchema[] {
@@ -27,30 +29,32 @@
      },
    },
    {
      fieldName: 'itemType',
      label: '物料类型',
      fieldName: 'categoryId',
      label: '物料分类',
      component: 'ApiSelect',
      componentProps: {
        placeholder: '请选择物料分类',
        allowClear: true,
        api: async () => {
          const res = await getItemTypeSimpleList();
          return res || [];
        },
        labelField: 'name',
        valueField: 'id',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        placeholder: '请选择状态',
        allowClear: true,
        placeholder: '请选择物料类型',
        options: [
          { label: '原料', value: 1 },
          { label: '半成品', value: 2 },
          { label: '成品', value: 3 },
          { label: '辅料', value: 4 },
        ],
        options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
      },
    },
  ];
}
/** 物料类型颜色映射 */
const itemTypeMap: Record<number, { label: string; color: string }> = {
  1: { label: '原料', color: 'green' },
  2: { label: '半成品', color: 'orange' },
  3: { label: '成品', color: 'blue' },
  4: { label: '辅料', color: 'purple' },
};
/** 物料选择弹窗列表字段 */
export function useMdmItemSelectGridColumns(
@@ -61,51 +65,45 @@
    {
      field: 'code',
      title: '物料编码',
      width: 180,
      minWidth: 120,
    },
    {
      field: 'name',
      title: '物料名称',
      minWidth: 160,
      minWidth: 180,
      align: 'left',
    },
    {
      field: 'specification',
      title: '规格型号',
      minWidth: 140,
      minWidth: 150,
      align: 'left',
    },
    {
      field: 'categoryId',
      title: '物料分类',
      minWidth: 120,
      align: 'center',
      slots: { default: 'categoryId' },
    },
    {
      field: 'unitMeasureName',
      title: '单位',
      width: 90,
      minWidth: 80,
      align: 'center',
    },
    {
      field: 'itemType',
      title: '物料类型',
      width: 110,
      align: 'center',
      formatter: ({ cellValue }: { cellValue: number }) => {
        const type = itemTypeMap[cellValue];
        return type ? type.label : '-';
      },
    },
    {
      field: 'isBatchManaged',
      title: '批次管理',
      width: 110,
      minWidth: 80,
      align: 'center',
      cellRender: {
        name: 'CellDict',
        props: { type: 'infra_boolean_string' },
      },
      slots: { default: 'isBatchManaged' },
    },
    {
      field: 'createTime',
      title: '创建时间',
      width: 180,
      formatter: 'formatDateTime',
      field: 'warehouseName',
      title: '默认仓库',
      minWidth: 100,
      align: 'center',
    },
  ];
}