云
2026-10-26 64a8cd04229f7b903913fc3dc7ef4aef267ac3bc
src/views/basicData/mdm/data.ts
@@ -1,19 +1,14 @@
import type { VbenFormApi, VbenFormSchema } from "#/adapter/form";
import type { VxeTableGridOptions } from "#/adapter/vxe-table";
import { h } from 'vue';
import { CommonStatusEnum, DICT_TYPE } from "#/packages/constants/src";
import { getDictOptions } from "#/packages/effects/hooks/src";
import { z } from '#/adapter/form';
import { generateAutoCode } from '#/api/mes/md/autocode/record';
import { MesAutoCodeRuleCode } from '@vben/constants';
import { getItemTypeSimpleList } from '#/api/mes/md/item/type';
import { getUnitPage } from '#/api/mdm/unit';
import { getWarehouseSimpleList } from '#/api/mes/wm/warehouse';
import { Button } from 'ant-design-vue';
// 缓存单位列表
let unitListCache: any[] | null = null;
@@ -95,26 +90,13 @@
    {
      component: "Input",
      fieldName: "code",
      label: "物料编码",
      label: "产品编号",
      componentProps: {
        maxLength: 64,
        placeholder: "请输入物料编码",
        placeholder: "选择产品类型并保存后自动生成",
        disabled: true,
      },
      rules: z.string().min(1, '物料编码不能为空').max(64),
      suffix: () =>
        h(
          Button,
          {
            type: 'default',
            onClick: async () => {
              const code = await generateAutoCode(
                MesAutoCodeRuleCode.MD_ITEM_CODE,
              );
              await formApi?.setFieldValue('code', code);
            },
          },
          { default: () => '生成' },
        ),
      help: "系统按产品类型自动生成九位编号,例如原材料 100100001",
    },
    {
      component: "Input",
@@ -136,6 +118,22 @@
        treeDefaultExpandAll: true,
        treeData: categoryTreeData,
        fieldNames: { label: 'label', value: 'value', children: 'children' },
      },
    },
    {
      component: 'Select',
      fieldName: 'itemType',
      label: '产品类型',
      rules: 'selectRequired',
      componentProps: {
        placeholder: '请选择产品类型',
        options: [
          { label: '原材料(1001)', value: 1 },
          { label: '半成品(1002)', value: 2 },
          { label: '成品(1003)', value: 3 },
          { label: '辅材(1004)', value: 4 },
          { label: '其他(1005)', value: 5 },
        ],
      },
    },
    {
@@ -245,6 +243,56 @@
      },
    },
    {
      component: 'Divider',
      fieldName: 'basicDataDivider',
      label: '基础数据',
      formItemClass: 'col-span-2',
      componentProps: { orientation: 'left', plain: true },
    },
    {
      component: 'Textarea',
      fieldName: 'technicalParameters',
      label: '技术参数',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入产品技术参数',
        rows: 4,
      },
    },
    {
      component: "InputNumber",
      fieldName: "safetyStock",
      label: "库存预警数量",
      componentProps: {
        class: "!w-full",
        min: 0,
        precision: 2,
        placeholder: "请输入库存预警数量",
      },
    },
    {
      component: "InputNumber",
      fieldName: "minStock",
      label: "最低库存",
      componentProps: {
        class: "!w-full",
        min: 0,
        precision: 2,
        placeholder: "请输入最低库存",
      },
    },
    {
      component: "InputNumber",
      fieldName: "maxStock",
      label: "最高库存",
      componentProps: {
        class: "!w-full",
        min: 0,
        precision: 2,
        placeholder: "请输入最高库存",
      },
    },
    {
      component: "InputNumber",
      fieldName: "purchasePrice",
      label: "采购价",
@@ -275,39 +323,6 @@
        min: 0,
        precision: 2,
        placeholder: "请输入成本价",
      },
    },
    {
      component: "InputNumber",
      fieldName: "safetyStock",
      label: "安全库存",
      componentProps: {
        class: "!w-full",
        min: 0,
        precision: 2,
        placeholder: "请输入安全库存",
      },
    },
    {
      component: "InputNumber",
      fieldName: "minStock",
      label: "最低库存",
      componentProps: {
        class: "!w-full",
        min: 0,
        precision: 2,
        placeholder: "请输入最低库存",
      },
    },
    {
      component: "InputNumber",
      fieldName: "maxStock",
      label: "最高库存",
      componentProps: {
        class: "!w-full",
        min: 0,
        precision: 2,
        placeholder: "请输入最高库存",
      },
    },
    {
@@ -492,7 +507,7 @@
  return [
    {
      fieldName: "code",
      label: "物料编码",
      label: "产品编号",
      component: "Input",
      componentProps: {
        placeholder: "请输入物料编码",
@@ -527,7 +542,7 @@
    { type: "checkbox", width: 40 },
    {
      field: "code",
      title: "物料编码",
      title: "产品编号",
      minWidth: 120,
    },
    {
@@ -551,52 +566,46 @@
      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,
    },
    // 辅单位1/辅单位1换算比率/辅单位2/辅单位2换算比率:物料列表不再展示(表单里仍可维护),需要恢复就取消注释
    // {
    //   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: "purchasePrice",
      title: "采购价",
      minWidth: 100,
      formatter: ({ cellValue }) => {
        return cellValue != null ? `¥${Number(cellValue).toFixed(2)}` : "";
      },
    },
    {
      field: "salesPrice",
      title: "销售价",
      minWidth: 100,
      formatter: ({ cellValue }) => {
        return cellValue != null ? `¥${Number(cellValue).toFixed(2)}` : "";
      },
    },
    // 销售价:物料列表不再展示,需要恢复就取消注释
    // {
    //   field: "salesPrice",
    //   title: "销售价",
    //   minWidth: 100,
    //   formatter: ({ cellValue }) => {
    //     return cellValue != null ? `¥${Number(cellValue).toFixed(2)}` : "";
    //   },
    // },
    {
      field: "createTime",
      title: "创建时间",
      minWidth: 180,
      formatter: "formatDateTime",
      formatter: 'formatDate',
    },
    {
      field: "isBatchManaged",