mirror of
https://gitee.com/hhyykk/ipms-sjy-ui.git
synced 2025-06-19 06:42:00 +08:00
【代码优化】商城: 满减送活动
This commit is contained in:
parent
9329978f6d
commit
dcc1a3e9d5
@ -22,7 +22,7 @@ export interface RewardRule {
|
||||
discountPrice?: number
|
||||
freeDelivery?: boolean
|
||||
point: number
|
||||
giveCoupons?: {
|
||||
giveCouponTemplateCounts?: {
|
||||
[key: number]: number
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ const open = async (type: string, id?: number) => {
|
||||
// 转区段时间
|
||||
data.startAndEndTime = [data.startTime, data.endTime]
|
||||
// 规则分转元
|
||||
data.rules.forEach((item: any) => {
|
||||
data.rules?.forEach((item: any) => {
|
||||
item.discountPrice = fenToYuan(item.discountPrice || 0)
|
||||
})
|
||||
formData.value = data
|
||||
|
@ -103,6 +103,9 @@ const deleteRule = (ruleIndex: number) => {
|
||||
|
||||
/** 添加优惠规则 */
|
||||
const addRule = () => {
|
||||
if (isEmpty(formData.value.rules)) {
|
||||
formData.value.rules = []
|
||||
}
|
||||
formData.value.rules.push({
|
||||
limit: 0,
|
||||
discountPrice: 0,
|
||||
|
@ -86,10 +86,12 @@ const deleteCoupon = (index: number) => {
|
||||
/** 初始化赠送的优惠券列表 */
|
||||
const initGiveCouponList = async () => {
|
||||
// 校验优惠券存在
|
||||
if (isEmpty(rewardRule.value) || isEmpty(rewardRule.value.giveCoupons)) {
|
||||
if (isEmpty(rewardRule.value) || isEmpty(rewardRule.value.giveCouponTemplateCounts)) {
|
||||
return
|
||||
}
|
||||
const tempLateIds = Object.keys(rewardRule.value.giveCoupons!).map((item) => parseInt(item))
|
||||
const tempLateIds = Object.keys(rewardRule.value.giveCouponTemplateCounts!).map((item) =>
|
||||
parseInt(item)
|
||||
)
|
||||
const data = await CouponTemplateApi.getCouponTemplateList(tempLateIds)
|
||||
if (!data) {
|
||||
return
|
||||
@ -98,7 +100,7 @@ const initGiveCouponList = async () => {
|
||||
data.forEach((coupon) => {
|
||||
list.value.push({
|
||||
...coupon,
|
||||
giveCount: rewardRule.value.giveCoupons![coupon.id]
|
||||
giveCount: rewardRule.value.giveCouponTemplateCounts![coupon.id]
|
||||
})
|
||||
})
|
||||
}
|
||||
@ -111,10 +113,10 @@ const setGiveCouponList = () => {
|
||||
|
||||
// 设置优惠券和其数量的对应
|
||||
list.value.forEach((rule) => {
|
||||
if (!rewardRule.value.giveCoupons) {
|
||||
rewardRule.value.giveCoupons = {}
|
||||
if (!rewardRule.value.giveCouponTemplateCounts) {
|
||||
rewardRule.value.giveCouponTemplateCounts = {}
|
||||
}
|
||||
rewardRule.value.giveCoupons[rule.id] = rule.giveCount!
|
||||
rewardRule.value.giveCouponTemplateCounts[rule.id] = rule.giveCount!
|
||||
})
|
||||
}
|
||||
defineExpose({ setGiveCouponList })
|
||||
|
Loading…
x
Reference in New Issue
Block a user