From 3eeb55749d4ff0602d9b95a5d14a1ca36f216aeb Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 23 Aug 2024 19:08:06 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E8=AF=84=E5=AE=A1?= =?UTF-8?q?=E3=80=91=E5=95=86=E5=9F=8E=EF=BC=9A=E6=BB=A1=E5=87=8F=E9=80=81?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/RewardRuleCouponShowcase.vue | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/views/mall/promotion/rewardActivity/components/RewardRuleCouponShowcase.vue b/src/views/mall/promotion/rewardActivity/components/RewardRuleCouponShowcase.vue index f7899fe3..d1e26bbd 100644 --- a/src/views/mall/promotion/rewardActivity/components/RewardRuleCouponShowcase.vue +++ b/src/views/mall/promotion/rewardActivity/components/RewardRuleCouponShowcase.vue @@ -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>() // 优惠券选择 /** 选择优惠券 */ +const couponSelectRef = ref>() // 优惠券选择 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 }