From e1ccf523897722eb48542589d1ea70b608dff56c Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 26 Aug 2024 16:30:35 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=91=E3=80=91=E5=95=86=E5=9F=8E:=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=AF=84=E5=AE=A1=E6=8F=90=E5=88=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UploadFile/src/UploadFile.vue | 1 - .../promotion/rewardActivity/RewardForm.vue | 36 ++++++++++++------- .../rewardActivity/components/RewardRule.vue | 33 ++++++++++------- ...howcase.vue => RewardRuleCouponSelect.vue} | 21 ++++------- 4 files changed, 51 insertions(+), 40 deletions(-) rename src/views/mall/promotion/rewardActivity/components/{RewardRuleCouponShowcase.vue => RewardRuleCouponSelect.vue} (84%) diff --git a/src/components/UploadFile/src/UploadFile.vue b/src/components/UploadFile/src/UploadFile.vue index dad9f004..9d0a904e 100644 --- a/src/components/UploadFile/src/UploadFile.vue +++ b/src/components/UploadFile/src/UploadFile.vue @@ -32,7 +32,6 @@ 格式为 {{ fileType.join('/') }} 的文件 - - - diff --git a/src/views/mall/promotion/rewardActivity/components/RewardRuleCouponShowcase.vue b/src/views/mall/promotion/rewardActivity/components/RewardRuleCouponSelect.vue similarity index 84% rename from src/views/mall/promotion/rewardActivity/components/RewardRuleCouponShowcase.vue rename to src/views/mall/promotion/rewardActivity/components/RewardRuleCouponSelect.vue index d1e26bbd..fba04e81 100644 --- a/src/views/mall/promotion/rewardActivity/components/RewardRuleCouponShowcase.vue +++ b/src/views/mall/promotion/rewardActivity/components/RewardRuleCouponSelect.vue @@ -40,7 +40,7 @@ import { isEmpty } from '@/utils/is' import { useVModel } from '@vueuse/core' import { findIndex } from '@/utils' -// TODO @puhui999:要不就叫 RewardRuleCouponSelect +defineOptions({ name: 'RewardRuleCouponSelect' }) const props = defineProps<{ modelValue: RewardRule @@ -89,15 +89,13 @@ const initGiveCouponList = async () => { if (!data) { return } - - for (let i = 0; i < data.length; i++) { - const coupon = data[i] - const index = findIndex(rewardRule.value.couponIds!, (item) => item.id === coupon.id) + data.forEach((coupon) => { + const index = findIndex(rewardRule.value.couponIds!, (couponId) => couponId === coupon.id) list.value.push({ ...coupon, giveCount: rewardRule.value.couponCounts![index] }) - } + }) } /** 设置赠送的优惠券 */ @@ -106,15 +104,8 @@ const setGiveCouponList = () => { return } - const couponIds: number[] = [] - const couponCounts: number[] = [] - for (let i = 0, len = list.value.length; i < len; i++) { - couponIds.push(list.value[i].id) - couponCounts.push(list.value[i].giveCount!) - } - // TODO @puhui999:可以考虑,直接使用 list 的 map 操作,简单一些。性能没啥差别的 - rewardRule.value.couponIds = couponIds - rewardRule.value.couponCounts = couponCounts + rewardRule.value.couponIds = list.value.map((rule) => rule.id) + rewardRule.value.couponCounts = list.value.map((rule) => rule.giveCount || 0) } defineExpose({ setGiveCouponList })