提交 d80f67c2 编写于 作者: guangjun.yang's avatar guangjun.yang

解决加减商品时,传的优惠券不对的问题

上级 cde8b6cc
此差异已折叠。
此差异已折叠。
...@@ -304,6 +304,7 @@ export default { ...@@ -304,6 +304,7 @@ export default {
); );
}, },
// 处理数据,并且先排序,再将不可用的放在最后 // 处理数据,并且先排序,再将不可用的放在最后
handlerCouponList(couponList, goodsPrice) { handlerCouponList(couponList, goodsPrice) {
if (!couponList.length) return []; if (!couponList.length) return [];
...@@ -313,9 +314,47 @@ export default { ...@@ -313,9 +314,47 @@ export default {
firstCanCouponIndex = 0, firstCanCouponIndex = 0,
item = {}, item = {},
count = 0; count = 0;
couponList.sort( (a, b) => { // couponList.sort( (a, b) => {
return b.discountAmount - a.discountAmount; // return b.discountAmount - a.discountAmount;
}); // });
for(let i = 0; i < couponList.length; i ++) {
item = couponList[i];
// couponList.forEach(item => {
// 要根据商品价格及券适用类型来计算
// item.disabled = !this.isCanSelect(item, goodsPrice);
item.disabled = !item.enableFlag;
if(!item.disabled) {
count ++;
}
// 是否已经选择
item.isChecked = !!item.checkFlag;
// console.log('firstCanCoupon, item.disabled', firstCanCoupon, item.disabled);
if (!firstCanCoupon && item.isChecked) {
firstCanCoupon = item;
firstCanCouponIndex = i;
}
newList.push(item);
}
this.setCurrentCoupon( JSON.parse(JSON.stringify(firstCanCoupon)) || {});
// this.setSelectCouponList(newList.concat(sortArray));
this.setSelectCouponList(newList);
this.goodsInfo4Coupon.count = count;
this.setGoodsInfo4Coupon(this.goodsInfo4Coupon);
},
// 处理数据,并且先排序,再将不可用的放在最后
handlerCouponListOld(couponList, goodsPrice) {
if (!couponList.length) return [];
let newList = [],
obj = {},
firstCanCoupon = null,
firstCanCouponIndex = 0,
item = {},
count = 0;
// couponList.sort( (a, b) => {
// return b.discountAmount - a.discountAmount;
// });
for(let i = 0; i < couponList.length; i ++) { for(let i = 0; i < couponList.length; i ++) {
item = couponList[i]; item = couponList[i];
// couponList.forEach(item => { // couponList.forEach(item => {
...@@ -459,8 +498,8 @@ export default { ...@@ -459,8 +498,8 @@ export default {
this.isShowCoupon = false; this.isShowCoupon = false;
this.needSortAndSelect = false; this.needSortAndSelect = false;
// 要重新调用计算价格接口 // 要重新调用计算价格接口
this.countTotalPrice(); // this.countTotalPrice();
// this.getTotalPrice(currentCoupon); this.getTotalPrice(currentCoupon);
}, },
// tab切换 // tab切换
...@@ -555,11 +594,12 @@ export default { ...@@ -555,11 +594,12 @@ export default {
// 多件商品的价格 // 多件商品的价格
// TODO,要多传优惠券id参数 // TODO,要多传优惠券id参数
getTotalPrice(coupon) { getTotalPrice(currentCoupon) {
console.log('coupon', coupon);
const num = this.curtGoodsNum; const num = this.curtGoodsNum;
// this.GET(`trade/goods/getPrice/${this.goodsId}/${num}/${couponId}`, {}).then(res => { let couponId = 0;
const couponId = this.currentCoupon.couponId || -1; if(currentCoupon) {
couponId = currentCoupon.couponId;
}
this.GET(`trade/goods/getPrice/${this.goodsId}/${num}/${couponId}`, {}).then(res => { this.GET(`trade/goods/getPrice/${this.goodsId}/${num}/${couponId}`, {}).then(res => {
if (res.code == "000000") { if (res.code == "000000") {
const { const {
...@@ -580,7 +620,8 @@ export default { ...@@ -580,7 +620,8 @@ export default {
this.setGoodsInfo4Coupon(this.goodsInfo4Coupon); this.setGoodsInfo4Coupon(this.goodsInfo4Coupon);
this.goodsNum = num; this.goodsNum = num;
if(this.needSortAndSelect) { if(this.needSortAndSelect) {
this.handlerCouponList(this.selectCouponList, preferentialPrice || costPrice); this.getCanUseCoupons(this.goodsInfo4Coupon);
// this.handlerCouponList(this.selectCouponList, preferentialPrice || costPrice);
} }
this.needSortAndSelect = true; this.needSortAndSelect = true;
} else if (res.code === "200006") { } else if (res.code === "200006") {
...@@ -589,34 +630,6 @@ export default { ...@@ -589,34 +630,6 @@ export default {
}); });
}, },
// 多件商品的价格
getTotalPriceOld() {
const num = this.curtGoodsNum;
this.GET(`trade/goods/getPrice/${this.goodsId}/${num}`, {}).then(res => {
if (res.code == "000000") {
const {
couponPrice,
preferentialPrice,
costPrice,
savePrice
} = res.data;
let price = couponPrice || preferentialPrice || costPrice;
this.totalPrice = {
...this.formatPrice(price),
preferentialPrice,
costPrice: costPrice,
costPriceText: (costPrice / 100).toFixed(2),
savePrice: savePrice ? (savePrice / 100).toFixed(2) : 0
};
this.goodsInfo4Coupon.price = price;
this.setGoodsInfo4Coupon(this.goodsInfo4Coupon);
this.goodsNum = num;
} else if (res.code === "200006") {
this.$store.dispatch("logout");
}
});
},
// 价格转成元、分 // 价格转成元、分
formatPrice(price) { formatPrice(price) {
let yuan = (price / 100).toFixed(0); let yuan = (price / 100).toFixed(0);
...@@ -627,6 +640,7 @@ export default { ...@@ -627,6 +640,7 @@ export default {
fen fen
}; };
}, },
// 获取切换标签宽度 // 获取切换标签宽度
getTabW() { getTabW() {
if (this.tabs.length === 0) { if (this.tabs.length === 0) {
...@@ -639,10 +653,12 @@ export default { ...@@ -639,10 +653,12 @@ export default {
this.tabW = width; this.tabW = width;
}); });
}, },
// 轮播切换 // 轮播切换
onSwiperChange(index) { onSwiperChange(index) {
this.swiperCurtIndex = index; this.swiperCurtIndex = index;
}, },
// 数量增 // 数量增
onPlus() { onPlus() {
this.$sendBuriedData({ this.$sendBuriedData({
...@@ -666,6 +682,7 @@ export default { ...@@ -666,6 +682,7 @@ export default {
this.curtGoodsNum = num + 1; this.curtGoodsNum = num + 1;
this.countTotalPrice(); this.countTotalPrice();
}, },
// 数量减 // 数量减
onReduce() { onReduce() {
this.$sendBuriedData({ this.$sendBuriedData({
...@@ -680,15 +697,14 @@ export default { ...@@ -680,15 +697,14 @@ export default {
this.curtGoodsNum = num - 1; this.curtGoodsNum = num - 1;
this.countTotalPrice(); this.countTotalPrice();
}, },
// goLogin() {
// this.$store.dispatch('goLogin');
// },
handlerAction(type) { handlerAction(type) {
if (type === 2) { if (type === 2) {
wxOauth(); wxOauth();
} }
this.isShowDialog = false; this.isShowDialog = false;
}, },
// 创建订单 // 创建订单
createOrder() { createOrder() {
this.$sendBuriedData({ this.$sendBuriedData({
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册