feat: mall brokerage user
parent
1518ec2f67
commit
f0d221ebf9
|
@ -29,12 +29,14 @@ export namespace MallBrokerageUserApi {
|
|||
export interface CreateRequest {
|
||||
/** 用户编号 */
|
||||
userId: number;
|
||||
/** 推广员编号 */
|
||||
bindUserId: number;
|
||||
}
|
||||
|
||||
/** 修改推广员请求 */
|
||||
export interface UpdateBindUserRequest {
|
||||
/** 用户编号 */
|
||||
userId: number;
|
||||
id: number;
|
||||
/** 推广员编号 */
|
||||
bindUserId: number;
|
||||
}
|
||||
|
@ -42,15 +44,15 @@ export namespace MallBrokerageUserApi {
|
|||
/** 清除推广员请求 */
|
||||
export interface ClearBindUserRequest {
|
||||
/** 用户编号 */
|
||||
userId: number;
|
||||
id: number;
|
||||
}
|
||||
|
||||
/** 修改推广资格请求 */
|
||||
export interface UpdateBrokerageEnabledRequest {
|
||||
/** 用户编号 */
|
||||
userId: number;
|
||||
id: number;
|
||||
/** 是否启用分销 */
|
||||
brokerageEnabled: boolean;
|
||||
enabled: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { fenToYuan } from '@vben/utils';
|
||||
|
||||
import { getRangePickerDefaultProps } from '#/utils';
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'bindUserId',
|
||||
label: '推广员编号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入推广员编号',
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'brokerageEnabled',
|
||||
label: '推广资格',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择推广资格',
|
||||
clearable: true,
|
||||
options: [
|
||||
{ label: '有', value: true },
|
||||
{ label: '无', value: false },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'createTime',
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'id',
|
||||
title: '用户编号',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'avatar',
|
||||
title: '头像',
|
||||
width: 70,
|
||||
slots: { default: 'avatar' },
|
||||
},
|
||||
{
|
||||
field: 'nickname',
|
||||
title: '昵称',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'brokerageUserCount',
|
||||
title: '推广人数',
|
||||
width: 80,
|
||||
},
|
||||
{
|
||||
field: 'brokerageOrderCount',
|
||||
title: '推广订单数量',
|
||||
minWidth: 110,
|
||||
},
|
||||
{
|
||||
field: 'brokerageOrderPrice',
|
||||
title: '推广订单金额',
|
||||
minWidth: 110,
|
||||
formatter: ({ row }) => `¥${fenToYuan(row.brokerageOrderPrice)}`,
|
||||
},
|
||||
{
|
||||
field: 'withdrawPrice',
|
||||
title: '已提现金额',
|
||||
minWidth: 100,
|
||||
formatter: ({ row }) => `¥${fenToYuan(row.withdrawPrice)}`,
|
||||
},
|
||||
{
|
||||
field: 'withdrawCount',
|
||||
title: '已提现次数',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'price',
|
||||
title: '未提现金额',
|
||||
minWidth: 100,
|
||||
formatter: ({ row }) => `¥${fenToYuan(row.price)}`,
|
||||
},
|
||||
{
|
||||
field: 'frozenPrice',
|
||||
title: '冻结中佣金',
|
||||
minWidth: 100,
|
||||
formatter: ({ row }) => `¥${fenToYuan(row.frozenPrice)}`,
|
||||
},
|
||||
{
|
||||
field: 'brokerageEnabled',
|
||||
title: '推广资格',
|
||||
minWidth: 80,
|
||||
slots: { default: 'brokerageEnabled' },
|
||||
},
|
||||
{
|
||||
field: 'brokerageTime',
|
||||
title: '成为推广员时间',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'bindUserId',
|
||||
title: '上级推广员编号',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
field: 'bindUserTime',
|
||||
title: '推广员绑定时间',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 150,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
|
@ -1,32 +1,234 @@
|
|||
<script lang="ts" setup>
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MallBrokerageUserApi } from '#/api/mall/trade/brokerage/user';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
import { onMounted } from 'vue';
|
||||
|
||||
import { useAccess } from '@vben/access';
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { Avatar, message, Switch } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
clearBindUser,
|
||||
getBrokerageUserPage,
|
||||
updateBrokerageEnabled,
|
||||
} from '#/api/mall/trade/brokerage/user';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import BrokerageOrderListModal from './modules/order-list-modal.vue';
|
||||
import BrokerageUserCreateForm from './modules/user-create-form.vue';
|
||||
import BrokerageUserListModal from './modules/user-list-modal.vue';
|
||||
import BrokerageUserUpdateForm from './modules/user-update-form.vue';
|
||||
|
||||
defineOptions({ name: 'TradeBrokerageUser' });
|
||||
|
||||
const { hasAccessByCodes } = useAccess();
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
const [OrderListModal, OrderListModalApi] = useVbenModal({
|
||||
connectedComponent: BrokerageOrderListModal,
|
||||
});
|
||||
|
||||
const [UserCreateModal, UserCreateModalApi] = useVbenModal({
|
||||
connectedComponent: BrokerageUserCreateForm,
|
||||
});
|
||||
|
||||
const [UserListModal, UserListModalApi] = useVbenModal({
|
||||
connectedComponent: BrokerageUserListModal,
|
||||
});
|
||||
|
||||
const [UserUpdateModal, UserUpdateModalApi] = useVbenModal({
|
||||
connectedComponent: BrokerageUserUpdateForm,
|
||||
});
|
||||
|
||||
/** 打开推广人列表 */
|
||||
function openBrokerageUserTable(row: MallBrokerageUserApi.BrokerageUser) {
|
||||
UserListModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 打开推广订单列表 */
|
||||
function openBrokerageOrderTable(row: MallBrokerageUserApi.BrokerageUser) {
|
||||
OrderListModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 打开表单:修改上级推广人 */
|
||||
function openUpdateBindUserForm(row: MallBrokerageUserApi.BrokerageUser) {
|
||||
UserUpdateModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 创建分销员 */
|
||||
function openCreateUserForm() {
|
||||
UserCreateModalApi.open();
|
||||
}
|
||||
|
||||
/** 清除上级推广人 */
|
||||
async function handleClearBindUser(row: MallBrokerageUserApi.BrokerageUser) {
|
||||
const hideLoading = message.loading({
|
||||
content: `正在清除"${row.nickname}"的上级推广人...`,
|
||||
key: 'clear_bind_user_msg',
|
||||
});
|
||||
try {
|
||||
await clearBindUser({ id: row.id as number });
|
||||
message.success({
|
||||
content: '清除成功',
|
||||
key: 'clear_bind_user_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 推广资格:开通/关闭 */
|
||||
async function handleBrokerageEnabledChange(
|
||||
row: MallBrokerageUserApi.BrokerageUser,
|
||||
) {
|
||||
const text = row.brokerageEnabled ? '开通' : '关闭';
|
||||
const hideLoading = message.loading({
|
||||
content: `正在${text}"${row.nickname}"的推广资格...`,
|
||||
key: 'brokerage_enabled_msg',
|
||||
});
|
||||
try {
|
||||
await updateBrokerageEnabled({
|
||||
id: row.id as number,
|
||||
enabled: row.brokerageEnabled as boolean,
|
||||
});
|
||||
message.success({
|
||||
content: `${text}成功`,
|
||||
key: 'brokerage_enabled_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} catch {
|
||||
// 异常时,需要重置回之前的值
|
||||
row.brokerageEnabled = !row.brokerageEnabled;
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
showOverflow: 'tooltip',
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getBrokerageUserPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: { code: 'query' },
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MallBrokerageUserApi.BrokerageUser>,
|
||||
});
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
// 表格初始化时会自动查询,无需手动调用
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<DocAlert
|
||||
title="【交易】分销返佣"
|
||||
url="https://doc.iocoder.cn/mall/trade-brokerage/"
|
||||
/>
|
||||
<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/brokerage/user/index"
|
||||
>
|
||||
可参考
|
||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mall/trade/brokerage/user/index
|
||||
代码,pull request 贡献给我们!
|
||||
</Button>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert
|
||||
title="【交易】分销返佣"
|
||||
url="https://doc.iocoder.cn/mall/trade-brokerage/"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<Grid table-title="分销用户列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: $t('ui.actionTitle.create', ['分销员']),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['trade:brokerage-user:create'],
|
||||
onClick: openCreateUserForm,
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #avatar="{ row }">
|
||||
<Avatar :src="row.avatar" />
|
||||
</template>
|
||||
|
||||
<template #brokerageEnabled="{ row }">
|
||||
<Switch
|
||||
v-model:checked="row.brokerageEnabled"
|
||||
:disabled="
|
||||
!hasAccessByCodes(['trade:brokerage-user:update-bind-user'])
|
||||
"
|
||||
checked-children="有"
|
||||
un-checked-children="无"
|
||||
@change="handleBrokerageEnabledChange(row)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:drop-down-actions="[
|
||||
{
|
||||
label: '推广人',
|
||||
type: 'link',
|
||||
auth: ['trade:brokerage-user:user-query'],
|
||||
onClick: openBrokerageUserTable.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '推广订单',
|
||||
type: 'link',
|
||||
auth: ['trade:brokerage-user:order-query'],
|
||||
onClick: openBrokerageOrderTable.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '修改上级推广人',
|
||||
type: 'link',
|
||||
auth: ['trade:brokerage-user:update-bind-user'],
|
||||
onClick: openUpdateBindUserForm.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '清除上级推广人',
|
||||
type: 'link',
|
||||
auth: ['trade:brokerage-user:clear-bind-user'],
|
||||
onClick: handleClearBindUser.bind(null, row),
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 修改上级推广人表单 -->
|
||||
<UserUpdateModal @success="onRefresh" />
|
||||
<!-- 推广人列表 -->
|
||||
<UserListModal />
|
||||
<!-- 推广订单列表 -->
|
||||
<OrderListModal />
|
||||
<!-- 创建分销员 -->
|
||||
<UserCreateModal @success="onRefresh" />
|
||||
</Page>
|
||||
</template>
|
||||
|
|
|
@ -0,0 +1,193 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MallBrokerageRecordApi } from '#/api/mall/trade/brokerage/record';
|
||||
import type { MallBrokerageUserApi } from '#/api/mall/trade/brokerage/user';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { fenToYuan } from '@vben/utils';
|
||||
|
||||
import { Avatar, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getBrokerageRecordPage } from '#/api/mall/trade/brokerage/record';
|
||||
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
||||
import { BrokerageRecordBizTypeEnum } from '#/utils/constants';
|
||||
|
||||
/** 推广订单列表 */
|
||||
defineOptions({ name: 'BrokerageOrderListModal' });
|
||||
|
||||
const userId = ref<number>();
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
userId.value = undefined;
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<MallBrokerageUserApi.BrokerageUser>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
userId.value = data.id;
|
||||
// 等待弹窗打开后再查询
|
||||
setTimeout(() => {
|
||||
gridApi.query();
|
||||
}, 100);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/** 搜索表单配置 */
|
||||
function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'sourceUserLevel',
|
||||
label: '用户类型',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '全部', value: 0 },
|
||||
{ label: '一级推广人', value: 1 },
|
||||
{ label: '二级推广人', value: 2 },
|
||||
],
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
defaultValue: 0,
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
clearable: true,
|
||||
options: getDictOptions(DICT_TYPE.BROKERAGE_RECORD_STATUS, 'number'),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'createTime',
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 表格列配置 */
|
||||
function useColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'bizId',
|
||||
title: '订单编号',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'sourceUserId',
|
||||
title: '用户编号',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'sourceUserAvatar',
|
||||
title: '头像',
|
||||
width: 70,
|
||||
slots: { default: 'avatar' },
|
||||
},
|
||||
{
|
||||
field: 'sourceUserNickname',
|
||||
title: '昵称',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'price',
|
||||
title: '佣金',
|
||||
minWidth: 100,
|
||||
formatter: ({ row }) => `¥${fenToYuan(row.price)}`,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 85,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useColumns(),
|
||||
height: '600',
|
||||
keepSource: true,
|
||||
showOverflow: 'tooltip',
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
// 处理全部的情况
|
||||
const params = {
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
userId: userId.value,
|
||||
bizType: BrokerageRecordBizTypeEnum.ORDER.type,
|
||||
sourceUserLevel:
|
||||
formValues.sourceUserLevel === 0
|
||||
? undefined
|
||||
: formValues.sourceUserLevel,
|
||||
status: formValues.status,
|
||||
createTime: formValues.createTime,
|
||||
};
|
||||
return await getBrokerageRecordPage(params);
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: { code: 'query' },
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MallBrokerageRecordApi.BrokerageRecord>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="推广订单列表" class="w-3/5">
|
||||
<Grid table-title="推广订单列表">
|
||||
<template #avatar="{ row }">
|
||||
<Avatar :src="row.sourceUserAvatar" />
|
||||
</template>
|
||||
|
||||
<template #status="{ row }">
|
||||
<template
|
||||
v-for="dict in getDictOptions(DICT_TYPE.BROKERAGE_RECORD_STATUS)"
|
||||
:key="dict.value"
|
||||
>
|
||||
<Tag v-if="dict.value === row.status" :color="dict.colorType">
|
||||
{{ dict.label }}
|
||||
</Tag>
|
||||
</template>
|
||||
</template>
|
||||
</Grid>
|
||||
</Modal>
|
||||
</template>
|
|
@ -0,0 +1,166 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MallBrokerageUserApi } from '#/api/mall/trade/brokerage/user';
|
||||
|
||||
import { reactive, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { formatDate, isEmpty } from '@vben/utils';
|
||||
|
||||
import {
|
||||
Avatar,
|
||||
Descriptions,
|
||||
DescriptionsItem,
|
||||
InputSearch,
|
||||
message,
|
||||
Tag,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createBrokerageUser,
|
||||
getBrokerageUser,
|
||||
} from '#/api/mall/trade/brokerage/user';
|
||||
import { getUser } from '#/api/member/user';
|
||||
|
||||
defineOptions({ name: 'BrokerageUserCreateForm' });
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
|
||||
const formData = ref<any>({
|
||||
userId: undefined,
|
||||
bindUserId: undefined,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
if (!formData.value) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
try {
|
||||
await createBrokerageUser(formData.value);
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
onOpenChange: async (isOpen: boolean) => {
|
||||
if (!isOpen) {
|
||||
return;
|
||||
}
|
||||
formData.value = {
|
||||
userId: undefined,
|
||||
bindUserId: undefined,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
/** 用户信息 */
|
||||
const userInfo = reactive<{
|
||||
bindUser: MallBrokerageUserApi.BrokerageUser | undefined;
|
||||
user: MallBrokerageUserApi.BrokerageUser | undefined;
|
||||
}>({
|
||||
bindUser: undefined,
|
||||
user: undefined,
|
||||
});
|
||||
|
||||
/** 查询推广员和分销员 */
|
||||
async function handleGetUser(id: any, userType: string) {
|
||||
if (isEmpty(id)) {
|
||||
message.warning(`请先输入${userType}编号后重试!!!`);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
userType === '推广员' &&
|
||||
formData.value?.bindUserId === formData.value?.userId
|
||||
) {
|
||||
message.error('不能绑定自己为推广人');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const user =
|
||||
userType === '推广员' ? await getBrokerageUser(id) : await getUser(id);
|
||||
if (userType === '推广员') {
|
||||
userInfo.bindUser = user as MallBrokerageUserApi.BrokerageUser;
|
||||
} else {
|
||||
userInfo.user = user as MallBrokerageUserApi.BrokerageUser;
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
message.warning(`${userType}不存在`);
|
||||
}
|
||||
} catch {
|
||||
message.warning(`${userType}不存在`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="创建分销员" class="w-2/5">
|
||||
<div class="mr-2 flex items-center">
|
||||
分销员编号:
|
||||
<InputSearch
|
||||
v-model:value="formData.userId"
|
||||
placeholder="请输入推广员编号"
|
||||
enter-button
|
||||
class="mx-2 w-52"
|
||||
@search="handleGetUser(formData?.userId, '分销员')"
|
||||
/>
|
||||
上级推广人编号:
|
||||
<InputSearch
|
||||
v-model:value="formData.bindUserId"
|
||||
placeholder="请输入推广员编号"
|
||||
enter-button
|
||||
class="mx-2 w-52"
|
||||
@search="handleGetUser(formData?.bindUserId, '推广员')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<!-- 展示分销员的信息 -->
|
||||
<Descriptions
|
||||
title="分销员信息"
|
||||
class="mt-4"
|
||||
v-if="userInfo.user"
|
||||
:column="1"
|
||||
bordered
|
||||
>
|
||||
<DescriptionsItem label="头像">
|
||||
<Avatar :src="userInfo.user?.avatar" />
|
||||
</DescriptionsItem>
|
||||
<DescriptionsItem label="昵称">
|
||||
{{ userInfo.user?.nickname }}
|
||||
</DescriptionsItem>
|
||||
</Descriptions>
|
||||
<!-- 展示上级推广人的信息 -->
|
||||
<Descriptions
|
||||
title="上级推广人信息"
|
||||
class="mt-4"
|
||||
v-if="userInfo.bindUser"
|
||||
:column="1"
|
||||
bordered
|
||||
>
|
||||
<DescriptionsItem label="头像">
|
||||
<Avatar :src="userInfo.bindUser?.avatar" />
|
||||
</DescriptionsItem>
|
||||
<DescriptionsItem label="昵称">
|
||||
{{ userInfo.bindUser?.nickname }}
|
||||
</DescriptionsItem>
|
||||
<DescriptionsItem label="推广资格">
|
||||
<Tag v-if="userInfo.bindUser?.brokerageEnabled" color="success">
|
||||
有
|
||||
</Tag>
|
||||
<Tag v-else>无</Tag>
|
||||
</DescriptionsItem>
|
||||
<DescriptionsItem label="成为推广员的时间">
|
||||
{{ formatDate(userInfo.bindUser?.brokerageTime) }}
|
||||
</DescriptionsItem>
|
||||
</Descriptions>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
|
@ -0,0 +1,157 @@
|
|||
<script lang="ts" setup>
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MallBrokerageUserApi } from '#/api/mall/trade/brokerage/user';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Avatar, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getBrokerageUserPage } from '#/api/mall/trade/brokerage/user';
|
||||
import { getRangePickerDefaultProps } from '#/utils';
|
||||
|
||||
defineOptions({ name: 'BrokerageUserListModal' });
|
||||
|
||||
const bindUserId = ref<number>();
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
onOpenChange: async (isOpen: boolean) => {
|
||||
if (!isOpen) {
|
||||
bindUserId.value = undefined;
|
||||
return;
|
||||
}
|
||||
const data = modalApi.getData<MallBrokerageUserApi.BrokerageUser>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
bindUserId.value = data.id;
|
||||
// 等待弹窗打开后再查询
|
||||
setTimeout(() => {
|
||||
gridApi.query();
|
||||
}, 100);
|
||||
},
|
||||
});
|
||||
|
||||
/** 搜索表单配置 */
|
||||
function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'level',
|
||||
label: '用户类型',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '全部', value: undefined },
|
||||
{ label: '一级推广人', value: '1' },
|
||||
{ label: '二级推广人', value: '2' },
|
||||
],
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'bindUserTime',
|
||||
label: '绑定时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 表格列配置 */
|
||||
function useColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'id',
|
||||
title: '用户编号',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'avatar',
|
||||
title: '头像',
|
||||
width: 70,
|
||||
slots: { default: 'avatar' },
|
||||
},
|
||||
{
|
||||
field: 'nickname',
|
||||
title: '昵称',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'brokerageUserCount',
|
||||
title: '推广人数',
|
||||
minWidth: 80,
|
||||
},
|
||||
{
|
||||
field: 'brokerageOrderCount',
|
||||
title: '推广订单数量',
|
||||
minWidth: 110,
|
||||
},
|
||||
{
|
||||
field: 'brokerageEnabled',
|
||||
title: '推广资格',
|
||||
minWidth: 80,
|
||||
slots: { default: 'brokerageEnabled' },
|
||||
},
|
||||
{
|
||||
field: 'bindUserTime',
|
||||
title: '绑定时间',
|
||||
width: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useColumns(),
|
||||
height: '600',
|
||||
keepSource: true,
|
||||
showOverflow: 'tooltip',
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getBrokerageUserPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
bindUserId: bindUserId.value,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: { code: 'query' },
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MallBrokerageUserApi.BrokerageUser>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="推广人列表" class="w-3/5">
|
||||
<Grid table-title="推广人列表">
|
||||
<template #avatar="{ row }">
|
||||
<Avatar :src="row.avatar" />
|
||||
</template>
|
||||
|
||||
<template #brokerageEnabled="{ row }">
|
||||
<Tag v-if="row.brokerageEnabled" color="success">有</Tag>
|
||||
<Tag v-else>无</Tag>
|
||||
</template>
|
||||
</Grid>
|
||||
</Modal>
|
||||
</template>
|
|
@ -0,0 +1,131 @@
|
|||
<script lang="ts" setup>
|
||||
import type { MallBrokerageUserApi } from '#/api/mall/trade/brokerage/user';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { formatDate } from '@vben/utils';
|
||||
|
||||
import {
|
||||
Avatar,
|
||||
Descriptions,
|
||||
DescriptionsItem,
|
||||
InputSearch,
|
||||
message,
|
||||
Tag,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
getBrokerageUser,
|
||||
updateBindUser,
|
||||
} from '#/api/mall/trade/brokerage/user';
|
||||
|
||||
/** 修改分销用户 */
|
||||
defineOptions({ name: 'BrokerageUserUpdateForm' });
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
|
||||
const formData = ref<any>();
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
if (!formData.value) {
|
||||
return;
|
||||
}
|
||||
// 未查找到合适的上级
|
||||
if (!bindUser.value) {
|
||||
message.error('请先查询并确认推广人');
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
await updateBindUser(formData.value);
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
onOpenChange: async (isOpen: boolean) => {
|
||||
if (!isOpen) {
|
||||
formData.value = {
|
||||
id: 0,
|
||||
bindUserId: 0,
|
||||
};
|
||||
return;
|
||||
}
|
||||
const data = modalApi.getData<MallBrokerageUserApi.BrokerageUser>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = {
|
||||
id: data.id,
|
||||
bindUserId: data.bindUserId,
|
||||
};
|
||||
if (data.bindUserId) {
|
||||
await handleGetUser();
|
||||
}
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const bindUser = ref<MallBrokerageUserApi.BrokerageUser>();
|
||||
|
||||
/** 查询推广员 */
|
||||
async function handleGetUser() {
|
||||
if (!formData.value) {
|
||||
return;
|
||||
}
|
||||
if (formData.value.bindUserId === formData.value.id) {
|
||||
message.error('不能绑定自己为推广人');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
bindUser.value = await getBrokerageUser(formData.value.bindUserId);
|
||||
if (!bindUser.value) {
|
||||
message.warning('推广员不存在');
|
||||
}
|
||||
} catch {
|
||||
message.warning('推广员不存在');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="修改上级推广人" class="w-2/5">
|
||||
<div class="mr-2 flex items-center">
|
||||
推广员编号:
|
||||
<InputSearch
|
||||
v-model:value="formData.bindUserId"
|
||||
placeholder="请输入推广员编号"
|
||||
enter-button
|
||||
class="mx-2 w-52"
|
||||
@search="handleGetUser"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 展示上级推广人的信息 -->
|
||||
<Descriptions class="mt-4" v-if="bindUser" :column="1" bordered>
|
||||
<DescriptionsItem label="头像">
|
||||
<Avatar :src="bindUser.avatar" />
|
||||
</DescriptionsItem>
|
||||
<DescriptionsItem label="昵称">
|
||||
{{ bindUser.nickname }}
|
||||
</DescriptionsItem>
|
||||
<DescriptionsItem label="推广资格">
|
||||
<Tag v-if="bindUser.brokerageEnabled" color="success">有</Tag>
|
||||
<Tag v-else>无</Tag>
|
||||
</DescriptionsItem>
|
||||
<DescriptionsItem label="成为推广员的时间">
|
||||
{{ formatDate(bindUser.brokerageTime) }}
|
||||
</DescriptionsItem>
|
||||
</Descriptions>
|
||||
</Modal>
|
||||
</template>
|
Loading…
Reference in New Issue