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 { 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 { z } from '#/adapter/form';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
return [
@@ -39,9 +41,10 @@ export function useFormSchema(): VbenFormSchema[] {
component: 'RadioGroup',
componentProps: {
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
buttonStyle: 'solid',
optionType: 'button',
},
rules: 'required',
defaultValue: 0,
rules: z.number().default(CommonStatusEnum.ENABLE),
},
{
fieldName: 'warehousePrice',
@@ -51,7 +54,6 @@ export function useFormSchema(): VbenFormSchema[] {
placeholder: '请输入仓储费,单位:元/天/KG',
min: 0,
precision: 2,
class: 'w-full',
},
},
{
@@ -62,7 +64,6 @@ export function useFormSchema(): VbenFormSchema[] {
placeholder: '请输入搬运费,单位:元',
min: 0,
precision: 2,
class: 'w-full',
},
},
{
@@ -80,10 +81,8 @@ export function useFormSchema(): VbenFormSchema[] {
componentProps: {
placeholder: '请输入排序',
precision: 0,
class: 'w-full',
},
rules: 'required',
defaultValue: 0,
},
{
fieldName: 'remark',
@@ -91,9 +90,7 @@ export function useFormSchema(): VbenFormSchema[] {
component: 'Textarea',
componentProps: {
placeholder: '请输入备注',
rows: 3,
},
formItemClass: 'col-span-2',
},
];
}
@@ -144,34 +141,30 @@ export function useGridColumns<T = ErpWarehouseApi.Warehouse>(
},
{
field: 'warehousePrice',
title: '仓储费(元)',
width: 120,
cellRender: {
name: 'CellMoney',
},
title: '仓储费',
minWidth: 120,
formatter: 'formatAmount2',
},
{
field: 'truckagePrice',
title: '搬运费(元)',
width: 120,
cellRender: {
name: 'CellMoney',
},
title: '搬运费',
minWidth: 120,
formatter: 'formatAmount2',
},
{
field: 'principal',
title: '负责人',
width: 100,
minWidth: 100,
},
{
field: 'sort',
title: '排序',
width: 80,
minWidth: 80,
},
{
field: 'status',
title: '状态',
width: 100,
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },
@@ -180,7 +173,7 @@ export function useGridColumns<T = ErpWarehouseApi.Warehouse>(
{
field: 'defaultStatus',
title: '是否默认',
width: 100,
minWidth: 100,
cellRender: {
attrs: { beforeChange: onDefaultStatusChange },
name: 'CellSwitch',
@@ -199,15 +192,12 @@ export function useGridColumns<T = ErpWarehouseApi.Warehouse>(
{
field: 'createTime',
title: '创建时间',
width: 180,
cellRender: {
name: 'CellDateTime',
},
minWidth: 180,
formatter: 'formatDateTime',
},
{
field: 'actions',
title: '操作',
width: 160,
width: 130,
fixed: 'right',
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 { 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';
@@ -23,18 +23,24 @@ import WarehouseForm from './modules/form.vue';
defineOptions({ name: 'ErpWarehouse' });
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
/** 添加仓库 */
/** 导出仓库 */
async function handleExport() {
const data = await exportWarehouse(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '仓库.xls', source: data });
}
/** 创建仓库 */
function handleCreate() {
formModalApi.setData({ type: 'create' }).open();
formModalApi.setData(null).open();
}
/** 编辑仓库 */
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 {
await deleteWarehouse(row.id!);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
onRefresh();
} catch {
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
handleRefresh();
} finally {
hideLoading();
}
}
@@ -60,15 +64,14 @@ async function handleDefaultStatusChange(
row: ErpWarehouseApi.Warehouse,
): Promise<boolean | undefined> {
return new Promise((resolve, reject) => {
const text = newStatus ? '开启' : '取消';
const text = newStatus ? '设置' : '取消';
confirm({
content: `确认要${text}"${row.name}"默认吗?`,
})
.then(async () => {
// 更新默认状态
await updateWarehouseDefaultStatus(row.id!, newStatus);
message.success(`${text}默认状态成功`);
message.success(`${text}默认成功`);
resolve(true);
})
.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({
connectedComponent: WarehouseForm,
destroyOnClose: true,
@@ -109,6 +106,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
@@ -127,7 +125,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
/>
</template>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="仓库列表">
<template #toolbar-tools>
<TableAction
@@ -154,14 +152,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
<TableAction
:actions="[
{
label: '编辑',
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['erp:warehouse:update'],
onClick: handleEdit.bind(null, row),
},
{
label: '删除',
label: $t('common.delete'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,

View File

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