review:【antd】【ele】member 增加 coupon-list 列表
This commit is contained in:
@@ -101,6 +101,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'actions',
|
||||
title: '操作',
|
||||
width: 100,
|
||||
fixed: 'right',
|
||||
|
||||
@@ -7,7 +7,6 @@ import { ref } from 'vue';
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import { DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { message, TabPane, Tabs } from 'ant-design-vue';
|
||||
|
||||
@@ -32,7 +31,7 @@ function handleRefresh() {
|
||||
/** 删除优惠券 */
|
||||
async function handleDelete(row: MallCouponApi.Coupon) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||
content: '回收中...',
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
|
||||
@@ -20,6 +20,7 @@ import AddressList from './modules/address-list.vue';
|
||||
import AfterSaleList from './modules/after-sale-list.vue';
|
||||
import BalanceList from './modules/balance-list.vue';
|
||||
import BasicInfo from './modules/basic-info.vue';
|
||||
import CouponList from './modules/coupon-list.vue';
|
||||
import ExperienceRecordList from './modules/experience-record-list.vue';
|
||||
import OrderList from './modules/order-list.vue';
|
||||
import PointList from './modules/point-list.vue';
|
||||
@@ -114,10 +115,7 @@ onMounted(async () => {
|
||||
</div>
|
||||
</TabPane>
|
||||
<TabPane tab="优惠劵" key="CouponList">
|
||||
<!-- Todo: 商城模块 -->
|
||||
<div class="h-full">
|
||||
<h1>优惠劵</h1>
|
||||
</div>
|
||||
<CouponList class="h-full" :user-id="userId" />
|
||||
</TabPane>
|
||||
<TabPane tab="推广用户" key="BrokerageList">
|
||||
<!-- Todo: 商城模块 -->
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MallCouponApi } from '#/api/mall/promotion/coupon/coupon';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { message, TabPane, Tabs } from 'ant-design-vue';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteCoupon,
|
||||
getCouponPage,
|
||||
} from '#/api/mall/promotion/coupon/coupon';
|
||||
import {
|
||||
useGridColumns as useCouponGridColumns,
|
||||
useGridFormSchema as useCouponGridFormSchema,
|
||||
} from '#/views/mall/promotion/coupon/data';
|
||||
|
||||
const props = defineProps<{
|
||||
userId: number;
|
||||
}>();
|
||||
|
||||
const activeTab = ref('all');
|
||||
const statusTabs = ref(getStatusTabs());
|
||||
|
||||
/** 列表的搜索表单(过滤掉会员相关字段) */
|
||||
function useGridFormSchema() {
|
||||
const excludeFields = new Set(['nickname']);
|
||||
return useCouponGridFormSchema().filter(
|
||||
(item) => !excludeFields.has(item.fieldName),
|
||||
);
|
||||
}
|
||||
|
||||
/** 列表的字段(过滤掉会员相关字段) */
|
||||
function useGridColumns() {
|
||||
const excludeFields = new Set(['nickname']);
|
||||
return useCouponGridColumns()?.filter(
|
||||
(item) => item.field && !excludeFields.has(item.field),
|
||||
);
|
||||
}
|
||||
|
||||
/** 获取状态选项卡配置 */
|
||||
function getStatusTabs() {
|
||||
const tabs = [
|
||||
{
|
||||
label: '全部',
|
||||
value: 'all',
|
||||
},
|
||||
];
|
||||
const statusOptions = getDictOptions(DICT_TYPE.PROMOTION_COUPON_STATUS);
|
||||
for (const option of statusOptions) {
|
||||
tabs.push({
|
||||
label: option.label,
|
||||
value: String(option.value),
|
||||
});
|
||||
}
|
||||
return tabs;
|
||||
}
|
||||
|
||||
/** Tab 切换 */
|
||||
function handleTabChange(tabName: any) {
|
||||
activeTab.value = tabName;
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 删除优惠券 */
|
||||
async function handleDelete(row: MallCouponApi.Coupon) {
|
||||
const hideLoading = message.loading({
|
||||
content: '回收中...',
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteCoupon(row.id!);
|
||||
message.success('回收成功');
|
||||
await gridApi.query();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
keepSource: true,
|
||||
pagerConfig: {
|
||||
pageSize: 10,
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
const params = {
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
userId: props.userId,
|
||||
...formValues,
|
||||
// Tab状态过滤
|
||||
status:
|
||||
activeTab.value === 'all' ? undefined : Number(activeTab.value),
|
||||
};
|
||||
return await getCouponPage(params);
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MallCouponApi.Coupon>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid>
|
||||
<template #toolbar-actions>
|
||||
<Tabs class="w-full" @change="handleTabChange">
|
||||
<TabPane v-for="tab in statusTabs" :key="tab.value" :tab="tab.label" />
|
||||
</Tabs>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '回收',
|
||||
type: 'link',
|
||||
danger: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['promotion:coupon:delete'],
|
||||
popConfirm: {
|
||||
title:
|
||||
'回收将会收回会员领取的待使用的优惠券,已使用的将无法回收,确定要回收所选优惠券吗?',
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
@@ -101,6 +101,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'actions',
|
||||
title: '操作',
|
||||
width: 100,
|
||||
fixed: 'right',
|
||||
|
||||
@@ -7,7 +7,6 @@ import { ref } from 'vue';
|
||||
import { DocAlert, Page } from '@vben/common-ui';
|
||||
import { DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { ElLoading, ElMessage, ElTabPane, ElTabs } from 'element-plus';
|
||||
|
||||
@@ -32,7 +31,7 @@ function handleRefresh() {
|
||||
/** 删除优惠券 */
|
||||
async function handleDelete(row: MallCouponApi.Coupon) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.name]),
|
||||
text: '回收中...',
|
||||
});
|
||||
try {
|
||||
await deleteCoupon(row.id!);
|
||||
|
||||
@@ -19,13 +19,13 @@ import AccountInfo from './modules/account-info.vue';
|
||||
import AfterSaleList from './modules/after-sale-list.vue';
|
||||
import BalanceList from './modules/balance-list.vue';
|
||||
import BasicInfo from './modules/basic-info.vue';
|
||||
import CouponList from './modules/coupon-list.vue';
|
||||
import ExperienceRecordList from './modules/experience-record-list.vue';
|
||||
import OrderList from './modules/order-list.vue';
|
||||
import PointList from './modules/point-list.vue';
|
||||
import SignList from './modules/sign-list.vue';
|
||||
import UserAddressList from './modules/user-address-list.vue';
|
||||
import UserBrokerageList from './modules/user-brokerage-list.vue';
|
||||
import UserCouponList from './modules/user-coupon-list.vue';
|
||||
import UserFavoriteList from './modules/user-favorite-list.vue';
|
||||
|
||||
const route = useRoute();
|
||||
@@ -119,10 +119,7 @@ onMounted(async () => {
|
||||
</div>
|
||||
</ElTabPane>
|
||||
<ElTabPane label="优惠劵" name="CouponList">
|
||||
<!-- Todo: 商城模块 -->
|
||||
<div class="h-full">
|
||||
<UserCouponList class="h-full" :user-id="userId" />
|
||||
</div>
|
||||
<CouponList class="h-full" :user-id="userId" />
|
||||
</ElTabPane>
|
||||
<ElTabPane label="推广用户" name="BrokerageList">
|
||||
<!-- Todo: 商城模块 -->
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MallCouponApi } from '#/api/mall/promotion/coupon/coupon';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { ElLoading, ElMessage, ElTabPane, ElTabs } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteCoupon,
|
||||
getCouponPage,
|
||||
} from '#/api/mall/promotion/coupon/coupon';
|
||||
import {
|
||||
useGridColumns as useCouponGridColumns,
|
||||
useGridFormSchema as useCouponGridFormSchema,
|
||||
} from '#/views/mall/promotion/coupon/data';
|
||||
|
||||
const props = defineProps<{
|
||||
userId: number;
|
||||
}>();
|
||||
|
||||
const activeTab = ref('all');
|
||||
const statusTabs = ref(getStatusTabs());
|
||||
|
||||
/** 列表的搜索表单(过滤掉会员相关字段) */
|
||||
function useGridFormSchema() {
|
||||
const excludeFields = new Set(['nickname']);
|
||||
return useCouponGridFormSchema().filter(
|
||||
(item) => !excludeFields.has(item.fieldName),
|
||||
);
|
||||
}
|
||||
|
||||
/** 列表的字段(过滤掉会员相关字段) */
|
||||
function useGridColumns() {
|
||||
const excludeFields = new Set(['nickname']);
|
||||
return useCouponGridColumns()?.filter(
|
||||
(item) => item.field && !excludeFields.has(item.field),
|
||||
);
|
||||
}
|
||||
|
||||
/** 获取状态选项卡配置 */
|
||||
function getStatusTabs() {
|
||||
const tabs = [
|
||||
{
|
||||
label: '全部',
|
||||
value: 'all',
|
||||
},
|
||||
];
|
||||
const statusOptions = getDictOptions(DICT_TYPE.PROMOTION_COUPON_STATUS);
|
||||
for (const option of statusOptions) {
|
||||
tabs.push({
|
||||
label: option.label,
|
||||
value: String(option.value),
|
||||
});
|
||||
}
|
||||
return tabs;
|
||||
}
|
||||
|
||||
/** Tab 切换 */
|
||||
function handleTabChange(tabName: any) {
|
||||
activeTab.value = tabName;
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 删除优惠券 */
|
||||
async function handleDelete(row: MallCouponApi.Coupon) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: '回收中...',
|
||||
});
|
||||
try {
|
||||
await deleteCoupon(row.id!);
|
||||
ElMessage.success('回收成功');
|
||||
await gridApi.query();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(),
|
||||
keepSource: true,
|
||||
pagerConfig: {
|
||||
pageSize: 10,
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
const params = {
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
userId: props.userId,
|
||||
...formValues,
|
||||
// Tab状态过滤
|
||||
status:
|
||||
activeTab.value === 'all' ? undefined : Number(activeTab.value),
|
||||
};
|
||||
return await getCouponPage(params);
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<MallCouponApi.Coupon>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid>
|
||||
<template #toolbar-actions>
|
||||
<ElTabs
|
||||
:model-value="activeTab"
|
||||
class="w-full"
|
||||
@tab-change="handleTabChange"
|
||||
>
|
||||
<ElTabPane
|
||||
v-for="tab in statusTabs"
|
||||
:key="tab.value"
|
||||
:label="tab.label"
|
||||
:name="tab.value"
|
||||
/>
|
||||
</ElTabs>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '回收',
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['promotion:coupon:delete'],
|
||||
popConfirm: {
|
||||
title:
|
||||
'回收将会收回会员领取的待使用的优惠券,已使用的将无法回收,确定要回收所选优惠券吗?',
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
@@ -1,183 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MallCouponApi } from '#/api/mall/promotion/coupon/coupon';
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import { DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { ElLoading, ElMessage, ElTabPane, ElTabs } from 'element-plus';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteCoupon,
|
||||
getCouponPage,
|
||||
} from '#/api/mall/promotion/coupon/coupon';
|
||||
import { getRangePickerDefaultProps } from '#/utils';
|
||||
|
||||
const props = defineProps<{
|
||||
userId: number;
|
||||
}>();
|
||||
|
||||
// 添加当前选中的状态
|
||||
const activeStatus = ref<number | string>('all');
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (row: MallCouponApi.Coupon) => {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: '回收将会收回会员领取的待使用的优惠券,已使用的将无法回收,确定要回收所选优惠券吗?',
|
||||
});
|
||||
try {
|
||||
await deleteCoupon(row.id as number);
|
||||
ElMessage.success('回收成功');
|
||||
// 重新加载列表
|
||||
gridApi.query();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: [
|
||||
{
|
||||
fieldName: 'createTime',
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
clearable: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
gridOptions: {
|
||||
columns: [
|
||||
{
|
||||
field: 'name',
|
||||
title: '优惠劵',
|
||||
},
|
||||
{
|
||||
field: 'discountType',
|
||||
title: 'discountType',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.PROMOTION_DISCOUNT_TYPE },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'takeType',
|
||||
title: '领取方式',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.PROMOTION_COUPON_TAKE_TYPE },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.PROMOTION_COUPON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '领取时间',
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'useTime',
|
||||
title: '使用时间',
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 180,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
],
|
||||
keepSource: true,
|
||||
pagerConfig: {
|
||||
pageSize: 10,
|
||||
},
|
||||
expandConfig: {
|
||||
trigger: 'row',
|
||||
expandAll: true,
|
||||
padding: true,
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getCouponPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
userId: props.userId,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
search: true,
|
||||
slots: {
|
||||
buttons: 'customTop',
|
||||
},
|
||||
},
|
||||
} as VxeTableGridOptions<MallCouponApi.Coupon>,
|
||||
separator: false,
|
||||
});
|
||||
|
||||
// 监听标签页变化,更新表单状态值并触发查询
|
||||
watch(activeStatus, (val) => {
|
||||
// 使用formApi获取表单对象
|
||||
if (gridApi.formApi) {
|
||||
// 设置状态值
|
||||
gridApi.formApi.setFieldValue(
|
||||
'status',
|
||||
val === 'all' ? undefined : Number(val),
|
||||
);
|
||||
|
||||
// 触发查询
|
||||
gridApi.query({ status: val === 'all' ? undefined : Number(val) });
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid>
|
||||
<template #customTop>
|
||||
<ElTabs v-model="activeStatus">
|
||||
<ElTabPane label="全部" name="all" />
|
||||
<ElTabPane
|
||||
v-for="item in getDictOptions(
|
||||
DICT_TYPE.PROMOTION_COUPON_STATUS,
|
||||
'number',
|
||||
)"
|
||||
:key="String(item.value)"
|
||||
:label="item.label"
|
||||
:name="String(item.value)"
|
||||
/>
|
||||
</ElTabs>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '回收',
|
||||
link: true,
|
||||
icon: ACTION_ICON.EDIT,
|
||||
auth: ['promotion:coupon:delete'],
|
||||
onClick: handleDelete.bind(null, row),
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
Reference in New Issue
Block a user