feat: mall pick up store

pull/135/head^2
xingyu4j 2025-06-09 12:08:36 +08:00
parent 82a2674817
commit 84b51ed8bb
5 changed files with 568 additions and 26 deletions

View File

@ -35,6 +35,9 @@ export namespace MallDeliveryPickUpStoreApi {
/** 绑定自提店员请求 */
export interface BindStaffRequest {
id?: number;
/** 门店名称 */
name: string;
/** 门店编号 */
storeId: number;
/** 用户编号列表 */

View File

@ -0,0 +1,248 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { z } from '#/adapter/form';
import { getAreaTree } from '#/api/system/area';
import { getSimpleUserList } from '#/api/system/user';
import {
CommonStatusEnum,
DICT_TYPE,
getDictOptions,
getRangePickerDefaultProps,
} from '#/utils';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'id',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
component: 'ImageUpload',
fieldName: 'logo',
label: '门店logo',
componentProps: {
maxSize: 1,
},
rules: 'required',
},
{
component: 'Input',
fieldName: 'name',
label: '门店名称',
rules: 'required',
},
{
component: 'Input',
fieldName: 'phone',
label: '门店手机',
rules: 'mobileRequired',
},
{
component: 'Textarea',
fieldName: 'introduction',
label: '门店简介',
},
{
fieldName: 'areaId',
label: '地址',
component: 'ApiTreeSelect',
componentProps: {
api: () => getAreaTree(),
fieldNames: { label: 'name', value: 'id', children: 'children' },
},
},
{
component: 'Input',
fieldName: 'detailAddress',
label: '详细地址',
rules: 'required',
},
{
component: 'TimePicker',
fieldName: 'openingTime',
label: '营业开始时间',
rules: 'required',
},
{
component: 'TimePicker',
fieldName: 'closingTime',
label: '营业结束时间',
rules: 'required',
},
{
component: 'Input',
fieldName: 'longitude',
label: '经度',
rules: 'required',
},
{
component: 'Input',
fieldName: 'latitude',
label: '纬度',
rules: 'required',
},
{
component: 'Input',
fieldName: 'getGeo',
label: '获取经纬度',
},
{
fieldName: 'status',
label: '门店状态',
component: 'RadioGroup',
componentProps: {
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
buttonStyle: 'solid',
optionType: 'button',
},
rules: z.number().default(CommonStatusEnum.ENABLE),
},
];
}
/** 绑定店员的表单 */
export function useBindFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'id',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
component: 'Input',
fieldName: 'name',
label: '门店名称',
dependencies: {
triggerFields: ['id'],
disabled: () => true,
},
},
{
component: 'ApiSelect',
fieldName: 'verifyUserIds',
label: '门店店员',
rules: 'required',
componentProps: {
api: () => getSimpleUserList(),
fieldNames: { label: 'nickname', value: 'id' },
mode: 'tags',
allowClear: true,
},
},
{
component: 'Select',
fieldName: 'verifyUsers',
label: '店员列表',
rules: 'required',
componentProps: {
options: [],
mode: 'tags',
},
dependencies: {
triggerFields: ['verifyUserIds'],
trigger(values, form) {
form.setFieldValue('verifyUsers', values.verifyUserIds);
},
disabled: () => true,
},
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'phone',
label: '门店手机',
component: 'Input',
},
{
fieldName: 'name',
label: '门店名称',
component: 'Input',
},
{
fieldName: 'status',
label: '门店状态',
component: 'Select',
componentProps: {
allowClear: true,
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
},
},
{
fieldName: 'createTime',
label: '创建时间',
component: 'RangePicker',
componentProps: {
...getRangePickerDefaultProps(),
allowClear: true,
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: '编号',
},
{
field: 'logo',
title: '门店logo',
cellRender: {
name: 'CellImage',
},
},
{
field: 'name',
title: '门店名称',
},
{
field: 'phone',
title: '门店手机',
},
{
field: 'detailAddress',
title: '地址',
},
{
field: 'openingTime',
title: '营业时间',
formatter: ({ row }) => {
return `${row.openingTime} ~ ${row.closingTime}`;
},
},
{
field: 'status',
title: '开启状态',
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },
},
},
{
field: 'createTime',
title: '创建时间',
formatter: 'formatDateTime',
},
{
title: '操作',
width: 200,
fixed: 'right',
slots: { default: 'actions' },
},
];
}

View File

