feat:【antd】【erp 系统】warehouse 迁移

This commit is contained in:
YunaiV
2025-10-03 11:37:34 +08:00
parent 85b6d0c4d6
commit 2572824d1a
3 changed files with 57 additions and 76 deletions

View File

@@ -2,9 +2,11 @@ import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ErpWarehouseApi } from '#/api/erp/stock/warehouse'; import type { ErpWarehouseApi } from '#/api/erp/stock/warehouse';
import { DICT_TYPE } from '@vben/constants'; import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks'; import { getDictOptions } from '@vben/hooks';
import { z } from '#/adapter/form';
/** 新增/修改的表单 */ /** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
return [ return [
@@ -39,9 +41,10 @@ export function useFormSchema(): VbenFormSchema[] {
component: 'RadioGroup', component: 'RadioGroup',
componentProps: { componentProps: {
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'), options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
buttonStyle: 'solid',
optionType: 'button',
}, },
rules: 'required', rules: z.number().default(CommonStatusEnum.ENABLE),
defaultValue: 0,
}, },
{ {
fieldName: 'warehousePrice', fieldName: 'warehousePrice',
@@ -51,7 +54,6 @@ export function useFormSchema(): VbenFormSchema[] {
placeholder: '请输入仓储费,单位:元/天/KG', placeholder: '请输入仓储费,单位:元/天/KG',
min: 0, min: 0,
precision: 2, precision: 2,
class: 'w-full',
}, },
}, },
{ {
@@ -62,7 +64,6 @@ export function useFormSchema(): VbenFormSchema[] {
placeholder: '请输入搬运费,单位:元', placeholder: '请输入搬运费,单位:元',
min: 0, min: 0,
precision: 2, precision: 2,
class: 'w-full',
}, },
}, },
{ {
@@ -80,10 +81,8 @@ export function useFormSchema(): VbenFormSchema[] {
componentProps: { componentProps: {
placeholder: '请输入排序', placeholder: '请输入排序',
precision: 0, precision: 0,
class: 'w-full',
}, },
rules: 'required', rules: 'required',
defaultValue: 0,
}, },
{ {
fieldName: 'remark', fieldName: 'remark',
@@ -91,9 +90,7 @@ export function useFormSchema(): VbenFormSchema[] {
component: 'Textarea', component: 'Textarea',
componentProps: { componentProps: {
placeholder: '请输入备注', placeholder: '请输入备注',
rows: 3,
}, },
formItemClass: 'col-span-2',
}, },
]; ];
} }
@@ -144,34 +141,30 @@ export function useGridColumns<T = ErpWarehouseApi.Warehouse>(
}, },
{ {
field: 'warehousePrice', field: 'warehousePrice',
title: '仓储费(元)', title: '仓储费',
width: 120, minWidth: 120,
cellRender: { formatter: 'formatAmount2',
name: 'CellMoney',
},
}, },
{ {
field: 'truckagePrice', field: 'truckagePrice',
title: '搬运费(元)', title: '搬运费',
width: 120, minWidth: 120,
cellRender: { formatter: 'formatAmount2',
name: 'CellMoney',
},
}, },
{ {
field: 'principal', field: 'principal',
title: '负责人', title: '负责人',
width: 100, minWidth: 100,
}, },
{ {
field: 'sort', field: 'sort',
title: '排序', title: '排序',
width: 80, minWidth: 80,
}, },
{ {
field: 'status', field: 'status',
title: '状态', title: '状态',
width: 100, minWidth: 100,
cellRender: { cellRender: {
name: 'CellDict', name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS }, props: { type: DICT_TYPE.COMMON_STATUS },
@@ -180,7 +173,7 @@ export function useGridColumns<T = ErpWarehouseApi.Warehouse>(
{ {
field: 'defaultStatus', field: 'defaultStatus',
title: '是否默认', title: '是否默认',
width: 100, minWidth: 100,
cellRender: { cellRender: {
attrs: { beforeChange: onDefaultStatusChange }, attrs: { beforeChange: onDefaultStatusChange },
name: 'CellSwitch', name: 'CellSwitch',
@@ -199,15 +192,12 @@ export function useGridColumns<T = ErpWarehouseApi.Warehouse>(
{ {
field: 'createTime', field: 'createTime',
title: '创建时间', title: '创建时间',
width: 180, minWidth: 180,
cellRender: { formatter: 'formatDateTime',
name: 'CellDateTime',
},
}, },
{ {
field: 'actions',
title: '操作', title: '操作',
width: 160, width: 130,
fixed: 'right', fixed: 'right',
slots: { default: 'actions' }, slots: { default: 'actions' },
}, },

View File

@@ -3,7 +3,7 @@ import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ErpWarehouseApi } from '#/api/erp/stock/warehouse'; import type { ErpWarehouseApi } from '#/api/erp/stock/warehouse';
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui'; import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils'; import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
@@ -23,18 +23,24 @@ import WarehouseForm from './modules/form.vue';
defineOptions({ name: 'ErpWarehouse' }); defineOptions({ name: 'ErpWarehouse' });
/** 刷新表格 */ /** 刷新表格 */
function onRefresh() { function handleRefresh() {
gridApi.query(); gridApi.query();
} }
/** 添加仓库 */ /** 导出仓库 */
async function handleExport() {
const data = await exportWarehouse(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '仓库.xls', source: data });
}
/** 创建仓库 */
function handleCreate() { function handleCreate() {
formModalApi.setData({ type: 'create' }).open(); formModalApi.setData(null).open();
} }
/** 编辑仓库 */ /** 编辑仓库 */
function handleEdit(row: ErpWarehouseApi.Warehouse) { function handleEdit(row: ErpWarehouseApi.Warehouse) {
formModalApi.setData({ type: 'update', id: row.id }).open(); formModalApi.setData(row).open();
} }
/** 删除仓库 */ /** 删除仓库 */
@@ -45,11 +51,9 @@ async function handleDelete(row: ErpWarehouseApi.Warehouse) {
}); });
try { try {
await deleteWarehouse(row.id!); await deleteWarehouse(row.id!);
message.success({ message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
content: $t('ui.actionMessage.deleteSuccess', [row.name]), handleRefresh();
}); } finally {
onRefresh();
} catch {
hideLoading(); hideLoading();
} }
} }
@@ -60,15 +64,14 @@ async function handleDefaultStatusChange(
row: ErpWarehouseApi.Warehouse, row: ErpWarehouseApi.Warehouse,
): Promise<boolean | undefined> { ): Promise<boolean | undefined> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const text = newStatus ? '开启' : '取消'; const text = newStatus ? '设置' : '取消';
confirm({ confirm({
content: `确认要${text}"${row.name}"默认吗?`, content: `确认要${text}"${row.name}"默认吗?`,
}) })
.then(async () => { .then(async () => {
// 更新默认状态 // 更新默认状态
await updateWarehouseDefaultStatus(row.id!, newStatus); await updateWarehouseDefaultStatus(row.id!, newStatus);
message.success(`${text}默认状态成功`); message.success(`${text}默认成功`);
resolve(true); resolve(true);
}) })
.catch(() => { .catch(() => {
@@ -77,12 +80,6 @@ async function handleDefaultStatusChange(
}); });
} }
/** 导出仓库 */
async function handleExport() {
const data = await exportWarehouse(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '仓库.xls', source: data });
}
const [FormModal, formModalApi] = useVbenModal({ const [FormModal, formModalApi] = useVbenModal({
connectedComponent: WarehouseForm, connectedComponent: WarehouseForm,
destroyOnClose: true, destroyOnClose: true,
@@ -109,6 +106,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,
@@ -127,7 +125,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
/> />
</template> </template>
<FormModal @success="onRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="仓库列表"> <Grid table-title="仓库列表">
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
@@ -154,14 +152,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
<TableAction <TableAction
:actions="[ :actions="[
{ {
label: '编辑', label: $t('common.edit'),
type: 'link', type: 'link',
icon: ACTION_ICON.EDIT, icon: ACTION_ICON.EDIT,
auth: ['erp:warehouse:update'], auth: ['erp:warehouse:update'],
onClick: handleEdit.bind(null, row), onClick: handleEdit.bind(null, row),
}, },
{ {
label: '删除', label: $t('common.delete'),
type: 'link', type: 'link',
danger: true, danger: true,
icon: ACTION_ICON.DELETE, icon: ACTION_ICON.DELETE,

View File

@@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { ErpWarehouseApi } from '#/api/erp/stock/warehouse'; import type { ErpWarehouseApi } from '#/api/erp/stock/warehouse';
import { ref } from 'vue'; import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
@@ -18,9 +18,12 @@ import { $t } from '#/locales';
import { useFormSchema } from '../data'; import { useFormSchema } from '../data';
const emit = defineEmits(['success']); const emit = defineEmits(['success']);
const formData = ref<ErpWarehouseApi.Warehouse>();
const formType = ref<'create' | 'update'>('create'); const getTitle = computed(() => {
const warehouseId = ref<number>(); return formData.value?.id
? $t('ui.actionTitle.edit', ['仓库'])
: $t('ui.actionTitle.create', ['仓库']);
});
const [Form, formApi] = useVbenForm({ const [Form, formApi] = useVbenForm({
commonConfig: { commonConfig: {
@@ -45,51 +48,41 @@ const [Modal, modalApi] = useVbenModal({
// 提交表单 // 提交表单
const data = (await formApi.getValues()) as ErpWarehouseApi.Warehouse; const data = (await formApi.getValues()) as ErpWarehouseApi.Warehouse;
try { try {
if (formType.value === 'create') { await (formData.value?.id
await createWarehouse(data); ? updateWarehouse(data)
message.success($t('ui.actionMessage.createSuccess')); : createWarehouse(data));
} else {
await updateWarehouse(data);
message.success($t('ui.actionMessage.updateSuccess'));
}
// 关闭并提示 // 关闭并提示
await modalApi.close(); await modalApi.close();
emit('success'); emit('success');
message.success($t('ui.actionMessage.operationSuccess'));
} finally { } finally {
modalApi.unlock(); modalApi.unlock();
} }
}, },
async onOpenChange(isOpen: boolean) { async onOpenChange(isOpen: boolean) {
if (!isOpen) { if (!isOpen) {
formData.value = undefined;
return; return;
} }
// 加载数据 // 加载数据
const data = modalApi.getData<{ id?: number; type: 'create' | 'update' }>(); const data = modalApi.getData<ErpWarehouseApi.Warehouse>();
if (!data) { if (!data || !data.id) {
return; return;
} }
formType.value = data.type;
warehouseId.value = data.id;
modalApi.lock(); modalApi.lock();
try { try {
if (data.type === 'update' && data.id) { formData.value = await getWarehouse(data.id);
const warehouseData = await getWarehouse(data.id); // 设置到 values
await formApi.setValues(warehouseData); await formApi.setValues(formData.value);
}
} finally { } finally {
modalApi.unlock(); modalApi.unlock();
} }
}, },
}); });
defineExpose({
modalApi,
});
</script> </script>
<template> <template>
<Modal :title="formType === 'create' ? '新增仓库' : '编辑仓库'" class="w-3/5"> <Modal :title="getTitle" class="w-1/2">
<Form class="mx-4" /> <Form class="mx-4" />
</Modal> </Modal>
</template> </template>