feat:【mall 商城】满减送活动优化(antd)
This commit is contained in:
@@ -1,2 +0,0 @@
|
|||||||
export { default as RewardRuleCouponSelect } from './reward-rule-coupon-select.vue';
|
|
||||||
export { default as RewardRule } from './reward-rule.vue';
|
|
||||||
@@ -1,10 +1,15 @@
|
|||||||
import type { VbenFormSchema } from '#/adapter/form';
|
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,
|
||||||
|
PromotionConditionTypeEnum,
|
||||||
|
PromotionProductScopeEnum,
|
||||||
|
} from '@vben/constants';
|
||||||
import { getDictOptions } from '@vben/hooks';
|
import { getDictOptions } from '@vben/hooks';
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
|
|
||||||
|
import { z } from '#/adapter/form';
|
||||||
import { getRangePickerDefaultProps } from '#/utils';
|
import { getRangePickerDefaultProps } from '#/utils';
|
||||||
|
|
||||||
/** 列表的搜索表单 */
|
/** 列表的搜索表单 */
|
||||||
@@ -97,35 +102,40 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
|||||||
/** 新增/修改的表单 */
|
/** 新增/修改的表单 */
|
||||||
export function useFormSchema(): VbenFormSchema[] {
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
return [
|
return [
|
||||||
|
// 隐藏 ID 字段
|
||||||
{
|
{
|
||||||
component: 'Input',
|
|
||||||
fieldName: 'id',
|
fieldName: 'id',
|
||||||
|
component: 'Input',
|
||||||
dependencies: {
|
dependencies: {
|
||||||
triggerFields: [''],
|
triggerFields: [''],
|
||||||
show: () => false,
|
show: () => false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// 活动名称
|
||||||
{
|
{
|
||||||
fieldName: 'name',
|
fieldName: 'name',
|
||||||
label: '活动名称',
|
label: '活动名称',
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
|
rules: 'required',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
placeholder: '请输入活动名称',
|
placeholder: '请输入活动名称',
|
||||||
|
allowClear: true,
|
||||||
},
|
},
|
||||||
rules: 'required',
|
|
||||||
},
|
},
|
||||||
|
// 活动时间
|
||||||
{
|
{
|
||||||
fieldName: 'startAndEndTime',
|
fieldName: 'startAndEndTime',
|
||||||
label: '活动时间',
|
label: '活动时间',
|
||||||
component: 'RangePicker',
|
component: 'RangePicker',
|
||||||
|
rules: 'required',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
showTime: true,
|
showTime: true,
|
||||||
format: 'YYYY-MM-DD HH:mm:ss',
|
format: 'YYYY-MM-DD HH:mm:ss',
|
||||||
placeholder: [$t('common.startTimeText'), $t('common.endTimeText')],
|
placeholder: [$t('common.startTimeText'), $t('common.endTimeText')],
|
||||||
|
allowClear: true,
|
||||||
},
|
},
|
||||||
rules: 'required',
|
|
||||||
},
|
},
|
||||||
// TODO @puhui999:增加一个 defaultValue
|
// 条件类型
|
||||||
{
|
{
|
||||||
fieldName: 'conditionType',
|
fieldName: 'conditionType',
|
||||||
label: '条件类型',
|
label: '条件类型',
|
||||||
@@ -135,9 +145,9 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
buttonStyle: 'solid',
|
buttonStyle: 'solid',
|
||||||
optionType: 'button',
|
optionType: 'button',
|
||||||
},
|
},
|
||||||
defaultValue: PromotionConditionTypeEnum.PRICE.type,
|
rules: z.number().default(PromotionConditionTypeEnum.PRICE.type),
|
||||||
rules: 'required',
|
|
||||||
},
|
},
|
||||||
|
// 活动范围
|
||||||
{
|
{
|
||||||
fieldName: 'productScope',
|
fieldName: 'productScope',
|
||||||
label: '活动范围',
|
label: '活动范围',
|
||||||
@@ -147,8 +157,9 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
buttonStyle: 'solid',
|
buttonStyle: 'solid',
|
||||||
optionType: 'button',
|
optionType: 'button',
|
||||||
},
|
},
|
||||||
rules: 'required',
|
rules: z.number().default(PromotionProductScopeEnum.ALL.scope),
|
||||||
},
|
},
|
||||||
|
// 备注
|
||||||
{
|
{
|
||||||
fieldName: 'remark',
|
fieldName: 'remark',
|
||||||
label: '备注',
|
label: '备注',
|
||||||
@@ -156,6 +167,26 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
componentProps: {
|
componentProps: {
|
||||||
placeholder: '请输入备注',
|
placeholder: '请输入备注',
|
||||||
rows: 4,
|
rows: 4,
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// 优惠规则(自定义组件插槽)
|
||||||
|
{
|
||||||
|
fieldName: 'rules',
|
||||||
|
label: '优惠设置',
|
||||||
|
component: 'Input',
|
||||||
|
formItemClass: 'items-start',
|
||||||
|
},
|
||||||
|
// 商品范围选择(自定义组件插槽)
|
||||||
|
{
|
||||||
|
fieldName: 'productSpuIds',
|
||||||
|
label: '选择商品',
|
||||||
|
component: 'Input',
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: ['productScope'],
|
||||||
|
show: (values) => {
|
||||||
|
return values.productScope === PromotionProductScopeEnum.SPU.scope;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ function handleEdit(row: MallRewardActivityApi.RewardActivity) {
|
|||||||
/** 关闭满减送活动 */
|
/** 关闭满减送活动 */
|
||||||
async function handleClose(row: MallRewardActivityApi.RewardActivity) {
|
async function handleClose(row: MallRewardActivityApi.RewardActivity) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: '正在关闭中...',
|
content: $t('ui.actionMessage.closing', [row.name]),
|
||||||
duration: 0,
|
duration: 0,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await closeRewardActivity(row.id!);
|
await closeRewardActivity(row.id!);
|
||||||
message.success('关闭成功');
|
message.success($t('ui.actionMessage.closeSuccess', [row.name]));
|
||||||
handleRefresh();
|
handleRefresh();
|
||||||
} finally {
|
} finally {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
@@ -96,7 +96,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
refresh: true,
|
refresh: true,
|
||||||
search: true,
|
search: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions,
|
} as VxeTableGridOptions<MallRewardActivityApi.RewardActivity>,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -104,6 +104,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
<Page auto-content-height>
|
<Page auto-content-height>
|
||||||
<FormModal @success="handleRefresh" />
|
<FormModal @success="handleRefresh" />
|
||||||
<Grid table-title="满减送活动">
|
<Grid table-title="满减送活动">
|
||||||
|
<!-- 工具栏按钮 -->
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<TableAction
|
<TableAction
|
||||||
:actions="[
|
:actions="[
|
||||||
@@ -111,19 +112,22 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
label: $t('ui.actionTitle.create', ['活动']),
|
label: $t('ui.actionTitle.create', ['活动']),
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
icon: ACTION_ICON.ADD,
|
icon: ACTION_ICON.ADD,
|
||||||
|
auth: ['promotion:reward-activity:create'],
|
||||||
onClick: handleCreate,
|
onClick: handleCreate,
|
||||||
},
|
},
|
||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<!-- 行操作按钮 -->
|
||||||
<template #actions="{ row }">
|
<template #actions="{ row }">
|
||||||
<!-- TODO @AI:table action 的权限标识;参考 /Users/yunai/Java/yudao-ui-admin-vue3/src/views/mall/promotion/rewardActivity/index.vue -->
|
|
||||||
<TableAction
|
<TableAction
|
||||||
:actions="[
|
:actions="[
|
||||||
{
|
{
|
||||||
label: $t('common.edit'),
|
label: $t('common.edit'),
|
||||||
type: 'link',
|
type: 'link',
|
||||||
icon: ACTION_ICON.EDIT,
|
icon: ACTION_ICON.EDIT,
|
||||||
|
auth: ['promotion:reward-activity:update'],
|
||||||
onClick: handleEdit.bind(null, row),
|
onClick: handleEdit.bind(null, row),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -131,9 +135,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
type: 'link',
|
type: 'link',
|
||||||
danger: true,
|
danger: true,
|
||||||
icon: ACTION_ICON.CLOSE,
|
icon: ACTION_ICON.CLOSE,
|
||||||
|
auth: ['promotion:reward-activity:close'],
|
||||||
ifShow: row.status === 0,
|
ifShow: row.status === 0,
|
||||||
popConfirm: {
|
popConfirm: {
|
||||||
title: '确认关闭该满减活动吗?',
|
title: '确认关闭该满减送活动吗?',
|
||||||
confirm: handleClose.bind(null, row),
|
confirm: handleClose.bind(null, row),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -142,6 +147,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
type: 'link',
|
type: 'link',
|
||||||
danger: true,
|
danger: true,
|
||||||
icon: ACTION_ICON.DELETE,
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['promotion:reward-activity:delete'],
|
||||||
popConfirm: {
|
popConfirm: {
|
||||||
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
|
||||||
confirm: handleDelete.bind(null, row),
|
confirm: handleDelete.bind(null, row),
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from '@vben/constants';
|
} from '@vben/constants';
|
||||||
import { convertToInteger, formatToFraction } from '@vben/utils';
|
import { convertToInteger, formatToFraction } from '@vben/utils';
|
||||||
|
|
||||||
import { Alert, FormItem, message } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
import { useVbenForm } from '#/adapter/form';
|
import { useVbenForm } from '#/adapter/form';
|
||||||
import {
|
import {
|
||||||
@@ -20,19 +20,19 @@ import {
|
|||||||
updateRewardActivity,
|
updateRewardActivity,
|
||||||
} from '#/api/mall/promotion/reward/rewardActivity';
|
} from '#/api/mall/promotion/reward/rewardActivity';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
// TODO @puhui999:有问题
|
import { SpuShowcase } from '#/views/mall/product/spu/components';
|
||||||
// import { SpuAndSkuList } from '#/views/mall/promotion/components';
|
|
||||||
|
|
||||||
import RewardRule from '../components/reward-rule.vue';
|
|
||||||
import { useFormSchema } from '../data';
|
import { useFormSchema } from '../data';
|
||||||
|
import RewardRule from './reward-rule.vue';
|
||||||
|
|
||||||
const emit = defineEmits(['success']);
|
const emit = defineEmits(['success']);
|
||||||
// TODO @puhui999:代码风格,和别的 form 保持一致;
|
|
||||||
const formData = ref<MallRewardActivityApi.RewardActivity>({
|
const formData = ref<MallRewardActivityApi.RewardActivity>({
|
||||||
conditionType: PromotionConditionTypeEnum.PRICE.type,
|
conditionType: PromotionConditionTypeEnum.PRICE.type,
|
||||||
productScope: PromotionProductScopeEnum.ALL.scope,
|
productScope: PromotionProductScopeEnum.ALL.scope,
|
||||||
rules: [],
|
rules: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const getTitle = computed(() => {
|
const getTitle = computed(() => {
|
||||||
return formData.value?.id
|
return formData.value?.id
|
||||||
? $t('ui.actionTitle.edit', ['满减送'])
|
? $t('ui.actionTitle.edit', ['满减送'])
|
||||||
@@ -44,7 +44,9 @@ const [Form, formApi] = useVbenForm({
|
|||||||
componentProps: {
|
componentProps: {
|
||||||
class: 'w-full',
|
class: 'w-full',
|
||||||
},
|
},
|
||||||
|
labelWidth: 100,
|
||||||
} as VbenFormProps['commonConfig'],
|
} as VbenFormProps['commonConfig'],
|
||||||
|
layout: 'horizontal',
|
||||||
schema: useFormSchema(),
|
schema: useFormSchema(),
|
||||||
showDefaultActions: false,
|
showDefaultActions: false,
|
||||||
});
|
});
|
||||||
@@ -60,29 +62,28 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
try {
|
try {
|
||||||
const data = await formApi.getValues();
|
const data = await formApi.getValues();
|
||||||
// 设置活动规则优惠券
|
|
||||||
rewardRuleRef.value?.setRuleCoupon();
|
rewardRuleRef.value?.setRuleCoupon();
|
||||||
// 时间段转换
|
|
||||||
if (data.startAndEndTime && Array.isArray(data.startAndEndTime)) {
|
if (data.startAndEndTime && Array.isArray(data.startAndEndTime)) {
|
||||||
data.startTime = data.startAndEndTime[0];
|
data.startTime = data.startAndEndTime[0];
|
||||||
data.endTime = data.startAndEndTime[1];
|
data.endTime = data.startAndEndTime[1];
|
||||||
delete data.startAndEndTime;
|
delete data.startAndEndTime;
|
||||||
}
|
}
|
||||||
// 规则元转分
|
|
||||||
data.rules?.forEach((item: any) => {
|
data.rules?.forEach((item: any) => {
|
||||||
item.discountPrice = convertToInteger(item.discountPrice || 0);
|
item.discountPrice = convertToInteger(item.discountPrice || 0);
|
||||||
if (data.conditionType === PromotionConditionTypeEnum.PRICE.type) {
|
if (data.conditionType === PromotionConditionTypeEnum.PRICE.type) {
|
||||||
item.limit = convertToInteger(item.limit || 0);
|
item.limit = convertToInteger(item.limit || 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 设置商品范围
|
|
||||||
setProductScopeValues(data);
|
setProductScopeValues(data);
|
||||||
|
|
||||||
// 提交表单
|
|
||||||
await (formData.value?.id
|
await (formData.value?.id
|
||||||
? updateRewardActivity(<MallRewardActivityApi.RewardActivity>data)
|
? updateRewardActivity(data as MallRewardActivityApi.RewardActivity)
|
||||||
: createRewardActivity(<MallRewardActivityApi.RewardActivity>data));
|
: createRewardActivity(data as MallRewardActivityApi.RewardActivity));
|
||||||
// 关闭并提示
|
|
||||||
await modalApi.close();
|
await modalApi.close();
|
||||||
emit('success');
|
emit('success');
|
||||||
message.success($t('ui.actionMessage.operationSuccess'));
|
message.success($t('ui.actionMessage.operationSuccess'));
|
||||||
@@ -99,17 +100,18 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 加载数据
|
|
||||||
const data = modalApi.getData<MallRewardActivityApi.RewardActivity>();
|
const data = modalApi.getData<MallRewardActivityApi.RewardActivity>();
|
||||||
if (!data || !data.id) {
|
if (!data || !data.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
try {
|
try {
|
||||||
const result = await getReward(data.id);
|
const result = await getReward(data.id);
|
||||||
// 转区段时间
|
|
||||||
result.startAndEndTime = [result.startTime, result.endTime];
|
result.startAndEndTime = [result.startTime, result.endTime] as any[];
|
||||||
// 规则分转元
|
|
||||||
result.rules?.forEach((item: any) => {
|
result.rules?.forEach((item: any) => {
|
||||||
item.discountPrice = formatToFraction(item.discountPrice || 0);
|
item.discountPrice = formatToFraction(item.discountPrice || 0);
|
||||||
if (result.conditionType === PromotionConditionTypeEnum.PRICE.type) {
|
if (result.conditionType === PromotionConditionTypeEnum.PRICE.type) {
|
||||||
@@ -118,10 +120,8 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
});
|
});
|
||||||
|
|
||||||
formData.value = result;
|
formData.value = result;
|
||||||
// 设置到 values
|
|
||||||
await formApi.setValues(result);
|
await formApi.setValues(result);
|
||||||
|
|
||||||
// 获得商品范围
|
|
||||||
await getProductScope();
|
await getProductScope();
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.unlock();
|
modalApi.unlock();
|
||||||
@@ -129,8 +129,6 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 获得商品范围 */
|
|
||||||
// TODO @puhui999:可以参考下优惠劵模版的做法;可见 /Users/yunai/Java/yudao-ui-admin-vben-v5/apps/web-antd/src/views/mall/promotion/coupon/template/data.ts 的 295 行;
|
|
||||||
async function getProductScope() {
|
async function getProductScope() {
|
||||||
switch (formData.value.productScope) {
|
switch (formData.value.productScope) {
|
||||||
case PromotionProductScopeEnum.CATEGORY.scope: {
|
case PromotionProductScopeEnum.CATEGORY.scope: {
|
||||||
@@ -140,15 +138,12 @@ async function getProductScope() {
|
|||||||
Array.isArray(productCategoryIds) &&
|
Array.isArray(productCategoryIds) &&
|
||||||
productCategoryIds.length === 1
|
productCategoryIds.length === 1
|
||||||
) {
|
) {
|
||||||
// 单选时使用数组不能反显
|
|
||||||
productCategoryIds = productCategoryIds[0];
|
productCategoryIds = productCategoryIds[0];
|
||||||
}
|
}
|
||||||
// 设置品类编号
|
|
||||||
formData.value.productCategoryIds = productCategoryIds;
|
formData.value.productCategoryIds = productCategoryIds;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PromotionProductScopeEnum.SPU.scope: {
|
case PromotionProductScopeEnum.SPU.scope: {
|
||||||
// 设置商品编号
|
|
||||||
formData.value.productSpuIds = formData.value.productScopeValues;
|
formData.value.productSpuIds = formData.value.productScopeValues;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -158,7 +153,6 @@ async function getProductScope() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 设置商品范围 */
|
|
||||||
function setProductScopeValues(data: any) {
|
function setProductScopeValues(data: any) {
|
||||||
switch (formData.value.productScope) {
|
switch (formData.value.productScope) {
|
||||||
case PromotionProductScopeEnum.CATEGORY.scope: {
|
case PromotionProductScopeEnum.CATEGORY.scope: {
|
||||||
@@ -179,33 +173,17 @@ function setProductScopeValues(data: any) {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Modal :title="getTitle" class="!w-[65%]">
|
<Modal :title="getTitle" class="w-2/3">
|
||||||
<!-- TODO @puhui999:貌似可以不要? -->
|
<Form class="mx-6">
|
||||||
<Alert
|
<!-- 自定义插槽:优惠规则 -->
|
||||||
description="【营销】满减送"
|
<template #rules>
|
||||||
message="提示"
|
<RewardRule ref="rewardRuleRef" v-model="formData" />
|
||||||
show-icon
|
</template>
|
||||||
type="info"
|
|
||||||
class="mb-4"
|
|
||||||
/>
|
|
||||||
<Form class="mx-4" />
|
|
||||||
|
|
||||||
<!-- 优惠设置 -->
|
<!-- 自定义插槽:商品选择 -->
|
||||||
<FormItem label="优惠设置">
|
<template #productSpuIds>
|
||||||
<RewardRule ref="rewardRuleRef" v-model="formData" />
|
<SpuShowcase v-model="formData.productSpuIds" />
|
||||||
</FormItem>
|
</template>
|
||||||
<!-- 商品范围选择 -->
|
</Form>
|
||||||
<FormItem
|
|
||||||
v-if="formData.productScope === PromotionProductScopeEnum.SPU.scope"
|
|
||||||
label="选择商品"
|
|
||||||
>
|
|
||||||
<SpuAndSkuList
|
|
||||||
v-model:spu-ids="formData.productSpuIds"
|
|
||||||
:rule-config="[]"
|
|
||||||
:spu-property-list="[]"
|
|
||||||
:deletable="true"
|
|
||||||
:spu-list="[]"
|
|
||||||
/>
|
|
||||||
</FormItem>
|
|
||||||
</Modal>
|
</Modal>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { MallCouponTemplateApi } from '#/api/mall/promotion/coupon/couponTemplate';
|
||||||
import type { MallRewardActivityApi } from '#/api/mall/promotion/reward/rewardActivity';
|
import type { MallRewardActivityApi } from '#/api/mall/promotion/reward/rewardActivity';
|
||||||
|
|
||||||
import { nextTick, onMounted, ref } from 'vue';
|
import { nextTick, onMounted, ref } from 'vue';
|
||||||
|
|
||||||
|
import { DICT_TYPE } from '@vben/constants';
|
||||||
|
|
||||||
import { useVModel } from '@vueuse/core';
|
import { useVModel } from '@vueuse/core';
|
||||||
import { Button, Input } from 'ant-design-vue';
|
import { Button, Input } from 'ant-design-vue';
|
||||||
|
|
||||||
// import { CouponSelect } from '@/views/mall/promotion/coupon/components'; // TODO: 根据实际路径调整
|
import { getCouponTemplateList } from '#/api/mall/promotion/coupon/couponTemplate';
|
||||||
// import * as CouponTemplateApi from '#/api/mall/promotion/coupon/couponTemplate'; // TODO: API
|
import { DictTag } from '#/components/dict-tag';
|
||||||
// import { discountFormat } from '@/views/mall/promotion/coupon/formatter'; // TODO: 根据实际路径调整
|
import { CouponSelect } from '#/views/mall/promotion/coupon/components';
|
||||||
|
import { discountFormat } from '#/views/mall/promotion/coupon/formatter';
|
||||||
|
|
||||||
// TODO @puhui999:这里报错了。
|
|
||||||
defineOptions({ name: 'RewardRuleCouponSelect' });
|
defineOptions({ name: 'RewardRuleCouponSelect' });
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -21,17 +24,22 @@ const emits = defineEmits<{
|
|||||||
(e: 'update:modelValue', v: any): void;
|
(e: 'update:modelValue', v: any): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
/** 选择赠送的优惠类型拓展 */
|
||||||
|
interface GiveCoupon extends MallCouponTemplateApi.CouponTemplate {
|
||||||
|
giveCount?: number;
|
||||||
|
}
|
||||||
|
|
||||||
const rewardRule = useVModel(props, 'modelValue', emits);
|
const rewardRule = useVModel(props, 'modelValue', emits);
|
||||||
const list = ref<any[]>([]); // TODO: 改为 GiveCouponVO[] 类型
|
const list = ref<GiveCoupon[]>([]);
|
||||||
|
|
||||||
const CouponTemplateTakeTypeEnum = {
|
const CouponTemplateTakeTypeEnum = {
|
||||||
ADMIN: { type: 2 },
|
ADMIN: { type: 2 },
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 选择优惠券 */
|
/** 选择优惠券 */
|
||||||
// const couponSelectRef = ref<InstanceType<typeof CouponSelect>>();
|
const couponSelectRef = ref<InstanceType<typeof CouponSelect>>();
|
||||||
function selectCoupon() {
|
function selectCoupon() {
|
||||||
// couponSelectRef.value?.open();
|
couponSelectRef.value?.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 选择优惠券后的回调 */
|
/** 选择优惠券后的回调 */
|
||||||
@@ -51,20 +59,22 @@ function deleteCoupon(index: number) {
|
|||||||
|
|
||||||
/** 初始化赠送的优惠券列表 */
|
/** 初始化赠送的优惠券列表 */
|
||||||
async function initGiveCouponList() {
|
async function initGiveCouponList() {
|
||||||
// if (!rewardRule.value || !rewardRule.value.giveCouponTemplateCounts) {
|
if (!rewardRule.value || !rewardRule.value.giveCouponTemplateCounts) {
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// const tempLateIds = Object.keys(rewardRule.value.giveCouponTemplateCounts);
|
const tempLateIds = Object.keys(
|
||||||
// const data = await getCouponTemplateList(tempLateIds);
|
rewardRule.value.giveCouponTemplateCounts,
|
||||||
// if (!data) {
|
) as unknown as number[];
|
||||||
// return;
|
const data = await getCouponTemplateList(tempLateIds);
|
||||||
// }
|
if (!data) {
|
||||||
// data.forEach((coupon) => {
|
return;
|
||||||
// list.value.push({
|
}
|
||||||
// ...coupon,
|
data.forEach((coupon) => {
|
||||||
// giveCount: rewardRule.value.giveCouponTemplateCounts![coupon.id],
|
list.value.push({
|
||||||
// });
|
...coupon,
|
||||||
// });
|
giveCount: rewardRule.value.giveCouponTemplateCounts![coupon.id],
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 设置赠送的优惠券 */
|
/** 设置赠送的优惠券 */
|
||||||
@@ -99,14 +109,18 @@ onMounted(async () => {
|
|||||||
<div>优惠券名称:{{ item.name }}</div>
|
<div>优惠券名称:{{ item.name }}</div>
|
||||||
<div>
|
<div>
|
||||||
范围:
|
范围:
|
||||||
<!-- <DictTag :type="DICT_TYPE.PROMOTION_PRODUCT_SCOPE" :value="item.productScope" /> -->
|
<DictTag
|
||||||
{{ item.productScope }}
|
:type="DICT_TYPE.PROMOTION_PRODUCT_SCOPE"
|
||||||
|
:value="item.productScope"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
优惠:
|
优惠:
|
||||||
<!-- <DictTag :type="DICT_TYPE.PROMOTION_DISCOUNT_TYPE" :value="item.discountType" /> -->
|
<DictTag
|
||||||
<!-- {{ discountFormat(item) }} -->
|
:type="DICT_TYPE.PROMOTION_DISCOUNT_TYPE"
|
||||||
{{ item.discountType }}
|
:value="item.discountType"
|
||||||
|
/>
|
||||||
|
{{ discountFormat(item) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="coupon-list-item-right flex items-center gap-2">
|
<div class="coupon-list-item-right flex items-center gap-2">
|
||||||
@@ -123,10 +137,10 @@ onMounted(async () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 优惠券选择 -->
|
<!-- 优惠券选择 -->
|
||||||
<!-- <CouponSelect
|
<CouponSelect
|
||||||
ref="couponSelectRef"
|
ref="couponSelectRef"
|
||||||
:take-type="CouponTemplateTakeTypeEnum.ADMIN.type"
|
:take-type="CouponTemplateTakeTypeEnum.ADMIN.type"
|
||||||
@change="handleCouponChange"
|
@change="handleCouponChange"
|
||||||
/> -->
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
// TODO @puhui999:在优化下代码;
|
|
||||||
import type { MallRewardActivityApi } from '#/api/mall/promotion/reward/rewardActivity';
|
import type { MallRewardActivityApi } from '#/api/mall/promotion/reward/rewardActivity';
|
||||||
|
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { PromotionConditionTypeEnum } from '@vben/constants';
|
||||||
|
|
||||||
import { useVModel } from '@vueuse/core';
|
import { useVModel } from '@vueuse/core';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -33,23 +34,12 @@ const formData = useVModel(props, 'modelValue', emits);
|
|||||||
const rewardRuleCouponSelectRef =
|
const rewardRuleCouponSelectRef =
|
||||||
ref<InstanceType<typeof RewardRuleCouponSelect>[]>();
|
ref<InstanceType<typeof RewardRuleCouponSelect>[]>();
|
||||||
|
|
||||||
const PromotionConditionTypeEnum = {
|
|
||||||
PRICE: { type: 10 },
|
|
||||||
COUNT: { type: 20 },
|
|
||||||
};
|
|
||||||
|
|
||||||
const isPriceCondition = computed(() => {
|
const isPriceCondition = computed(() => {
|
||||||
return (
|
return (
|
||||||
formData.value?.conditionType === PromotionConditionTypeEnum.PRICE.type
|
formData.value?.conditionType === PromotionConditionTypeEnum.PRICE.type
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 删除优惠规则 */
|
|
||||||
function deleteRule(ruleIndex: number) {
|
|
||||||
formData.value.rules.splice(ruleIndex, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 添加优惠规则 */
|
|
||||||
function addRule() {
|
function addRule() {
|
||||||
if (!formData.value.rules) {
|
if (!formData.value.rules) {
|
||||||
formData.value.rules = [];
|
formData.value.rules = [];
|
||||||
@@ -62,7 +52,10 @@ function addRule() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 设置规则优惠券-提交时 */
|
function deleteRule(ruleIndex: number) {
|
||||||
|
formData.value.rules.splice(ruleIndex, 1);
|
||||||
|
}
|
||||||
|
|
||||||
function setRuleCoupon() {
|
function setRuleCoupon() {
|
||||||
if (!rewardRuleCouponSelectRef.value) {
|
if (!rewardRuleCouponSelectRef.value) {
|
||||||
return;
|
return;
|
||||||
@@ -76,11 +69,12 @@ defineExpose({ setRuleCoupon });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Row>
|
<Row :gutter="[16, 16]">
|
||||||
<template v-if="formData.rules">
|
<template v-if="formData.rules">
|
||||||
<Col v-for="(rule, index) in formData.rules" :key="index" :span="24">
|
<Col v-for="(rule, index) in formData.rules" :key="index" :span="24">
|
||||||
<div class="mb-4">
|
<!-- 规则标题 -->
|
||||||
<span class="font-bold">活动层级{{ index + 1 }}</span>
|
<div class="mb-4 flex items-center">
|
||||||
|
<span class="text-base font-bold">活动层级 {{ index + 1 }}</span>
|
||||||
<Button
|
<Button
|
||||||
v-if="index !== 0"
|
v-if="index !== 0"
|
||||||
type="link"
|
type="link"
|
||||||
@@ -92,8 +86,9 @@ defineExpose({ setRuleCoupon });
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Form :model="rule">
|
<Form :model="rule" layout="horizontal">
|
||||||
<FormItem label="优惠门槛:" :label-col="{ span: 4 }">
|
<!-- 优惠门槛 -->
|
||||||
|
<FormItem label="优惠门槛" :label-col="{ span: 4 }">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<span>满</span>
|
<span>满</span>
|
||||||
<InputNumber
|
<InputNumber
|
||||||
@@ -102,44 +97,46 @@ defineExpose({ setRuleCoupon });
|
|||||||
:min="0"
|
:min="0"
|
||||||
:precision="2"
|
:precision="2"
|
||||||
:step="0.1"
|
:step="0.1"
|
||||||
class="!w-150px"
|
:controls="false"
|
||||||
placeholder=""
|
class="!w-40"
|
||||||
controls-position="right"
|
placeholder="请输入金额"
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
v-else
|
v-else
|
||||||
v-model:value="rule.limit"
|
v-model:value="rule.limit"
|
||||||
:min="0"
|
:min="0"
|
||||||
class="!w-150px"
|
class="!w-40"
|
||||||
placeholder=""
|
placeholder="请输入数量"
|
||||||
type="number"
|
type="number"
|
||||||
/>
|
/>
|
||||||
<span>{{ isPriceCondition ? '元' : '件' }}</span>
|
<span>{{ isPriceCondition ? '元' : '件' }}</span>
|
||||||
</div>
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
||||||
<FormItem label="优惠内容:" :label-col="{ span: 4 }">
|
<!-- 优惠内容 -->
|
||||||
|
<FormItem label="优惠内容" :label-col="{ span: 4 }">
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col gap-4">
|
||||||
<!-- 订单金额优惠 -->
|
<!-- 订单金额优惠 -->
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<span>订单金额优惠</span>
|
<div class="font-medium">订单金额优惠</div>
|
||||||
</div>
|
<div class="ml-4 flex items-center gap-2">
|
||||||
<div class="ml-4 flex items-center gap-2">
|
<span>减</span>
|
||||||
<span>减</span>
|
<InputNumber
|
||||||
<InputNumber
|
v-model:value="rule.discountPrice"
|
||||||
v-model:value="rule.discountPrice"
|
:min="0"
|
||||||
:min="0"
|
:precision="2"
|
||||||
:precision="2"
|
:step="0.1"
|
||||||
:step="0.1"
|
:controls="false"
|
||||||
class="!w-150px"
|
class="!w-40"
|
||||||
controls-position="right"
|
placeholder="请输入金额"
|
||||||
/>
|
/>
|
||||||
<span>元</span>
|
<span>元</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 包邮 -->
|
<!-- 包邮 -->
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<span>包邮:</span>
|
<span class="font-medium">包邮:</span>
|
||||||
<Switch
|
<Switch
|
||||||
v-model:checked="rule.freeDelivery"
|
v-model:checked="rule.freeDelivery"
|
||||||
checked-children="是"
|
checked-children="是"
|
||||||
@@ -149,20 +146,21 @@ defineExpose({ setRuleCoupon });
|
|||||||
|
|
||||||
<!-- 送积分 -->
|
<!-- 送积分 -->
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<span>送积分:</span>
|
<span class="font-medium">送积分:</span>
|
||||||
<span>送</span>
|
<span>送</span>
|
||||||
<Input
|
<InputNumber
|
||||||
v-model:value="rule.point"
|
v-model:value="rule.point"
|
||||||
class="!w-150px"
|
:min="0"
|
||||||
placeholder=""
|
:controls="false"
|
||||||
type="number"
|
class="!w-40"
|
||||||
|
placeholder="请输入积分"
|
||||||
/>
|
/>
|
||||||
<span>积分</span>
|
<span>积分</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 送优惠券 -->
|
<!-- 送优惠券 -->
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-start gap-2">
|
||||||
<span>送优惠券:</span>
|
<span class="font-medium">送优惠券:</span>
|
||||||
<RewardRuleCouponSelect
|
<RewardRuleCouponSelect
|
||||||
ref="rewardRuleCouponSelectRef"
|
ref="rewardRuleCouponSelectRef"
|
||||||
:model-value="rule"
|
:model-value="rule"
|
||||||
@@ -174,12 +172,16 @@ defineExpose({ setRuleCoupon });
|
|||||||
</Col>
|
</Col>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<Col :span="24" class="mt-4">
|
<!-- 添加规则按钮 -->
|
||||||
<Button type="primary" @click="addRule">添加优惠规则</Button>
|
<Col :span="24" class="mt-2">
|
||||||
|
<Button type="primary" @click="addRule">+ 添加优惠规则</Button>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col :span="24" class="mt-4">
|
<!-- 提示信息 -->
|
||||||
<Tag color="warning">赠送积分为 0 时不赠送。未选优惠券时不赠送。</Tag>
|
<Col :span="24" class="mt-2">
|
||||||
|
<Tag color="warning">
|
||||||
|
提示:赠送积分为 0 时不赠送;未选择优惠券时不赠送。
|
||||||
|
</Tag>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</template>
|
</template>
|
||||||
Reference in New Issue
Block a user