H5 前端:商品详情页,接入促销活动

pull/1/head
YunaiV 2019-04-17 00:41:10 +08:00
parent 3909a95495
commit 355c53df66
3 changed files with 67 additions and 9 deletions

View File

@ -9,8 +9,14 @@
<!-- TODO 这里需要优化下芋艿 -->
<van-cell-group>
<van-cell>
<span class="goods-price">{{ formatPrice(initialSku.price) }}</span>
<!--<span class="goods-market-price">{{ formatPrice(goods.market_price) }}</span>-->
<div v-if="calSkuPriceResult.originalPrice && calSkuPriceResult.originalPrice !== calSkuPriceResult.presentPrice">
<span class="goods-price">{{ formatPrice(calSkuPriceResult.presentPrice) }}</span>
<span class="goods-market-price">{{ formatPrice(calSkuPriceResult.originalPrice) }}</span>
</div>
<div v-else>
<span class="goods-price">{{ formatPrice(initialSku.price) }}</span>
</div>
<div class="goods-title">{{ spu.name }}</div>
<div class="goods-subtit">{{spu.sellPoint}}</div>
</van-cell>
@ -45,6 +51,7 @@
<!--</template>-->
<!--</van-cell>-->
<!---->
<!--<van-cell is-link @click="showPromotion" >-->
<!--<template slot="title">-->
<!--<span style="margin-right: 10px;">促销</span>-->
@ -71,16 +78,17 @@
<!-- <span> 满2件总价打9折</span>-->
<!-- </template>-->
<!-- </van-cell>-->
<van-cell is-link @click="sorry">
<!-- TODO 芋艿后续限时折扣需要改下样式 -->
<van-cell v-if="calSkuPriceResult.timeLimitedDiscount" is-link @click="sorry">
<template slot="title">
<van-tag type="danger">满减</van-tag>
<span> 满100元减50元</span>
<van-tag type="danger">限时折扣</van-tag>
<span> {{ formatTimeLimitedDiscountText(calSkuPriceResult.timeLimitedDiscount) }} </span>
</template>
</van-cell>
<van-cell is-link @click="sorry">
<van-cell v-if="calSkuPriceResult.fullPrivilege" is-link @click="sorry">
<template slot="title">
<van-tag type="danger">限购</van-tag>
<span> 购买不超过5件时享受单件价8.00超出数量以结算价为准</span>
<van-tag type="danger">满减送</van-tag>
<span> {{ formatFullPrivilegeText(calSkuPriceResult.fullPrivilege) }} </span>
</template>
</van-cell>
@ -215,6 +223,43 @@
text = text + 'x ' + data.quantity + ' 件';
return text;
},
formatTimeLimitedDiscountText(activity) {
let text = '';
let timeLimitedDiscount = activity.timeLimitedDiscount.items[0];
if (timeLimitedDiscount.preferentialType === 1) {
text += '减 ' + timeLimitedDiscount.preferentialValue / 100.0 + ' 元';
} else if (timeLimitedDiscount.preferentialType === 2) {
text += '打 ' + timeLimitedDiscount.preferentialValue / 10.0 + ' 折';
}
if (activity.timeLimitedDiscount.quota > 0) {
text += '【限购 ' + activity.timeLimitedDiscount.quota + ' 件】';
}
return text;
},
formatFullPrivilegeText(activity) {
let text = '';
let fullPrivilege = activity.fullPrivilege;
for (let i in fullPrivilege.privileges) {
let privilege = fullPrivilege.privileges[i];
if (i > 0) {
text += ';';
}
if (fullPrivilege.cycled) {
text += '每';
}
if (privilege.meetType === 1) {
text += '满 ' + privilege.meetValue + ' 元,';
} else if (privilege.meetType === 2) {
text += '满 ' + privilege.meetValue + ' 件,';
}
if (privilege.preferentialType === 1) {
text += '减 ' + privilege.preferentialValue / 100.0 + ' 元';
} else if (privilege.preferentialType === 2) {
text += '打 ' + privilege.preferentialValue / 10.0 + ' 折';
}
}
return text;
},
stepperChange(value) { // sku
this.initialSku.quantity = value;
@ -234,6 +279,14 @@
doCalcSkuPrice(skuId) {
getCartCalcSkuPrice(skuId).then(data => {
this.calSkuPriceResult = data;
// vanSku.list sku
for (let i in this.vanSku.list) {
let sku = this.vanSku.list[i];
if (sku.id === skuId) {
sku.price = data.presentPrice;
break;
}
}
});
},
onClickCart() {

View File

@ -244,7 +244,7 @@ public class CartServiceImpl implements CartService {
return presentPrice >= 0 ? presentPrice : sku.getPrice(); // 如果计算优惠价格小于 0 ,则说明无法使用优惠。
}
if (PreferentialTypeEnum.DISCOUNT.getValue().equals(item.getPreferentialType())) { // 打折
return sku.getPrice() * item.getPreferentialValue() / 100;
return sku.getPrice() * item.getPreferentialValue() / 10;
}
throw new IllegalArgumentException(String.format("折扣活动(%s) 的优惠类型不正确", timeLimitedDiscount.toString()));
}

View File

@ -56,6 +56,11 @@ public class PromotionActivityServiceImpl implements PromotionActivityService {
// 不匹配,则进行移除
if (!matched) {
iterator.remove();
} else { // 匹配,则做一些后续的处理
// 如果是限时折扣,移除不在 spuId 数组中的折扣规则
if (PromotionActivityTypeEnum.TIME_LIMITED_DISCOUNT.getValue().equals(activity.getActivityType())) {
activity.getTimeLimitedDiscount().getItems().removeIf(item -> !spuIds.contains(item.getSpuId()));
}
}
}
// 返回最终结果