From 346a988f537228ae44731cd31007f1412b482e83 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 19 十月 2026 16:32:10 +0800
Subject: [PATCH] refactor(mdm): 移除物料主数据中废弃的字段配置

---
 src/views/basicData/mdm/data.ts |  394 +++++++++++++++-----------------------------------------
 1 files changed, 107 insertions(+), 287 deletions(-)

diff --git a/src/views/basicData/mdm/data.ts b/src/views/basicData/mdm/data.ts
index f294908..490572c 100644
--- a/src/views/basicData/mdm/data.ts
+++ b/src/views/basicData/mdm/data.ts
@@ -1,38 +1,69 @@
-import type { VbenFormSchema } from "#/adapter/form";
+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 { getUnitPage } from '#/api/mdm/unit';
+import { getWarehouseSimpleList } from '#/api/mes/wm/warehouse';
 
-/** 鐗╂枡绫诲瀷閫夐」 */
-export const ITEM_TYPE_OPTIONS = [
-  { label: "鍘熸枡", value: 1 },
-  { label: "鍗婃垚鍝�", value: 2 },
-  { label: "鎴愬搧", value: 3 },
-  { label: "杈呮枡", value: 4 },
-];
+import { Button } from 'ant-design-vue';
 
-/** 鐗╂枡绫诲瀷鏄犲皠 */
-export const ITEM_TYPE_MAP: Record<number, string> = {
-  1: "鍘熸枡",
-  2: "鍗婃垚鍝�",
-  3: "鎴愬搧",
-  4: "杈呮枡",
-};
+// 缂撳瓨鍗曚綅鍒楄〃
+let unitListCache: any[] | null = null;
+let unitListPromise: Promise<any[]> | null = null;
 
-/** 鐗╂枡绫诲瀷棰滆壊鏄犲皠 */
-export const ITEM_TYPE_COLOR_MAP: Record<number, string> = {
-  1: "green",
-  2: "orange",
-  3: "blue",
-  4: "purple",
-};
+// 缂撳瓨浠撳簱鍒楄〃
+let warehouseListCache: any[] | null = null;
+let warehouseListPromise: Promise<any[]> | null = null;
+
+/** 鑾峰彇鍗曚綅鍒楄〃锛堝甫缂撳瓨锛� */
+async function getUnitListCached() {
+  if (unitListCache) {
+    return unitListCache;
+  }
+  if (unitListPromise) {
+    return unitListPromise;
+  }
+  unitListPromise = getUnitPage({ pageNo: 1, pageSize: 100, status: 0 }).then((res) => {
+    unitListCache = res.list || [];
+    return unitListCache;
+  }).finally(() => {
+    unitListPromise = null;
+  });
+  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(): VbenFormSchema[] {
+export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
   return [
     {
       component: "Input",
@@ -45,29 +76,33 @@
     {
       component: "Input",
       fieldName: "code",
-      label: "鐗╂枡缂栫爜",
+      label: "鍝佺缂栫爜",
       componentProps: {
-        placeholder: "璇疯緭鍏ョ墿鏂欑紪鐮�",
+        maxLength: 64,
+        placeholder: "璇疯緭鍏ュ搧绉嶇紪鐮�",
       },
-      rules: "required",
+      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: () => '鐢熸垚' },
+        ),
     },
     {
       component: "Input",
       fieldName: "name",
-      label: "鐗╂枡鍚嶇О",
+      label: "鍝佺鍚嶇О",
       componentProps: {
-        placeholder: "璇疯緭鍏ョ墿鏂欏悕绉�",
-      },
-      rules: "required",
-    },
-    {
-      component: "RadioGroup",
-      fieldName: "itemType",
-      label: "鐗╂枡绫诲瀷",
-      componentProps: {
-        options: ITEM_TYPE_OPTIONS,
-        buttonStyle: "solid",
-        optionType: "button",
+        placeholder: "璇疯緭鍏ュ搧绉嶅悕绉�",
       },
       rules: "required",
     },
@@ -88,183 +123,35 @@
       componentProps: {
         placeholder: "璇烽�夋嫨璁¢噺鍗曚綅",
         allowClear: true,
-        api: async () => {
-          const res = await getUnitPage({ pageNo: 1, pageSize: 100, status: 0 });
-          return res.list || [];
-        },
+        api: getUnitListCached,
         labelField: "name",
         valueField: "id",
       },
     },
     {
-      component: "ApiSelect",
-      fieldName: "unitMeasureId2",
-      label: "杈呭崟浣�1",
-      formItemClass: "col-span-1",
+      component: 'ApiSelect',
+      fieldName: 'warehouseId',
+      label: '榛樿浠撳簱',
       componentProps: {
-        placeholder: "璇烽�夋嫨杈呭崟浣�1",
+        placeholder: '璇烽�夋嫨榛樿浠撳簱',
         allowClear: true,
-        api: async () => {
-          const res = await getUnitPage({ pageNo: 1, pageSize: 100, status: 0 });
-          return res.list || [];
+        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);
         },
-        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: 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: 'Input',
-      fieldName: 'warehouseId',
-      label: '榛樿浠撳簱',
-      componentProps: {
-        placeholder: '璇疯緭鍏ラ粯璁や粨搴揑D',
-      },
-    },
-    {
-      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: true,
-      componentProps: {
-        class: "w-auto",
-        checkedChildren: "鏄�",
-        unCheckedChildren: "鍚�",
-      },
-      rules: z.boolean().default(true),
-    },
-    {
-      component: "Switch",
-      fieldName: "syncMes",
-      label: "鍚屾鍒� MES",
-      componentProps: {
-        class: "w-auto",
-        checkedChildren: "鏄�",
-        unCheckedChildren: "鍚�",
-      },
-      rules: z.boolean().default(false),
-    },
-    {
-      component: "InputNumber",
-      fieldName: "expiryDay",
-      label: "鏈夋晥鏈�(澶�)",
-      componentProps: {
-        class: "!w-full",
-        min: 0,
-        placeholder: "璇疯緭鍏ユ湁鏁堟湡",
+      fieldName: 'warehouseCode',
+      dependencies: {
+        triggerFields: [''],
+        show: () => false,
       },
     },
     {
@@ -278,16 +165,6 @@
       },
       rules: z.number().default(CommonStatusEnum.ENABLE),
     },
-    {
-      component: "Textarea",
-      fieldName: "remark",
-      label: "澶囨敞",
-      formItemClass: "col-span-2",
-      componentProps: {
-        placeholder: "璇疯緭鍏ュ娉�",
-        rows: 3,
-      },
-    },
   ];
 }
 
