云
昨天 346a988f537228ae44731cd31007f1412b482e83
src/views/basicData/mdm/data.ts
@@ -9,7 +9,6 @@
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';
@@ -22,24 +21,6 @@
// 缓存仓库列表
let warehouseListCache: any[] | null = null;
let warehouseListPromise: Promise<any[]> | null = null;
/** 将扁平分类列表转为 TreeSelect 所需的树形结构 */
export function buildCategoryTree(list: any[]): any[] {
  const map = new Map<number, any>();
  const roots: any[] = [];
  for (const item of list) {
    map.set(item.id, { label: item.name, value: item.id, children: [] });
  }
  for (const item of list) {
    const node = map.get(item.id)!;
    if (item.parentId && map.has(item.parentId)) {
      map.get(item.parentId)!.children.push(node);
    } else {
      roots.push(node);
    }
  }
  return roots;
}
/** 获取单位列表(带缓存) */
async function getUnitListCached() {
@@ -82,7 +63,7 @@
}
/** 新增/修改的表单 */
export function useFormSchema(formApi?: VbenFormApi, categoryTreeData: any[] = []): VbenFormSchema[] {
export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
  return [
    {
      component: "Input",
@@ -95,12 +76,12 @@
    {
      component: "Input",
      fieldName: "code",
      label: "物料编码",
      label: "品种编码",
      componentProps: {
        maxLength: 64,
        placeholder: "请输入物料编码",
        placeholder: "请输入品种编码",
      },
      rules: z.string().min(1, '物料编码不能为空').max(64),
      rules: z.string().min(1, '品种编码不能为空').max(64),
      suffix: () =>
        h(
          Button,
@@ -119,24 +100,11 @@
    {
      component: "Input",
      fieldName: "name",
      label: "物料名称",
      label: "品种名称",
      componentProps: {
        placeholder: "请输入物料名称",
        placeholder: "请输入品种名称",
      },
      rules: "required",
    },
    {
      component: "TreeSelect",
      fieldName: "categoryId",
      label: "物料分类",
      rules: "selectRequired",
      componentProps: {
        placeholder: "请选择物料分类",
        allowClear: true,
        treeDefaultExpandAll: true,
        treeData: categoryTreeData,
        fieldNames: { label: 'label', value: 'value', children: 'children' },
      },
    },
    {
      component: "Input",
@@ -158,56 +126,6 @@
        api: getUnitListCached,
        labelField: "name",
        valueField: "id",
      },
    },
    {
      component: "ApiSelect",
      fieldName: "unitMeasureId2",
      label: "辅单位1",
      formItemClass: "col-span-1",
      componentProps: {
        placeholder: "请选择辅单位1",
        allowClear: true,
        api: getUnitListCached,
        labelField: "name",
        valueField: "id",
      },
    },
    {
      component: "InputNumber",
      fieldName: "unitMeasureRate1",
      label: "辅单位1换算比率",
      formItemClass: "col-span-1",
      componentProps: {
        class: "!w-full",
        min: 0,
        precision: 6,
        placeholder: "请输入换算比率",
      },
    },
    {
      component: "ApiSelect",
      fieldName: "unitMeasureId3",
      label: "辅单位2",
      formItemClass: "col-span-1",
      componentProps: {
        placeholder: "请选择辅单位2",
        allowClear: true,
        api: getUnitListCached,
        labelField: "name",
        valueField: "id",
      },
    },
    {
      component: "InputNumber",
      fieldName: "unitMeasureRate2",
      label: "辅单位2换算比率",
      formItemClass: "col-span-1",
      componentProps: {
        class: "!w-full",
        min: 0,
        precision: 6,
        placeholder: "请输入换算比率",
      },
    },
    {
@@ -237,113 +155,6 @@
      },
    },
    {
      component: "Input",
      fieldName: "barCode",
      label: "条码",
      componentProps: {
        placeholder: "请输入条码",
      },
    },
    {
      component: "InputNumber",
      fieldName: "purchasePrice",
      label: "采购价",
      componentProps: {
        class: "!w-full",
        min: 0,
        precision: 2,
        placeholder: "请输入采购价",
      },
    },
    {
      component: "InputNumber",
      fieldName: "salesPrice",
      label: "销售价",
      componentProps: {
        class: "!w-full",
        min: 0,
        precision: 2,
        placeholder: "请输入销售价",
      },
    },
    {
      component: "InputNumber",
      fieldName: "costPrice",
      label: "成本价",
      componentProps: {
        class: "!w-full",
        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: "请输入最高库存",
      },
    },
    {
      component: 'Switch',
      fieldName: 'isBatchManaged',
      label: '批次管理',
      defaultValue: false,
      componentProps: {
        class: "w-auto",
        checkedChildren: "是",
        unCheckedChildren: "否",
      },
      rules: z.boolean().default(false),
    },
    {
      component: "InputNumber",
      fieldName: "expiryDay",
      label: "有效期(天)",
      componentProps: {
        class: "!w-full",
        min: 0,
        placeholder: "请输入有效期",
      },
    },
    {
      component: 'Switch',
      fieldName: 'syncMes',
      label: '同步到MES',
      defaultValue: true,
      componentProps: {
        checkedChildren: '是',
        unCheckedChildren: '否',
      },
      rules: z.boolean().default(true),
    },
    {
      component: "RadioGroup",
      fieldName: "status",
      label: "状态",
@@ -354,136 +165,6 @@
      },
      rules: z.number().default(CommonStatusEnum.ENABLE),
    },
    {
      component: "Textarea",
      fieldName: "remark",
      label: "备注",
      formItemClass: "col-span-2",
      componentProps: {
        placeholder: "请输入备注",
        rows: 3,
      },
    },
    // ===== 批次属性配置(isBatchManaged = true 时显示) =====
    {
      component: "Divider",
      fieldName: "batchConfigDivider",
      label: "批次属性配置",
      formItemClass: "col-span-2",
      componentProps: {
        orientation: "left",
        plain: true,
      },
      dependencies: {
        triggerFields: ["isBatchManaged"],
        show: (values) => values.isBatchManaged === true,
      },
    },
    {
      component: "Switch",
      fieldName: "produceDateFlag",
      label: "生产日期必填",
      defaultValue: false,
      componentProps: {
        class: "w-auto",
        checkedChildren: "是",
        unCheckedChildren: "否",
      },
      dependencies: {
        triggerFields: ["isBatchManaged"],
        show: (values) => values.isBatchManaged === true,
      },
    },
    {
      component: "Switch",
      fieldName: "expireDateFlag",
      label: "有效期必填",
      defaultValue: false,
      componentProps: {
        class: "w-auto",
        checkedChildren: "是",
        unCheckedChildren: "否",
      },
      dependencies: {
        triggerFields: ["isBatchManaged"],
        show: (values) => values.isBatchManaged === true,
      },
    },
    {
      component: "Switch",
      fieldName: "receiptDateFlag",
      label: "入库日期必填",
      defaultValue: false,
      componentProps: {
        class: "w-auto",
        checkedChildren: "是",
        unCheckedChildren: "否",
      },
      dependencies: {
        triggerFields: ["isBatchManaged"],
        show: (values) => values.isBatchManaged === true,
      },
    },
    {
      component: "Switch",
      fieldName: "vendorFlag",
      label: "供应商必填",
      defaultValue: false,
      componentProps: {
        class: "w-auto",
        checkedChildren: "是",
        unCheckedChildren: "否",
      },
      dependencies: {
        triggerFields: ["isBatchManaged"],
        show: (values) => values.isBatchManaged === true,
      },
    },
    {
      component: "Switch",
      fieldName: "purchaseOrderCodeFlag",
      label: "采购订单号必填",
      defaultValue: false,
      componentProps: {
        class: "w-auto",
        checkedChildren: "是",
        unCheckedChildren: "否",
      },
      dependencies: {
        triggerFields: ["isBatchManaged"],
        show: (values) => values.isBatchManaged === true,
      },
    },
    {
      component: "Switch",
      fieldName: "lotNumberFlag",
      label: "生产批号必填",
      defaultValue: false,
      componentProps: {
        class: "w-auto",
        checkedChildren: "是",
        unCheckedChildren: "否",
      },
      dependencies: {
        triggerFields: ["isBatchManaged"],
        show: (values) => values.isBatchManaged === true,
      },
    },
    {
      component: "Switch",
      fieldName: "qualityStatusFlag",
      label: "质量状态必填",
      defaultValue: false,
      componentProps: {
        class: "w-auto",
        checkedChildren: "是",
        unCheckedChildren: "否",
      },
      dependencies: {
        triggerFields: ["isBatchManaged"],
        show: (values) => values.isBatchManaged === true,
      },
    },
  ];
}
@@ -492,19 +173,19 @@
  return [
    {
      fieldName: "code",
      label: "物料编码",
      label: "品种编码",
      component: "Input",
      componentProps: {
        placeholder: "请输入物料编码",
        placeholder: "请输入品种编码",
        allowClear: true,
      },
    },
    {
      fieldName: "name",
      label: "物料名称",
      label: "品种名称",
      component: "Input",
      componentProps: {
        placeholder: "请输入物料名称",
        placeholder: "请输入品种名称",
        allowClear: true,
      },
    },
@@ -527,12 +208,12 @@
    { type: "checkbox", width: 40 },
    {
      field: "code",
      title: "物料编码",
      title: "品种编码",
      minWidth: 120,
    },
    {
      field: "name",
      title: "物料名称",
      title: "品种名称",
      minWidth: 180,
    },
    {
@@ -541,35 +222,9 @@
      minWidth: 150,
    },
    {
      field: "categoryName",
      title: "物料分类",
      minWidth: 120,
      slots: { default: "categoryName" },
    },
    {
      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",
@@ -577,40 +232,10 @@
      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: "createTime",
      title: "创建时间",
      minWidth: 180,
      formatter: "formatDateTime",
    },
    {
      field: "isBatchManaged",
      title: "批次管理",
      width: 80,
      fixed: "right",
      slots: { default: "isBatchManaged" },
    },
    {
      field: "syncedMes",
      title: "同步状态",
      width: 100,
      fixed: "right",
      slots: { default: "syncedMes" },
    },
    {
      field: "status",