feat:【mall 商城】优惠劵-领取记录(100% antd)
This commit is contained in:
@@ -2,7 +2,6 @@ import type { VbenFormSchema } from '#/adapter/form';
|
|||||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
|
||||||
import { DICT_TYPE } from '@vben/constants';
|
import { DICT_TYPE } from '@vben/constants';
|
||||||
import { getDictOptions } from '@vben/hooks';
|
|
||||||
|
|
||||||
import { getRangePickerDefaultProps } from '#/utils';
|
import { getRangePickerDefaultProps } from '#/utils';
|
||||||
|
|
||||||
@@ -110,23 +109,3 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取状态选项卡配置 */
|
|
||||||
export 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;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
} from '@vben/constants';
|
} from '@vben/constants';
|
||||||
import { floatToFixed2, formatDate } from '@vben/utils';
|
import { floatToFixed2, formatDate } from '@vben/utils';
|
||||||
|
|
||||||
// 格式化【优惠金额/折扣】
|
/** 格式化【优惠金额/折扣】 */
|
||||||
export function discountFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
export function discountFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
||||||
if (row.discountType === PromotionDiscountTypeEnum.PRICE.type) {
|
if (row.discountType === PromotionDiscountTypeEnum.PRICE.type) {
|
||||||
return `¥${floatToFixed2(row.discountPrice)}`;
|
return `¥${floatToFixed2(row.discountPrice)}`;
|
||||||
@@ -17,7 +17,7 @@ export function discountFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
|||||||
return `未知【${row.discountType}】`;
|
return `未知【${row.discountType}】`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化【领取上限】
|
/** 格式化【领取上限】 */
|
||||||
export function takeLimitCountFormat(
|
export function takeLimitCountFormat(
|
||||||
row: MallCouponTemplateApi.CouponTemplate,
|
row: MallCouponTemplateApi.CouponTemplate,
|
||||||
) {
|
) {
|
||||||
@@ -31,7 +31,7 @@ export function takeLimitCountFormat(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化【有效期限】
|
/** 格式化【有效期限】 */
|
||||||
export function validityTypeFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
export function validityTypeFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
||||||
if (row.validityType === CouponTemplateValidityTypeEnum.DATE.type) {
|
if (row.validityType === CouponTemplateValidityTypeEnum.DATE.type) {
|
||||||
return `${formatDate(row.validStartTime)} 至 ${formatDate(row.validEndTime)}`;
|
return `${formatDate(row.validStartTime)} 至 ${formatDate(row.validEndTime)}`;
|
||||||
@@ -42,7 +42,7 @@ export function validityTypeFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
|||||||
return `未知【${row.validityType}】`;
|
return `未知【${row.validityType}】`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化【totalCount】
|
/** 格式化【totalCount】 */
|
||||||
export function totalCountFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
export function totalCountFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
||||||
if (row.totalCount === -1) {
|
if (row.totalCount === -1) {
|
||||||
return '不限制';
|
return '不限制';
|
||||||
@@ -50,7 +50,7 @@ export function totalCountFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
|||||||
return row.totalCount;
|
return row.totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化【剩余数量】
|
/** 格式化【剩余数量】 */
|
||||||
export function remainedCountFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
export function remainedCountFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
||||||
if (row.totalCount === -1) {
|
if (row.totalCount === -1) {
|
||||||
return '不限制';
|
return '不限制';
|
||||||
@@ -58,7 +58,7 @@ export function remainedCountFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
|||||||
return row.totalCount - row.takeCount;
|
return row.totalCount - row.takeCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化【最低消费】
|
/** 格式化【最低消费】 */
|
||||||
export function usePriceFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
export function usePriceFormat(row: MallCouponTemplateApi.CouponTemplate) {
|
||||||
return `¥${floatToFixed2(row.usePrice)}`;
|
return `¥${floatToFixed2(row.usePrice)}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import type { MallCouponApi } from '#/api/mall/promotion/coupon/coupon';
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { DocAlert, Page } from '@vben/common-ui';
|
import { DocAlert, Page } from '@vben/common-ui';
|
||||||
|
import { DICT_TYPE } from '@vben/constants';
|
||||||
|
import { getDictOptions } from '@vben/hooks';
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
|
|
||||||
import { message, TabPane, Tabs } from 'ant-design-vue';
|
import { message, TabPane, Tabs } from 'ant-design-vue';
|
||||||
@@ -15,13 +17,18 @@ import {
|
|||||||
getCouponPage,
|
getCouponPage,
|
||||||
} from '#/api/mall/promotion/coupon/coupon';
|
} from '#/api/mall/promotion/coupon/coupon';
|
||||||
|
|
||||||
import { getStatusTabs, useGridColumns, useGridFormSchema } from './data';
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
|
||||||
defineOptions({ name: 'PromotionCoupon' });
|
defineOptions({ name: 'PromotionCoupon' });
|
||||||
|
|
||||||
const activeTab = ref('all');
|
const activeTab = ref('all');
|
||||||
const statusTabs = ref(getStatusTabs());
|
const statusTabs = ref(getStatusTabs());
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
function handleRefresh() {
|
||||||
|
gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
/** 删除优惠券 */
|
/** 删除优惠券 */
|
||||||
async function handleDelete(row: MallCouponApi.Coupon) {
|
async function handleDelete(row: MallCouponApi.Coupon) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
@@ -29,28 +36,35 @@ async function handleDelete(row: MallCouponApi.Coupon) {
|
|||||||
duration: 0,
|
duration: 0,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteCoupon(row.id as number);
|
await deleteCoupon(row.id!);
|
||||||
message.success({
|
message.success('回收成功');
|
||||||
content: '回收成功',
|
|
||||||
});
|
|
||||||
handleRefresh();
|
handleRefresh();
|
||||||
} finally {
|
} finally {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 刷新表格 */
|
/** 获取状态选项卡配置 */
|
||||||
function handleRefresh() {
|
function getStatusTabs() {
|
||||||
gridApi.query();
|
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切换 */
|
/** Tab 切换 */
|
||||||
function onTabChange(tabName: any) {
|
function handleTabChange(tabName: any) {
|
||||||
activeTab.value = tabName;
|
activeTab.value = tabName;
|
||||||
// 设置状态查询参数
|
|
||||||
const formValues = gridApi.formApi.getValues();
|
|
||||||
const status = tabName === 'all' ? undefined : Number(tabName);
|
|
||||||
gridApi.formApi.setValues({ ...formValues, status });
|
|
||||||
gridApi.query();
|
gridApi.query();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,9 +112,9 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<Grid table-title="领取记录">
|
<Grid>
|
||||||
<template #top>
|
<template #top>
|
||||||
<Tabs v-model:active-key="activeTab" type="card" @change="onTabChange">
|
<Tabs class="-mt-11" @change="handleTabChange">
|
||||||
<TabPane
|
<TabPane
|
||||||
v-for="tab in statusTabs"
|
v-for="tab in statusTabs"
|
||||||
:key="tab.value"
|
:key="tab.value"
|
||||||
@@ -129,3 +143,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
<style scoped>
|
||||||
|
:deep(.vxe-toolbar div) {
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user