@@ -296,30 +173,20 @@
   return [
     {
       fieldName: "code",
-      label: "鐗╂枡缂栫爜",
+      label: "鍝佺缂栫爜",
       component: "Input",
       componentProps: {
-        placeholder: "璇疯緭鍏ョ墿鏂欑紪鐮�",
+        placeholder: "璇疯緭鍏ュ搧绉嶇紪鐮�",
         allowClear: true,
       },
     },
     {
       fieldName: "name",
-      label: "鐗╂枡鍚嶇О",
+      label: "鍝佺鍚嶇О",
       component: "Input",
       componentProps: {
-        placeholder: "璇疯緭鍏ョ墿鏂欏悕绉�",
+        placeholder: "璇疯緭鍏ュ搧绉嶅悕绉�",
         allowClear: true,
-      },
-    },
-    {
-      fieldName: "itemType",
-      label: "鐗╂枡绫诲瀷",
-      component: "Select",
-      componentProps: {
-        placeholder: "璇烽�夋嫨鐗╂枡绫诲瀷",
-        allowClear: true,
-        options: ITEM_TYPE_OPTIONS,
       },
     },
     {
@@ -341,12 +208,12 @@
     { type: "checkbox", width: 40 },
     {
       field: "code",
-      title: "鐗╂枡缂栫爜",
+      title: "鍝佺缂栫爜",
       minWidth: 120,
     },
     {
       field: "name",
-      title: "鐗╂枡鍚嶇О",
+      title: "鍝佺鍚嶇О",
       minWidth: 180,
     },
     {
@@ -360,66 +227,9 @@
       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,
-      slots: { default: "itemType" },
-    },
-    {
-      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: "isBatchManaged",
-      title: "鎵规绠$悊",
-      minWidth: 80,
-      slots: { default: "isBatchManaged" },
-    },
-    {
-      field: "status",
-      title: "鐘舵��",
-      minWidth: 80,
-      cellRender: {
-        name: "CellDict",
-        props: { type: DICT_TYPE.COMMON_STATUS },
-      },
     },
     {
       field: "createTime",
@@ -428,6 +238,16 @@
       formatter: "formatDateTime",
     },
     {
+      field: "status",
+      title: "鐘舵��",
+      width: 80,
+      fixed: "right",
+      cellRender: {
+        name: "CellDict",
+        props: { type: DICT_TYPE.COMMON_STATUS },
+      },
+    },
+    {
       title: "鎿嶄綔",
       width: 180,
       fixed: "right",

--
Gitblit v1.9.3