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

请选择优惠券

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