@ -1,34 +1,149 @@
<script lang="ts" setup>
import { Page } from '@vben/common-ui';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MallDeliveryPickUpStoreApi } from '#/api/mall/trade/delivery/pickUpStore';
import { Button } from 'ant-design-vue';
import { Page, useVbenModal } from '@vben/common-ui';
import { DocAlert } from '#/components/doc-alert';
import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteDeliveryPickUpStore,
getDeliveryPickUpStorePage,
} from '#/api/mall/trade/delivery/pickUpStore';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import BindForm from './modules/bind-form.vue';
import Form from './modules/form.vue';
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
const [BindFormModal, bindFormModalApi] = useVbenModal({
connectedComponent: BindForm,
destroyOnClose: true,
});
/** 刷新表格 */
function onRefresh() {
gridApi.query();
}
/** 创建门店 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑门店 */
function handleEdit(row: MallDeliveryPickUpStoreApi.PickUpStore) {
formModalApi.setData(row).open();
}
/** 绑定店员 */
function handleBind(row: MallDeliveryPickUpStoreApi.PickUpStore) {
bindFormModalApi.setData(row).open();
}
/** 删除门店 */
async function handleDelete(row: MallDeliveryPickUpStoreApi.PickUpStore) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
key: 'action_key_msg',
});
try {
await deleteDeliveryPickUpStore(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_key_msg',
});
onRefresh();
} finally {
hideLoading();
}
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getDeliveryPickUpStorePage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
} as VxeTableGridOptions<MallDeliveryPickUpStoreApi.PickUpStore>,
});
</script>
<template>
<Page>
<DocAlert
title="【交易】快递发货"
url="https://doc.iocoder.cn/mall/trade-delivery-express/"
/>
<Button
danger
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
>
该功能支持 Vue3 + element-plus 版本
</Button>
<br />
<Button
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mall/trade/delivery/pickUpStore/index"
>
可参考
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mall/trade/delivery/pickUpStore/index
代码pull request 贡献给我们
</Button>
<Page auto-content-height>
<FormModal @success="onRefresh" />
<BindFormModal />
<Grid table-title="">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['门店']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['trade:delivery:pick-up-store:create'],
onClick: handleCreate,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['trade:delivery:pick-up-store:update'],
onClick: handleEdit.bind(null, row),
},
{
label: '绑定店员',
type: 'link',
icon: ACTION_ICON.ADD,
auth: ['trade:delivery:pick-up-store:update'],
onClick: handleBind.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['trade:delivery:pick-up-store:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@ -0,0 +1,87 @@
<script lang="ts" setup>
import type { MallDeliveryPickUpStoreApi } from '#/api/mall/trade/delivery/pickUpStore';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import {
bindStoreStaffId,
getDeliveryPickUpStore,
} from '#/api/mall/trade/delivery/pickUpStore';
import { $t } from '#/locales';
import { useBindFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<MallDeliveryPickUpStoreApi.PickUpStore>();
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: 120,
},
layout: 'horizontal',
schema: useBindFormSchema(),
showDefaultActions: false,
});
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
//
const data =
(await formApi.getValues()) as MallDeliveryPickUpStoreApi.BindStaffRequest;
try {
await bindStoreStaffId(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<MallDeliveryPickUpStoreApi.BindStaffRequest>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
formData.value = await getDeliveryPickUpStore(data.id as number);
// values
await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal class="w-[40%]" :title="getTitle">
<Form class="mx-4" />
</Modal>
</template>

View File

@ -0,0 +1,89 @@
<script lang="ts" setup>
import type { MallDeliveryPickUpStoreApi } from '#/api/mall/trade/delivery/pickUpStore';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import {
createDeliveryPickUpStore,
getDeliveryPickUpStore,
updateDeliveryPickUpStore,
} from '#/api/mall/trade/delivery/pickUpStore';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<MallDeliveryPickUpStoreApi.PickUpStore>();
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: 120,
},
layout: 'horizontal',
schema: useFormSchema(),
showDefaultActions: false,
});
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
//
const data =
(await formApi.getValues()) as MallDeliveryPickUpStoreApi.PickUpStore;
try {
await (formData.value?.id
? updateDeliveryPickUpStore(data)
: createDeliveryPickUpStore(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<MallDeliveryPickUpStoreApi.PickUpStore>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
formData.value = await getDeliveryPickUpStore(data.id as number);
// values
await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal class="w-[40%]" :title="getTitle">
<Form class="mx-4" />
</Modal>
</template>