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

请选择优惠券

上级 b7ecbe21
......@@ -6,10 +6,13 @@
<img @click="cancle" src="../../images/cme/close.png" />
</article>
<article v-if="true" class="list-wrapper">
<p v-if="currentCoupon.couponId">
<p v-if="currentCoupon.couponId || goodsInfo4Coupon.count">
已选择1张优惠券,共抵扣
<span class="sc thin">¥{{yuan(currentCoupon.discountAmount)}}</span>
</p>
<p v-else-if="goodsInfo4Coupon.count">
请选择优惠券
</p>
<div
class="item"
@click="toggleChecked(item)"
......@@ -139,8 +142,8 @@ export default {
this.selectCouponList.forEach((cItem, index) => {
cItem.isChecked = false;
});
this.currentCouponInfo = JSON.parse(JSON.stringify(item));
item.isChecked = true;
this.currentCouponInfo = JSON.parse(JSON.stringify(item));
} else {
this.currentCouponInfo = {};
item.isChecked = false;
......
......@@ -177,13 +177,13 @@ export default {
deep: true
},
// 监听当前商品信息
goodsInfo4Coupon: {
handler(goodsInfo) {
this.setSelectCouponList(this.selectCouponList);
},
deep: true
}
// // 监听当前商品信息
// goodsInfo4Coupon: {
// handler(goodsInfo) {
// this.setSelectCouponList(this.selectCouponList);
// },
// deep: true
// }
},
created() {
......@@ -194,7 +194,7 @@ export default {
this.projectId = this.$route.query.projectId;
this.goodsId = this.$route.query.goodsId || 74;
this.courseUrl = this.$route.query.courseUrl || ""; //
this.couponIdFromGL = this.$route.query.couponId || ""; //
// this.couponIdFromGL = this.$route.query.couponId || ""; //
this.shareUrl = getWebPageUrl(
`profexam/#/goods-detail?goodsId=${this.goodsId}`
);
......@@ -213,7 +213,6 @@ export default {
localStorage.setItem("returnUrl", this.shareUrl);
window.__getUserInfo4GD = function(param) {
// appVersion 安卓 3.2.2 iOS
console.log("__getUserInfo4GD", param);
_this.token = param.userToken;
_this.setUserInfo(param);
......@@ -229,7 +228,6 @@ export default {
};
},
mounted() {
this.getTabW();
console.log("this.isWeb ... isWechat - 1", this.isWeb, isWechat);
......@@ -287,7 +285,8 @@ export default {
this.GET(`trade/coupon/app/goodsCoupons`, { goodsType, cardType }).then(
res => {
if (res.code == "000000") {
this.handlerCouponList(res.data || [], params.price);
this.handlerCouponList(res.data || [], params.price, !!this.couponId);
// 设置优惠券个数
params.count = (res.data || []).length;
this.setGoodsInfo4Coupon(params);
}
......@@ -295,29 +294,48 @@ export default {
);
},
// 处理数据
// 先排序,再将不可用的放在最后
handlerCouponList(couponList, goodsPrice) {
// 处理数据,并且先排序,再将不可用的放在最后
handlerCouponList(couponList, goodsPrice, isFromGoodsList) {
if (!couponList.length) return [];
let newList = [],
obj = {},
firstCanCoupon = null;
firstCanCoupon = null,
firstCanCouponIndex = 0,
item = {};
couponList.sort( (a, b) => {
return b.discountAmount - a.discountAmount;
});
couponList.forEach(item => {
for(let i = 0; i < couponList.length; i ++) {
item = couponList[i];
// couponList.forEach(item => {
// 要根据商品价格及券适用类型来计算
item.disabled = !this.isCanSelect(item, goodsPrice);
// 是否已经选择
item.isChecked = false;
console.log('firstCanCoupon, item.disabled', firstCanCoupon, item.disabled);
// console.log('firstCanCoupon, item.disabled', firstCanCoupon, item.disabled);
if (!firstCanCoupon && !item.disabled) {
console.log('!firstCanCoupon');
item.isChecked = true;
firstCanCoupon = item;
firstCanCouponIndex = i;
}
newList.push(item);
});
}
// 如果是从商品列表选择过来的,则要选中这个优惠券
// 如果优惠券不可用
// if(isFromGoodsList) {
// let cCoupon = couponList.find( item => {
// return item.couponId == this.couponId;
// });
// if(cCoupon.isChecked) {
// firstCanCoupon = cCoupon;
// } else {
// firstCanCoupon = {};
// couponList[firstCanCouponIndex].isChecked = false;
// }
// }
// 将不可用的放在最后
let sortArray = [], c = {};
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册