From 08b86cccfc8227ab065ee913f809609ef708486d Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期五, 21 八月 2026 09:59:21 +0800
Subject: [PATCH] 物料管理/物料分类/计量单位增加 Excel 导入功能
---
src/views/basicData/mdm/data.ts | 191 ++++++++++++++++++++++++++++++++++++++---------
1 files changed, 153 insertions(+), 38 deletions(-)
diff --git a/src/views/basicData/mdm/data.ts b/src/views/basicData/mdm/data.ts
index bbde65a..ca625c3 100644
--- a/src/views/basicData/mdm/data.ts
+++ b/src/views/basicData/mdm/data.ts
@@ -1,16 +1,45 @@
-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 { 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;
+
+/** 灏嗘墎骞冲垎绫诲垪琛ㄨ浆涓� 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() {
@@ -29,8 +58,31 @@
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, categoryTreeData: any[] = []): VbenFormSchema[] {
return [
{
component: "Input",
@@ -45,9 +97,24 @@
fieldName: "code",
label: "鐗╂枡缂栫爜",
componentProps: {
+ 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",
@@ -59,19 +126,16 @@
rules: "required",
},
{
- component: "ApiSelect",
+ component: "TreeSelect",
fieldName: "categoryId",
label: "鐗╂枡鍒嗙被",
rules: "selectRequired",
componentProps: {
placeholder: "璇烽�夋嫨鐗╂枡鍒嗙被",
allowClear: true,
- api: async () => {
- const res = await getItemTypeSimpleList();
- return res || [];
- },
- labelField: "name",
- valueField: "id",
+ treeDefaultExpandAll: true,
+ treeData: categoryTreeData,
+ fieldNames: { label: 'label', value: 'value', children: 'children' },
},
},
{
@@ -147,11 +211,29 @@
},
},
{
- component: 'Input',
+ component: 'ApiSelect',
fieldName: 'warehouseId',
label: '榛樿浠撳簱',
componentProps: {
- placeholder: '璇疯緭鍏ラ粯璁や粨搴揑D',
+ 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,
},
},
{
@@ -241,17 +323,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: "鏈夋晥鏈�(澶�)",
@@ -260,6 +331,17 @@
min: 0,
placeholder: "璇疯緭鍏ユ湁鏁堟湡",
},
+ },
+ {
+ component: 'Switch',
+ fieldName: 'syncMes',
+ label: '鍚屾鍒癕ES',
+ defaultValue: true,
+ componentProps: {
+ checkedChildren: '鏄�',
+ unCheckedChildren: '鍚�',
+ },
+ rules: z.boolean().default(true),
},
{
component: "RadioGroup",
@@ -511,27 +593,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",
@@ -539,3 +630,27 @@
},
];
}
+
+/** 鐗╂枡瀵煎叆鐨勮〃鍗� */
+export function useImportFormSchema(): VbenFormSchema[] {
+ return [
+ {
+ fieldName: 'file',
+ label: '鐗╂枡鏁版嵁',
+ component: 'Upload',
+ rules: 'required',
+ help: '浠呭厑璁稿鍏� xls銆亁lsx 鏍煎紡鏂囦欢',
+ },
+ {
+ fieldName: 'updateSupport',
+ label: '鏄惁瑕嗙洊',
+ component: 'Switch',
+ componentProps: {
+ checkedChildren: '鏄�',
+ unCheckedChildren: '鍚�',
+ },
+ rules: z.boolean().default(false),
+ help: '鏄惁鏇存柊宸茬粡瀛樺湪鐨勭墿鏂欐暟鎹�',
+ },
+ ];
+}
--
Gitblit v1.9.3