【代码评审】商城:满减送活动的实现
parent
f2f39c3a91
commit
3eeb55749d
|
@ -40,7 +40,7 @@ import { isEmpty } from '@/utils/is'
|
||||||
import { useVModel } from '@vueuse/core'
|
import { useVModel } from '@vueuse/core'
|
||||||
import { findIndex } from '@/utils'
|
import { findIndex } from '@/utils'
|
||||||
|
|
||||||
defineOptions({ name: 'RewardRuleCouponShowcase' })
|
// TODO @puhui999:要不就叫 RewardRuleCouponSelect
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue: RewardRule
|
modelValue: RewardRule
|
||||||
|
@ -58,11 +58,12 @@ interface GiveCouponVO extends CouponTemplateApi.CouponTemplateVO {
|
||||||
giveCount?: number
|
giveCount?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const couponSelectRef = ref<InstanceType<typeof CouponSelect>>() // 优惠券选择
|
|
||||||
/** 选择优惠券 */
|
/** 选择优惠券 */
|
||||||
|
const couponSelectRef = ref<InstanceType<typeof CouponSelect>>() // 优惠券选择
|
||||||
const selectCoupon = () => {
|
const selectCoupon = () => {
|
||||||
couponSelectRef.value?.open()
|
couponSelectRef.value?.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 选择优惠券后的回调 */
|
/** 选择优惠券后的回调 */
|
||||||
const handleCouponChange = (val: CouponTemplateApi.CouponTemplateVO[]) => {
|
const handleCouponChange = (val: CouponTemplateApi.CouponTemplateVO[]) => {
|
||||||
for (const item of val) {
|
for (const item of val) {
|
||||||
|
@ -72,23 +73,24 @@ const handleCouponChange = (val: CouponTemplateApi.CouponTemplateVO[]) => {
|
||||||
list.value.push(item)
|
list.value.push(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除优惠券 */
|
/** 删除优惠券 */
|
||||||
const deleteCoupon = (index: number) => {
|
const deleteCoupon = (index: number) => {
|
||||||
list.value.splice(index, 1)
|
list.value.splice(index, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 初始化赠送的优惠券列表-如果有的话*/
|
/** 初始化赠送的优惠券列表 */
|
||||||
const initGiveCouponList = async () => {
|
const initGiveCouponList = async () => {
|
||||||
|
// 朝赵优惠劵
|
||||||
if (isEmpty(rewardRule.value) || isEmpty(rewardRule.value.couponIds)) {
|
if (isEmpty(rewardRule.value) || isEmpty(rewardRule.value.couponIds)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await CouponTemplateApi.getCouponTemplateList(rewardRule.value.couponIds!)
|
const data = await CouponTemplateApi.getCouponTemplateList(rewardRule.value.couponIds!)
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0, len = data.length; i < len; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
const coupon = data[i]
|
const coupon = data[i]
|
||||||
const index = findIndex(rewardRule.value.couponIds!, (item) => item.id === coupon.id)
|
const index = findIndex(rewardRule.value.couponIds!, (item) => item.id === coupon.id)
|
||||||
list.value.push({
|
list.value.push({
|
||||||
|
@ -110,6 +112,7 @@ const setGiveCouponList = () => {
|
||||||
couponIds.push(list.value[i].id)
|
couponIds.push(list.value[i].id)
|
||||||
couponCounts.push(list.value[i].giveCount!)
|
couponCounts.push(list.value[i].giveCount!)
|
||||||
}
|
}
|
||||||
|
// TODO @puhui999:可以考虑,直接使用 list 的 map 操作,简单一些。性能没啥差别的
|
||||||
rewardRule.value.couponIds = couponIds
|
rewardRule.value.couponIds = couponIds
|
||||||
rewardRule.value.couponCounts = couponCounts
|
rewardRule.value.couponCounts = couponCounts
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue