【代码评审】商城:满减送活动的实现

pull/522/MERGE
YunaiV 2024-08-23 19:08:06 +08:00
parent f2f39c3a91
commit 3eeb55749d
1 changed files with 8 additions and 5 deletions

View File

@ -40,7 +40,7 @@ import { isEmpty } from '@/utils/is'
import { useVModel } from '@vueuse/core'
import { findIndex } from '@/utils'
defineOptions({ name: 'RewardRuleCouponShowcase' })
// TODO @puhui999 RewardRuleCouponSelect
const props = defineProps<{
modelValue: RewardRule
@ -58,11 +58,12 @@ interface GiveCouponVO extends CouponTemplateApi.CouponTemplateVO {
giveCount?: number
}
const couponSelectRef = ref<InstanceType<typeof CouponSelect>>() //
/** 选择优惠券 */
const couponSelectRef = ref<InstanceType<typeof CouponSelect>>() //
const selectCoupon = () => {
couponSelectRef.value?.open()
}
/** 选择优惠券后的回调 */
const handleCouponChange = (val: CouponTemplateApi.CouponTemplateVO[]) => {
for (const item of val) {
@ -72,23 +73,24 @@ const handleCouponChange = (val: CouponTemplateApi.CouponTemplateVO[]) => {
list.value.push(item)
}
}
/** 删除优惠券 */
const deleteCoupon = (index: number) => {
list.value.splice(index, 1)
}
/** 初始化赠送的优惠券列表-如果有的话*/
/** 初始化赠送的优惠券列表 */
const initGiveCouponList = async () => {
//
if (isEmpty(rewardRule.value) || isEmpty(rewardRule.value.couponIds)) {
return
}
const data = await CouponTemplateApi.getCouponTemplateList(rewardRule.value.couponIds!)
if (!data) {
return
}
for (let i = 0, len = data.length; i < len; i++) {
for (let i = 0; i < data.length; i++) {
const coupon = data[i]
const index = findIndex(rewardRule.value.couponIds!, (item) => item.id === coupon.id)
list.value.push({
@ -110,6 +112,7 @@ const setGiveCouponList = () => {
couponIds.push(list.value[i].id)
couponCounts.push(list.value[i].giveCount!)
}
// TODO @puhui999使 list map
rewardRule.value.couponIds = couponIds
rewardRule.value.couponCounts = couponCounts
}