feat:【mall 商城】promotion reward【antd】100%: 迁移完成
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export { default as RewardRuleCouponSelect } from './reward-rule-coupon-select.vue';
|
||||
export { default as RewardRule } from './reward-rule.vue';
|
||||
@@ -0,0 +1,131 @@
|
||||
<script lang="ts" setup>
|
||||
import type { MallRewardActivityApi } from '#/api/mall/promotion/reward/rewardActivity';
|
||||
|
||||
import { nextTick, onMounted, ref } from 'vue';
|
||||
|
||||
import { useVModel } from '@vueuse/core';
|
||||
import { Button, Input } from 'ant-design-vue';
|
||||
|
||||
// import { CouponSelect } from '@/views/mall/promotion/coupon/components'; // TODO: 根据实际路径调整
|
||||
// import * as CouponTemplateApi from '#/api/mall/promotion/coupon/couponTemplate'; // TODO: API
|
||||
// import { discountFormat } from '@/views/mall/promotion/coupon/formatter'; // TODO: 根据实际路径调整
|
||||
|
||||
defineOptions({ name: 'RewardRuleCouponSelect' });
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: MallRewardActivityApi.RewardRule;
|
||||
}>();
|
||||
|
||||
const emits = defineEmits<{
|
||||
(e: 'update:modelValue', v: any): void;
|
||||
}>();
|
||||
|
||||
const rewardRule = useVModel(props, 'modelValue', emits);
|
||||
const list = ref<any[]>([]); // TODO: 改为 GiveCouponVO[] 类型
|
||||
|
||||
const CouponTemplateTakeTypeEnum = {
|
||||
ADMIN: { type: 2 },
|
||||
};
|
||||
|
||||
/** 选择优惠券 */
|
||||
// const couponSelectRef = ref<InstanceType<typeof CouponSelect>>();
|
||||
function selectCoupon() {
|
||||
// couponSelectRef.value?.open();
|
||||
}
|
||||
|
||||
/** 选择优惠券后的回调 */
|
||||
function handleCouponChange(val: any[]) {
|
||||
for (const item of val) {
|
||||
if (list.value.some((v) => v.id === item.id)) {
|
||||
continue;
|
||||
}
|
||||
list.value.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
/** 删除优惠券 */
|
||||
function deleteCoupon(index: number) {
|
||||
list.value.splice(index, 1);
|
||||
}
|
||||
|
||||
/** 初始化赠送的优惠券列表 */
|
||||
async function initGiveCouponList() {
|
||||
// if (!rewardRule.value || !rewardRule.value.giveCouponTemplateCounts) {
|
||||
// return;
|
||||
// }
|
||||
// const tempLateIds = Object.keys(rewardRule.value.giveCouponTemplateCounts);
|
||||
// const data = await CouponTemplateApi.getCouponTemplateList(tempLateIds);
|
||||
// if (!data) {
|
||||
// return;
|
||||
// }
|
||||
// data.forEach((coupon) => {
|
||||
// list.value.push({
|
||||
// ...coupon,
|
||||
// giveCount: rewardRule.value.giveCouponTemplateCounts![coupon.id],
|
||||
// });
|
||||
// });
|
||||
}
|
||||
|
||||
/** 设置赠送的优惠券 */
|
||||
function setGiveCouponList() {
|
||||
if (!rewardRule.value) {
|
||||
return;
|
||||
}
|
||||
rewardRule.value.giveCouponTemplateCounts = {};
|
||||
list.value.forEach((rule) => {
|
||||
rewardRule.value.giveCouponTemplateCounts![rule.id] = rule.giveCount!;
|
||||
});
|
||||
}
|
||||
|
||||
defineExpose({ setGiveCouponList });
|
||||
|
||||
onMounted(async () => {
|
||||
await nextTick();
|
||||
await initGiveCouponList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="w-full">
|
||||
<Button type="link" class="ml-2" @click="selectCoupon">添加优惠劵</Button>
|
||||
|
||||
<div
|
||||
v-for="(item, index) in list"
|
||||
:key="item.id"
|
||||
class="coupon-list-item mb-2 flex justify-between rounded-lg border border-dashed border-gray-300 p-2"
|
||||
>
|
||||
<div class="coupon-list-item-left flex flex-wrap items-center gap-2">
|
||||
<div>优惠券名称:{{ item.name }}</div>
|
||||
<div>
|
||||
范围:
|
||||
<!-- <DictTag :type="DICT_TYPE.PROMOTION_PRODUCT_SCOPE" :value="item.productScope" /> -->
|
||||
{{ item.productScope }}
|
||||
</div>
|
||||
<div class="flex items-center">
|
||||
优惠:
|
||||
<!-- <DictTag :type="DICT_TYPE.PROMOTION_DISCOUNT_TYPE" :value="item.discountType" /> -->
|
||||
<!-- {{ discountFormat(item) }} -->
|
||||
{{ item.discountType }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="coupon-list-item-right flex items-center gap-2">
|
||||
<span>送</span>
|
||||
<Input
|
||||
v-model:value="item.giveCount"
|
||||
class="!w-150px"
|
||||
placeholder=""
|
||||
type="number"
|
||||
/>
|
||||
<span>张</span>
|
||||
<Button type="link" danger @click="deleteCoupon(index)">删除</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 优惠券选择 -->
|
||||
<!-- <CouponSelect
|
||||
ref="couponSelectRef"
|
||||
:take-type="CouponTemplateTakeTypeEnum.ADMIN.type"
|
||||
@change="handleCouponChange"
|
||||
/> -->
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,184 @@
|
||||
<script lang="ts" setup>
|
||||
import type { MallRewardActivityApi } from '#/api/mall/promotion/reward/rewardActivity';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVModel } from '@vueuse/core';
|
||||
import {
|
||||
Button,
|
||||
Col,
|
||||
Form,
|
||||
FormItem,
|
||||
Input,
|
||||
InputNumber,
|
||||
Row,
|
||||
Switch,
|
||||
Tag,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import RewardRuleCouponSelect from './reward-rule-coupon-select.vue';
|
||||
|
||||
defineOptions({ name: 'RewardRule' });
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: MallRewardActivityApi.RewardActivity;
|
||||
}>();
|
||||
|
||||
const emits = defineEmits<{
|
||||
(e: 'update:modelValue', v: any): void;
|
||||
}>();
|
||||
|
||||
const formData = useVModel(props, 'modelValue', emits);
|
||||
const rewardRuleCouponSelectRef =
|
||||
ref<InstanceType<typeof RewardRuleCouponSelect>[]>();
|
||||
|
||||
const PromotionConditionTypeEnum = {
|
||||
PRICE: { type: 10 },
|
||||
COUNT: { type: 20 },
|
||||
};
|
||||
|
||||
const isPriceCondition = computed(() => {
|
||||
return (
|
||||
formData.value?.conditionType === PromotionConditionTypeEnum.PRICE.type
|
||||
);
|
||||
});
|
||||
|
||||
/** 删除优惠规则 */
|
||||
function deleteRule(ruleIndex: number) {
|
||||
formData.value.rules.splice(ruleIndex, 1);
|
||||
}
|
||||
|
||||
/** 添加优惠规则 */
|
||||
function addRule() {
|
||||
if (!formData.value.rules) {
|
||||
formData.value.rules = [];
|
||||
}
|
||||
formData.value.rules.push({
|
||||
limit: 0,
|
||||
discountPrice: 0,
|
||||
freeDelivery: false,
|
||||
point: 0,
|
||||
});
|
||||
}
|
||||
|
||||
/** 设置规则优惠券-提交时 */
|
||||
function setRuleCoupon() {
|
||||
if (!rewardRuleCouponSelectRef.value) {
|
||||
return;
|
||||
}
|
||||
rewardRuleCouponSelectRef.value.forEach((item: any) =>
|
||||
item.setGiveCouponList(),
|
||||
);
|
||||
}
|
||||
|
||||
defineExpose({ setRuleCoupon });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Row>
|
||||
<template v-if="formData.rules">
|
||||
<Col v-for="(rule, index) in formData.rules" :key="index" :span="24">
|
||||
<div class="mb-4">
|
||||
<span class="font-bold">活动层级{{ index + 1 }}</span>
|
||||
<Button
|
||||
v-if="index !== 0"
|
||||
type="link"
|
||||
danger
|
||||
class="ml-2"
|
||||
@click="deleteRule(index)"
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Form :model="rule">
|
||||
<FormItem label="优惠门槛:" label-col="{ span: 4 }">
|
||||
<div class="flex items-center gap-2">
|
||||
<span>满</span>
|
||||
<InputNumber
|
||||
v-if="isPriceCondition"
|
||||
v-model:value="rule.limit"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
:step="0.1"
|
||||
class="!w-150px"
|
||||
placeholder=""
|
||||
controls-position="right"
|
||||
/>
|
||||
<Input
|
||||
v-else
|
||||
v-model:value="rule.limit"
|
||||
:min="0"
|
||||
class="!w-150px"
|
||||
placeholder=""
|
||||
type="number"
|
||||
/>
|
||||
<span>{{ isPriceCondition ? '元' : '件' }}</span>
|
||||
</div>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label="优惠内容:" label-col="{ span: 4 }">
|
||||
<div class="flex flex-col gap-4">
|
||||
<!-- 订单金额优惠 -->
|
||||
<div class="flex items-center gap-2">
|
||||
<span>订单金额优惠</span>
|
||||
</div>
|
||||
<div class="ml-4 flex items-center gap-2">
|
||||
<span>减</span>
|
||||
<InputNumber
|
||||
v-model:value="rule.discountPrice"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
:step="0.1"
|
||||
class="!w-150px"
|
||||
controls-position="right"
|
||||
/>
|
||||
<span>元</span>
|
||||
</div>
|
||||
|
||||
<!-- 包邮 -->
|
||||
<div class="flex items-center gap-2">
|
||||
<span>包邮:</span>
|
||||
<Switch
|
||||
v-model:checked="rule.freeDelivery"
|
||||
checked-children="是"
|
||||
un-checked-children="否"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 送积分 -->
|
||||
<div class="flex items-center gap-2">
|
||||
<span>送积分:</span>
|
||||
<span>送</span>
|
||||
<Input
|
||||
v-model:value="rule.point"
|
||||
class="!w-150px"
|
||||
placeholder=""
|
||||
type="number"
|
||||
/>
|
||||
<span>积分</span>
|
||||
</div>
|
||||
|
||||
<!-- 送优惠券 -->
|
||||
<div class="flex items-center gap-2">
|
||||
<span>送优惠券:</span>
|
||||
<RewardRuleCouponSelect
|
||||
ref="rewardRuleCouponSelectRef"
|
||||
v-model="rule"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</FormItem>
|
||||
</Form>
|
||||
</Col>
|
||||
</template>
|
||||
|
||||
<Col :span="24" class="mt-4">
|
||||
<Button type="primary" @click="addRule">添加优惠规则</Button>
|
||||
</Col>
|
||||
|
||||
<Col :span="24" class="mt-4">
|
||||
<Tag color="warning">赠送积分为 0 时不赠送。未选优惠券时不赠送。</Tag>
|
||||
</Col>
|
||||
</Row>
|
||||
</template>
|
||||
Reference in New Issue
Block a user