2 天以前 46624ce480a3c14da21f39cc4ad5f7eecea2bb1e
src/views/basicData/mdm/data.ts
@@ -9,14 +9,18 @@
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;
let unitListPromise: Promise<any[]> | null = null;
// 缓存仓库列表
let warehouseListCache: any[] | null = null;
let warehouseListPromise: Promise<any[]> | null = null;
/** 获取单位列表(带缓存) */
async function getUnitListCached() {
@@ -35,6 +39,29 @@
  return unitListPromise;
}
/** 获取仓库列表(带缓存) */
async function getWarehouseListCached() {
  if (warehouseListCache) {
    return warehouseListCache;
  }
  if (warehouseListPromise) {
    return warehouseListPromise;
  }
  warehouseListPromise = getWarehouseSimpleList().then((res) => {
    warehouseListCache = res || [];
    return warehouseListCache;
  }).finally(() => {
    warehouseListPromise = null;
  });
  return warehouseListPromise;
}
/** 清除单位列表缓存 */
export function clearUnitListCache() {
  unitListCache = null;
  warehouseListCache = null;
}
/** 新增/修改的表单 */
export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
  return [
@@ -49,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,
@@ -73,27 +100,11 @@
    {
      component: "Input",
      fieldName: "name",
      label: "物料名称",
      label: "品种名称",
      componentProps: {
        placeholder: "请输入物料名称",
        placeholder: "请输入品种名称",
      },
      rules: "required",
    },
    {
      component: "ApiSelect",
      fieldName: "categoryId",
      label: "物料分类",
      rules: "selectRequired",
      componentProps: {
        placeholder: "请选择物料分类",
        allowClear: true,
        api: async () => {
          const res = await getItemTypeSimpleList();
          return res || [];
        },
        labelField: "name",
        valueField: "id",
      },
    },
    {
      component: "Input",
@@ -168,11 +179,29 @@
      },
    },
    {
      component: 'Input',
      component: 'ApiSelect',
      fieldName: 'warehouseId',
      label: '默认仓库',
      componentProps: {
        placeholder: '请输入默认仓库ID',
        placeholder: '请选择默认仓库',
        allowClear: true,
        api: getWarehouseListCached,
        labelField: 'name',
        valueField: 'id',
        onChange: async (value: number | undefined) => {
          const code = value
            ? ((await getWarehouseListCached()).find((w: any) => w.id === value)?.code || '')
            : '';
          formApi?.setFieldValue('warehouseCode', code);
        },
      },
    },
    {
      component: 'Input',
      fieldName: 'warehouseCode',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
@@ -181,17 +210,6 @@
      label: "条码",
      componentProps: {
        placeholder: "请输入条码",
      },
    },
    {
      component: "InputNumber",
      fieldName: "purchasePrice",
      label: "采购价",
      componentProps: {
        class: "!w-full",
        min: 0,
        precision: 2,
        placeholder: "请输入采购价",
      },
    },
    {
@@ -262,17 +280,6 @@
      rules: z.boolean().default(false),
    },
    {
      component: "Switch",
      fieldName: "syncMes",
      label: "同步到 MES",
      componentProps: {
        class: "w-auto",
        checkedChildren: "是",
        unCheckedChildren: "否",
      },
      rules: z.boolean().default(false),
    },
    {
      component: "InputNumber",
      fieldName: "expiryDay",
      label: "有效期(天)",
@@ -281,6 +288,17 @@
        min: 0,
        placeholder: "请输入有效期",
      },
    },
    {
      component: 'Switch',
      fieldName: 'syncMes',
      label: '同步到MES',
      defaultValue: true,
      componentProps: {
        checkedChildren: '是',
        unCheckedChildren: '否',
      },
      rules: z.boolean().default(true),
    },
    {
      component: "RadioGroup",
@@ -431,19 +449,19 @@
  return [
    {
      fieldName: "code",
      label: "物料编码",
      label: "品种编码",
      component: "Input",
      componentProps: {
        placeholder: "请输入物料编码",
        placeholder: "请输入品种编码",
        allowClear: true,
      },
    },
    {
      fieldName: "name",
      label: "物料名称",
      label: "品种名称",
      component: "Input",
      componentProps: {
        placeholder: "请输入物料名称",
        placeholder: "请输入品种名称",
        allowClear: true,
      },
    },
@@ -466,24 +484,18 @@
    { type: "checkbox", width: 40 },
    {
      field: "code",
      title: "物料编码",
      title: "品种编码",
      minWidth: 120,
    },
    {
      field: "name",
      title: "物料名称",
      title: "品种名称",
      minWidth: 180,
    },
    {
      field: "specification",
      title: "规格型号",
      minWidth: 150,
    },
    {
      field: "categoryName",
      title: "物料分类",
      minWidth: 120,
      slots: { default: "categoryName" },
    },
    {
      field: "unitMeasureName",
@@ -516,14 +528,6 @@
      minWidth: 100,
    },
    {
      field: "purchasePrice",
      title: "采购价",
      minWidth: 100,
      formatter: ({ cellValue }) => {
        return cellValue != null ? `¥${Number(cellValue).toFixed(2)}` : "";
      },
    },
    {
      field: "salesPrice",
      title: "销售价",
      minWidth: 100,
@@ -532,27 +536,36 @@
      },
    },
    {
      field: "isBatchManaged",
      title: "批次管理",
      minWidth: 80,
      slots: { default: "isBatchManaged" },
    },
    {
      field: "status",
      title: "状态",
      minWidth: 80,
      cellRender: {
        name: "CellDict",
        props: { type: DICT_TYPE.COMMON_STATUS },
      },
    },
    {
      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",
      title: "状态",
      width: 80,
      fixed: "right",
      cellRender: {
        name: "CellDict",
        props: { type: DICT_TYPE.COMMON_STATUS },
      },
    },
    {
      title: "操作",
      width: 180,
      fixed: "right",