feat(wms):增加 warehouse 模块的迁移
parent
80fa8b74e8
commit
19b5f38e23
|
|
@ -0,0 +1,57 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace WmsWarehouseApi {
|
||||
/** WMS 仓库 */
|
||||
export interface Warehouse {
|
||||
id?: number;
|
||||
code?: string;
|
||||
name?: string;
|
||||
remark?: string;
|
||||
sort?: number;
|
||||
createTime?: Date;
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询仓库分页 */
|
||||
export function getWarehousePage(params: PageParam) {
|
||||
return requestClient.get<PageResult<WmsWarehouseApi.Warehouse>>(
|
||||
'/wms/warehouse/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询仓库精简列表 */
|
||||
export function getWarehouseSimpleList() {
|
||||
return requestClient.get<WmsWarehouseApi.Warehouse[]>(
|
||||
'/wms/warehouse/simple-list',
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询仓库详情 */
|
||||
export function getWarehouse(id: number) {
|
||||
return requestClient.get<WmsWarehouseApi.Warehouse>(
|
||||
`/wms/warehouse/get?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 新增仓库 */
|
||||
export function createWarehouse(data: WmsWarehouseApi.Warehouse) {
|
||||
return requestClient.post('/wms/warehouse/create', data);
|
||||
}
|
||||
|
||||
/** 修改仓库 */
|
||||
export function updateWarehouse(data: WmsWarehouseApi.Warehouse) {
|
||||
return requestClient.put('/wms/warehouse/update', data);
|
||||
}
|
||||
|
||||
/** 删除仓库 */
|
||||
export function deleteWarehouse(id: number) {
|
||||
return requestClient.delete(`/wms/warehouse/delete?id=${id}`);
|
||||
}
|
||||
|
||||
/** 导出仓库 */
|
||||
export function exportWarehouse(params: any) {
|
||||
return requestClient.download('/wms/warehouse/export-excel', { params });
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
export { default as WmsWarehouseSelect } from './warehouse-select.vue';
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
<script lang="ts" setup>
|
||||
import type { SelectValue } from 'ant-design-vue/es/select';
|
||||
|
||||
import type { WmsWarehouseApi } from '#/api/wms/md/warehouse';
|
||||
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { Select } from 'ant-design-vue';
|
||||
|
||||
import { getWarehouseSimpleList } from '#/api/wms/md/warehouse';
|
||||
|
||||
defineOptions({ name: 'WmsWarehouseSelect', inheritAttrs: false });
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
allowClear?: boolean;
|
||||
disabled?: boolean;
|
||||
modelValue?: number;
|
||||
placeholder?: string;
|
||||
}>(),
|
||||
{
|
||||
allowClear: true,
|
||||
disabled: false,
|
||||
modelValue: undefined,
|
||||
placeholder: '请选择仓库',
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
change: [warehouse: undefined | WmsWarehouseApi.Warehouse];
|
||||
'update:modelValue': [value: number | undefined];
|
||||
}>();
|
||||
|
||||
const loading = ref(false);
|
||||
const warehouseList = ref<WmsWarehouseApi.Warehouse[]>([]);
|
||||
|
||||
const options = computed(() =>
|
||||
warehouseList.value
|
||||
.filter((warehouse) => warehouse.id !== undefined)
|
||||
.map((warehouse) => ({
|
||||
label: warehouse.name,
|
||||
value: warehouse.id,
|
||||
})),
|
||||
);
|
||||
|
||||
/** 选中变化 */
|
||||
function handleChange(value: SelectValue) {
|
||||
const warehouseId = typeof value === 'number' ? value : undefined;
|
||||
emit('update:modelValue', warehouseId);
|
||||
emit(
|
||||
'change',
|
||||
warehouseList.value.find((warehouse) => warehouse.id === warehouseId),
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询仓库精简列表 */
|
||||
async function getList() {
|
||||
loading.value = true;
|
||||
try {
|
||||
warehouseList.value = await getWarehouseSimpleList();
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Select
|
||||
v-bind="$attrs"
|
||||
:allow-clear="allowClear"
|
||||
:disabled="disabled"
|
||||
:loading="loading"
|
||||
:options="options"
|
||||
:placeholder="placeholder"
|
||||
:value="modelValue"
|
||||
class="w-full"
|
||||
option-filter-prop="label"
|
||||
show-search
|
||||
@change="handleChange"
|
||||
/>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { generateWmsCode } from '#/views/wms/utils/constants';
|
||||
|
||||
/** 新增/修改仓库的表单 */
|
||||
export function useFormSchema(formApi?: any): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '仓库名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
maxLength: 50,
|
||||
placeholder: '请输入仓库名称',
|
||||
},
|
||||
rules: z.string().min(1, '仓库名称不能为空').max(50),
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '仓库编号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
maxLength: 20,
|
||||
placeholder: '请输入仓库编号',
|
||||
},
|
||||
rules: z.string().min(1, '仓库编号不能为空').max(20),
|
||||
suffix: () => {
|
||||
return h(
|
||||
Button,
|
||||
{
|
||||
type: 'default',
|
||||
onClick: () => {
|
||||
formApi?.setFieldValue('code', generateWmsCode('W'));
|
||||
},
|
||||
},
|
||||
{ default: () => '生成' },
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'sort',
|
||||
label: '排序',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
min: 0,
|
||||
},
|
||||
rules: z.number().default(0),
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
maxLength: 255,
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '仓库名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入仓库名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '仓库编号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入仓库编号',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'name',
|
||||
title: '仓库名称',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'code',
|
||||
title: '仓库编号',
|
||||
minWidth: 140,
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 220,
|
||||
},
|
||||
{
|
||||
field: 'sort',
|
||||
title: '排序',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { WmsWarehouseApi } from '#/api/wms/md/warehouse';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteWarehouse,
|
||||
exportWarehouse,
|
||||
getWarehousePage,
|
||||
} from '#/api/wms/md/warehouse';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
defineOptions({ name: 'WmsWarehouse' });
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 创建仓库 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 编辑仓库 */
|
||||
function handleEdit(row: WmsWarehouseApi.Warehouse) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除仓库 */
|
||||
async function handleDelete(row: WmsWarehouseApi.Warehouse) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteWarehouse(row.id!);
|
||||
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出仓库 */
|
||||
async function handleExport() {
|
||||
const data = await exportWarehouse(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '仓库.xls', source: data });
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getWarehousePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<WmsWarehouseApi.Warehouse>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【基础】仓库"
|
||||
url="https://doc.iocoder.cn/wms/md/warehouse/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<FormModal @success="handleRefresh" />
|
||||
<Grid table-title="仓库列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['仓库']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['wms:warehouse:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['wms:warehouse:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['wms:warehouse:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['wms:warehouse:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
<script lang="ts" setup>
|
||||
import type { WmsWarehouseApi } from '#/api/wms/md/warehouse';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createWarehouse,
|
||||
getWarehouse,
|
||||
updateWarehouse,
|
||||
} from '#/api/wms/md/warehouse';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
defineOptions({ name: 'WmsWarehouseForm' });
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<WmsWarehouseApi.Warehouse>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['仓库'])
|
||||
: $t('ui.actionTitle.create', ['仓库']);
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 80,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: [],
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
/** 表单 schema 需要 formApi 引用,所以通过 setState 设置 schema */
|
||||
formApi.setState({ schema: useFormSchema(formApi) });
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as WmsWarehouseApi.Warehouse;
|
||||
try {
|
||||
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<WmsWarehouseApi.Warehouse>();
|
||||
if (!data || !data.id) {
|
||||
await formApi.setValues({ sort: 0 });
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getWarehouse(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-1/3">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/** 单据状态枚举 */
|
||||
export const OrderStatusEnum = {
|
||||
PREPARE: 0, // 草稿
|
||||
FINISHED: 4, // 已完成
|
||||
CANCELED: 5, // 已作废
|
||||
} as const;
|
||||
|
||||
/** 可修改的单据状态 */
|
||||
export const OrderUpdateStatusList: number[] = [OrderStatusEnum.PREPARE];
|
||||
|
||||
/** 可删除的单据状态 */
|
||||
export const OrderDeleteStatusList: number[] = [
|
||||
OrderStatusEnum.PREPARE,
|
||||
OrderStatusEnum.CANCELED,
|
||||
];
|
||||
|
||||
/** 往来企业类型枚举 */
|
||||
export const MerchantTypeEnum = {
|
||||
CUSTOMER: 1, // 客户
|
||||
SUPPLIER: 2, // 供应商
|
||||
CUSTOMER_SUPPLIER: 3, // 客户/供应商
|
||||
} as const;
|
||||
|
||||
/** 供应商类型的往来企业 */
|
||||
export const SupplierMerchantTypeList = [
|
||||
MerchantTypeEnum.SUPPLIER,
|
||||
MerchantTypeEnum.CUSTOMER_SUPPLIER,
|
||||
];
|
||||
|
||||
/** 客户类型的往来企业 */
|
||||
export const CustomerMerchantTypeList = [
|
||||
MerchantTypeEnum.CUSTOMER,
|
||||
MerchantTypeEnum.CUSTOMER_SUPPLIER,
|
||||
];
|
||||
|
||||
/**
|
||||
* 生成 WMS 编号 / 条码。
|
||||
*
|
||||
* @param prefix 可选前缀,按业务域区分编号种类。
|
||||
* @returns 前缀 + 8 位随机数字串。
|
||||
*/
|
||||
export function generateWmsCode(prefix = ''): string {
|
||||
let result = '';
|
||||
for (let i = 0; i < 8; i++) {
|
||||
result += Math.floor(Math.random() * 10).toString();
|
||||
}
|
||||
return prefix + result;
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
import type { PageParam, PageResult } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace WmsWarehouseApi {
|
||||
/** WMS 仓库 */
|
||||
export interface Warehouse {
|
||||
id?: number;
|
||||
code?: string;
|
||||
name?: string;
|
||||
remark?: string;
|
||||
sort?: number;
|
||||
createTime?: Date;
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询仓库分页 */
|
||||
export function getWarehousePage(params: PageParam) {
|
||||
return requestClient.get<PageResult<WmsWarehouseApi.Warehouse>>(
|
||||
'/wms/warehouse/page',
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询仓库精简列表 */
|
||||
export function getWarehouseSimpleList() {
|
||||
return requestClient.get<WmsWarehouseApi.Warehouse[]>(
|
||||
'/wms/warehouse/simple-list',
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询仓库详情 */
|
||||
export function getWarehouse(id: number) {
|
||||
return requestClient.get<WmsWarehouseApi.Warehouse>(
|
||||
`/wms/warehouse/get?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 新增仓库 */
|
||||
export function createWarehouse(data: WmsWarehouseApi.Warehouse) {
|
||||
return requestClient.post('/wms/warehouse/create', data);
|
||||
}
|
||||
|
||||
/** 修改仓库 */
|
||||
export function updateWarehouse(data: WmsWarehouseApi.Warehouse) {
|
||||
return requestClient.put('/wms/warehouse/update', data);
|
||||
}
|
||||
|
||||
/** 删除仓库 */
|
||||
export function deleteWarehouse(id: number) {
|
||||
return requestClient.delete(`/wms/warehouse/delete?id=${id}`);
|
||||
}
|
||||
|
||||
/** 导出仓库 */
|
||||
export function exportWarehouse(params: any) {
|
||||
return requestClient.download('/wms/warehouse/export-excel', { params });
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
export { default as WmsWarehouseSelect } from './warehouse-select.vue';
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
<script lang="ts" setup>
|
||||
import type { WmsWarehouseApi } from '#/api/wms/md/warehouse';
|
||||
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { ElOption, ElSelect } from 'element-plus';
|
||||
|
||||
import { getWarehouseSimpleList } from '#/api/wms/md/warehouse';
|
||||
|
||||
defineOptions({ name: 'WmsWarehouseSelect', inheritAttrs: false });
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
clearable?: boolean;
|
||||
disabled?: boolean;
|
||||
modelValue?: number;
|
||||
placeholder?: string;
|
||||
}>(),
|
||||
{
|
||||
clearable: true,
|
||||
disabled: false,
|
||||
modelValue: undefined,
|
||||
placeholder: '请选择仓库',
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
change: [warehouse: undefined | WmsWarehouseApi.Warehouse];
|
||||
'update:modelValue': [value: number | undefined];
|
||||
}>();
|
||||
|
||||
const loading = ref(false);
|
||||
const warehouseList = ref<WmsWarehouseApi.Warehouse[]>([]);
|
||||
|
||||
const options = computed(() =>
|
||||
warehouseList.value
|
||||
.filter((warehouse) => warehouse.id !== undefined)
|
||||
.map((warehouse) => ({
|
||||
label: warehouse.name,
|
||||
value: warehouse.id!,
|
||||
})),
|
||||
);
|
||||
|
||||
/** 选中变化 */
|
||||
function handleChange(value: number | string | undefined) {
|
||||
const warehouseId = typeof value === 'number' ? value : undefined;
|
||||
emit('update:modelValue', warehouseId);
|
||||
emit(
|
||||
'change',
|
||||
warehouseList.value.find((warehouse) => warehouse.id === warehouseId),
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询仓库精简列表 */
|
||||
async function getList() {
|
||||
loading.value = true;
|
||||
try {
|
||||
warehouseList.value = await getWarehouseSimpleList();
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ElSelect
|
||||
v-bind="$attrs"
|
||||
:clearable="clearable"
|
||||
:disabled="disabled"
|
||||
:loading="loading"
|
||||
:model-value="modelValue"
|
||||
:placeholder="placeholder"
|
||||
class="w-full"
|
||||
filterable
|
||||
@change="handleChange"
|
||||
>
|
||||
<ElOption
|
||||
v-for="option in options"
|
||||
:key="option.value"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { h } from 'vue';
|
||||
|
||||
import { ElButton } from 'element-plus';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { generateWmsCode } from '#/views/wms/utils/constants';
|
||||
|
||||
/** 新增/修改仓库的表单 */
|
||||
export function useFormSchema(formApi?: any): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '仓库名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
maxLength: 50,
|
||||
placeholder: '请输入仓库名称',
|
||||
},
|
||||
rules: z.string().min(1, '仓库名称不能为空').max(50),
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '仓库编号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
maxLength: 20,
|
||||
placeholder: '请输入仓库编号',
|
||||
},
|
||||
rules: z.string().min(1, '仓库编号不能为空').max(20),
|
||||
suffix: () => {
|
||||
return h(
|
||||
ElButton,
|
||||
{
|
||||
type: 'default',
|
||||
onClick: () => {
|
||||
formApi?.setFieldValue('code', generateWmsCode('W'));
|
||||
},
|
||||
},
|
||||
{ default: () => '生成' },
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'sort',
|
||||
label: '排序',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
class: '!w-full',
|
||||
controlsPosition: 'right',
|
||||
min: 0,
|
||||
},
|
||||
rules: z.number().default(0),
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
maxLength: 255,
|
||||
placeholder: '请输入备注',
|
||||
rows: 3,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '仓库名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入仓库名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '仓库编号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
clearable: true,
|
||||
placeholder: '请输入仓库编号',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'name',
|
||||
title: '仓库名称',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'code',
|
||||
title: '仓库编号',
|
||||
minWidth: 140,
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 220,
|
||||
},
|
||||
{
|
||||
field: 'sort',
|
||||
title: '排序',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 160,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { WmsWarehouseApi } from '#/api/wms/md/warehouse';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteWarehouse,
|
||||
exportWarehouse,
|
||||
getWarehousePage,
|
||||
} from '#/api/wms/md/warehouse';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
defineOptions({ name: 'WmsWarehouse' });
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 创建仓库 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 编辑仓库 */
|
||||
function handleEdit(row: WmsWarehouseApi.Warehouse) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除仓库 */
|
||||
async function handleDelete(row: WmsWarehouseApi.Warehouse) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.name]),
|
||||
});
|
||||
try {
|
||||
await deleteWarehouse(row.id!);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** 导出仓库 */
|
||||
async function handleExport() {
|
||||
const data = await exportWarehouse(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '仓库.xls', source: data });
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getWarehousePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<WmsWarehouseApi.Warehouse>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【基础】仓库"
|
||||
url="https://doc.iocoder.cn/wms/md/warehouse/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<FormModal @success="handleRefresh" />
|
||||
<Grid table-title="仓库列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['仓库']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['wms:warehouse:create'],
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['wms:warehouse:export'],
|
||||
onClick: handleExport,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'primary',
|
||||
link: true,
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['wms:warehouse:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['wms:warehouse:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
<script lang="ts" setup>
|
||||
import type { WmsWarehouseApi } from '#/api/wms/md/warehouse';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createWarehouse,
|
||||
getWarehouse,
|
||||
updateWarehouse,
|
||||
} from '#/api/wms/md/warehouse';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
defineOptions({ name: 'WmsWarehouseForm' });
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<WmsWarehouseApi.Warehouse>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['仓库'])
|
||||
: $t('ui.actionTitle.create', ['仓库']);
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 80,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: [],
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
/** 表单 schema 需要 formApi 引用,所以通过 setState 设置 schema */
|
||||
formApi.setState({ schema: useFormSchema(formApi) });
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as WmsWarehouseApi.Warehouse;
|
||||
try {
|
||||
await (formData.value?.id
|
||||
? updateWarehouse(data)
|
||||
: createWarehouse(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
const data = modalApi.getData<WmsWarehouseApi.Warehouse>();
|
||||
if (!data || !data.id) {
|
||||
await formApi.setValues({ sort: 0 });
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getWarehouse(data.id);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle" class="w-1/3">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* 生成 WMS 编号 / 条码。
|
||||
*
|
||||
* @param prefix 可选前缀,按业务域区分编号种类。
|
||||
* @returns 前缀 + 8 位随机数字串。
|
||||
*/
|
||||
export function generateWmsCode(prefix = ''): string {
|
||||
let result = '';
|
||||
for (let i = 0; i < 8; i++) {
|
||||
result += Math.floor(Math.random() * 10).toString();
|
||||
}
|
||||
return prefix + result;
|
||||
}
|
||||
Loading…
Reference in New Issue