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

请选择优惠券

上级 90e54c92
...@@ -5,7 +5,10 @@ ...@@ -5,7 +5,10 @@
<div class="left"> <div class="left">
<p class="name" :class="{'status': !item.showStatus}">{{item.couponName}}</p> <p class="name" :class="{'status': !item.showStatus}">{{item.couponName}}</p>
<div class="other"> <div class="other">
<p v-if="item.validTimeType == 2" class="time-end" :class="{'status': !item.showStatus}">距离到期仅剩<span class="coupon-pc"> {{item.validTimeSpan}} </span></p> <p v-if="item.validTimeType == 2" class="time-end" :class="{'status': !item.showStatus}">
<span v-if="item.couponStatus == 0">领取后<span class="coupon-pc"> {{item.validTimeSpan}} </span>天内有效</span>
<span v-else>距离到期仅剩<span class="coupon-pc"> {{item.validTimeSpan}} </span></span>
</p>
<p v-else class="time-end" :class="{'status': !item.showStatus}">{{parseTime(item.startTime)}}{{parseTime(item.expireTime)}}</p> <p v-else class="time-end" :class="{'status': !item.showStatus}">{{parseTime(item.startTime)}}{{parseTime(item.expireTime)}}</p>
<p v-show="!item.isAll" class="rules"> <p v-show="!item.isAll" class="rules">
<span :class="{'status': !item.showStatus}" @click="toggleRules(item)">使用规则</span> <span :class="{'status': !item.showStatus}" @click="toggleRules(item)">使用规则</span>
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
<span>优惠券</span> <span>优惠券</span>
<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="selectCouponList.length" class="list-wrapper">
<p v-if="currentCoupon.couponId || goodsInfo4Coupon.count"> <p v-if="currentCoupon.couponId">
已选择1张优惠券,共抵扣 已选择1张优惠券,共抵扣
<span class="sc thin">¥{{yuan(currentCoupon.discountAmount)}}</span> <span class="sc thin">¥{{yuan(currentCoupon.discountAmount)}}</span>
</p> </p>
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
</article> </article>
<no-coupon v-else></no-coupon> <no-coupon v-else></no-coupon>
<article class="bottom"> <article v-if="selectCouponList.length" class="bottom">
<van-button @click="confirm" size="large" round color="#449284">确定使用</van-button> <van-button @click="confirm" size="large" round color="#449284">确定使用</van-button>
</article> </article>
</section> </section>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</template> </template>
<script> <script>
import CommonNavbar from "@/components/common/common-navbar"; import CommonNavbar from "@/components/common/common-navbar";
import CouponList from "@/components/coupon/com-coupon-list"; import CouponList from "@/components/coupon/component-list";
import NoCoupon from "@/components/coupon/no-coupon"; import NoCoupon from "@/components/coupon/no-coupon";
import { getWebPageUrl, getHactiveUrl } from "@/utils"; import { getWebPageUrl, getHactiveUrl } from "@/utils";
import { mapGetters, mapActions } from "vuex"; import { mapGetters, mapActions } from "vuex";
...@@ -93,7 +93,9 @@ export default { ...@@ -93,7 +93,9 @@ export default {
return; return;
} }
if (token && !info.id) { if (token && !info.id) {
this.$store.dispatch("getUserInfo"); this.commonCheckToken(() => {
this.$store.dispatch("getUserInfo");
});
return; return;
} }
// 从登陆页面过来的 // 从登陆页面过来的
...@@ -210,7 +212,7 @@ export default { ...@@ -210,7 +212,7 @@ export default {
if (item.couponStatus == 1) { if (item.couponStatus == 1) {
let pageUrl = ""; let pageUrl = "";
if(item.couponMappingModelList.length > 1) { if(item.couponMappingModelList.length > 1) {
pageUrl = getHactiveUrl(`/message_push/#/study-card`); pageUrl = getHactiveUrl(`/message_push/#/study-card?origin=1`);
this.jumpForCoupon(pageUrl); this.jumpForCoupon(pageUrl);
} else { } else {
item.couponMappingModelList.length && this.getCardInfoByProvinceId(item.couponMappingModelList[0], item); item.couponMappingModelList.length && this.getCardInfoByProvinceId(item.couponMappingModelList[0], item);
......
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
import { Swipe, SwipeItem } from "vant"; import { Swipe, SwipeItem } from "vant";
import Loading from "@/components/common/common-loading"; import Loading from "@/components/common/common-loading";
import CourseDialog from "@/components/course/course-dialog"; import CourseDialog from "@/components/course/course-dialog";
import CouponSelectList from "@/components/coupon/com-coupon-select-list"; import CouponSelectList from "@/components/coupon/component-select-list";
import { wxConfig, chooseWXPay } from "@/utils/wxShare"; import { wxConfig, chooseWXPay } from "@/utils/wxShare";
import { import {
...@@ -143,7 +143,8 @@ export default { ...@@ -143,7 +143,8 @@ export default {
showLoading: false, showLoading: false,
isShowDialog: false, isShowDialog: false,
isShowCoupon: false, //是否展示激活弹框, isShowCoupon: false, //是否展示激活弹框,
courseUrl: "" courseUrl: "",
defaultCouponId: "",
}; };
}, },
computed: { computed: {
...@@ -194,7 +195,7 @@ export default { ...@@ -194,7 +195,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.couponIdFromGoodsList = this.$route.query.couponId || ""; //
this.shareUrl = getWebPageUrl( this.shareUrl = getWebPageUrl(
`profexam/#/goods-detail?goodsId=${this.goodsId}` `profexam/#/goods-detail?goodsId=${this.goodsId}`
); );
...@@ -244,7 +245,9 @@ export default { ...@@ -244,7 +245,9 @@ export default {
if (this.isWeb) { if (this.isWeb) {
const { token, info } = this.$store.state.user; const { token, info } = this.$store.state.user;
if (token && !info.id) { if (token && !info.id) {
this.$store.dispatch("getUserInfo"); this.commonCheckToken(() => {
this.$store.dispatch("getUserInfo");
});
return; return;
} }
// 从登陆页面过来时 // 从登陆页面过来时
...@@ -285,23 +288,29 @@ export default { ...@@ -285,23 +288,29 @@ 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.couponId);
// 设置优惠券个数
params.count = (res.data || []).length; params.count = (res.data || []).length;
this.setGoodsInfo4Coupon(params); this.setGoodsInfo4Coupon(params);
this.handlerCouponList(res.data || [], params.price);
// 设置优惠券个数
} else {
params.count = 0;
this.setGoodsInfo4Coupon(params);
this.setCurrentCoupon({});
this.setSelectCouponList([]);
} }
} }
); );
}, },
// 处理数据,并且先排序,再将不可用的放在最后 // 处理数据,并且先排序,再将不可用的放在最后
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, firstCanCouponIndex = 0,
item = {}; item = {},
count = 0;
couponList.sort( (a, b) => { couponList.sort( (a, b) => {
return b.discountAmount - a.discountAmount; return b.discountAmount - a.discountAmount;
}); });
...@@ -310,6 +319,9 @@ export default { ...@@ -310,6 +319,9 @@ export default {
// couponList.forEach(item => { // couponList.forEach(item => {
// 要根据商品价格及券适用类型来计算 // 要根据商品价格及券适用类型来计算
item.disabled = !this.isCanSelect(item, goodsPrice); item.disabled = !this.isCanSelect(item, goodsPrice);
if(!item.disabled) {
count ++;
}
// 是否已经选择 // 是否已经选择
item.isChecked = false; item.isChecked = false;
// console.log('firstCanCoupon, item.disabled', firstCanCoupon, item.disabled); // console.log('firstCanCoupon, item.disabled', firstCanCoupon, item.disabled);
...@@ -337,6 +349,20 @@ export default { ...@@ -337,6 +349,20 @@ export default {
// } // }
// } // }
// 商品详情接口已经选择了一张, 则使用默认的
if(this.defaultCouponId) {
let cCoupon = couponList.find( item => {
return item.couponId == this.defaultCouponId;
});
if(cCoupon && cCoupon.isChecked) {
firstCanCoupon = cCoupon;
} else {
firstCanCoupon = {};
couponList[firstCanCouponIndex].isChecked = false;
}
}
// 将不可用的放在最后 // 将不可用的放在最后
let sortArray = [], c = {}; let sortArray = [], c = {};
for(let i = 0; i < newList.length; i ++) { for(let i = 0; i < newList.length; i ++) {
...@@ -348,8 +374,10 @@ export default { ...@@ -348,8 +374,10 @@ export default {
} }
} }
this.setCurrentCoupon(firstCanCoupon || {}); this.setCurrentCoupon( JSON.parse(JSON.stringify(firstCanCoupon)) || {});
this.setSelectCouponList(newList.concat(sortArray)); this.setSelectCouponList(newList.concat(sortArray));
this.goodsInfo4Coupon.count = count;
this.setGoodsInfo4Coupon(this.goodsInfo4Coupon);
return newList; return newList;
}, },
...@@ -415,7 +443,9 @@ export default { ...@@ -415,7 +443,9 @@ export default {
// 显示优惠券弹框 // 显示优惠券弹框
showCouponPopup() { showCouponPopup() {
this.isShowCoupon = true; this.commonCheckToken(() => {
this.isShowCoupon = true;
})
}, },
// 设置当前选中的优惠券 // 设置当前选中的优惠券
...@@ -425,7 +455,7 @@ export default { ...@@ -425,7 +455,7 @@ export default {
this.getCPText(); this.getCPText();
this.isShowCoupon = false; this.isShowCoupon = false;
// 要重新调用计算价格接口 // 要重新调用计算价格接口
this.getTotalPrice(currentCoupon); // this.getTotalPrice(currentCoupon);
}, },
// tab切换 // tab切换
...@@ -447,6 +477,7 @@ export default { ...@@ -447,6 +477,7 @@ export default {
let price = let price =
goods.couponPrice || goods.preferentialPrice || goods.costPrice; goods.couponPrice || goods.preferentialPrice || goods.costPrice;
this.goods = goods; this.goods = goods;
this.defaultCouponId = goods.couponId;
// 获取到商品后,再获取优惠券 // 获取到商品后,再获取优惠券
this.getCanUseCoupons({ this.getCanUseCoupons({
goodsType: goods.goodsType, goodsType: goods.goodsType,
...@@ -520,7 +551,7 @@ export default { ...@@ -520,7 +551,7 @@ export default {
// TODO,要多传优惠券id参数 // TODO,要多传优惠券id参数
getTotalPrice(coupon) { getTotalPrice(coupon) {
console.log('coupon', coupon); console.log('coupon', coupon);
const couponId = this.currentCoupon.couponId || 0; // const couponId = this.currentCoupon.couponId || 0;
const num = this.curtGoodsNum; const num = this.curtGoodsNum;
// this.GET(`trade/goods/getPrice/${this.goodsId}/${num}/${couponId}`, {}).then(res => { // this.GET(`trade/goods/getPrice/${this.goodsId}/${num}/${couponId}`, {}).then(res => {
this.GET(`trade/goods/getPrice/${this.goodsId}/${num}`, {}).then(res => { this.GET(`trade/goods/getPrice/${this.goodsId}/${num}`, {}).then(res => {
...@@ -672,6 +703,7 @@ export default { ...@@ -672,6 +703,7 @@ export default {
return; return;
} }
const orderData = { const orderData = {
// couponId: couponDTO ? couponDTO.couponId : 0,
couponId: couponDTO ? couponDTO.couponId : 0, couponId: couponDTO ? couponDTO.couponId : 0,
goodsId: id, goodsId: id,
goodsQuantity: this.goodsNum, goodsQuantity: this.goodsNum,
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册