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

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

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