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

已选择1张优惠券,共抵扣

上级 e75c96e8
<template> <template>
<van-popup v-model="isShowCoupon" @click-overlay="cancle" position="bottom" class="coupon-select"> <van-popup v-model="isShow" @click-overlay="cancle" position="bottom" class="coupon-select">
<section class="coupon-select-wrapper"> <section class="coupon-select-wrapper">
<article class="title"> <article class="title">
<span>优惠券</span> <span>优惠券</span>
...@@ -8,31 +8,34 @@ ...@@ -8,31 +8,34 @@
<article v-if="true" class="list-wrapper"> <article v-if="true" class="list-wrapper">
<p> <p>
已选择1张优惠券,共抵扣 已选择1张优惠券,共抵扣
<span class="sc thin">¥{{couponPrice}}</span> <span class="sc thin">¥{{yuan(currentCoupon.discountAmount)}}</span>
</p> </p>
<div <div
class="item" class="item"
@click="toggleChecked(item)" @click="toggleChecked(item)"
:class="{'disabled': disabled}" :class="{'disabled': item.disabled}"
v-for="(item, index) in dataList" v-for="(item, index) in selectCouponList"
:key="index" :key="index"
> >
<div class="left opacity"> <div class="left opacity">
<p class="price"> <p class="price">
<span class="symbol sc">¥</span> <span class="symbol sc">¥</span>
<span class="num sc">{{item.discountAmount}}</span> <span class="num sc">{{yuan(item.discountAmount)}}</span>
</p> </p>
<p class="desc">{{item.requiredTotalFee}}元可用</p> <p class="desc">{{yuan(item.requiredTotalFee)}}元可用</p>
</div> </div>
<div class="center"> <div class="center">
<p class="name status">{{item.couponName}}</p> <p class="name status">{{item.couponName}}</p>
<div> <div>
<p v-if="item.validTimeType == 2" class="date"> <p v-if="item.validTimeType == 2" class="date">
距离到期仅剩 距离到期仅剩
<span class="sc"> {{item.validLeftDays}} </span> <span class="sc">{{item.validLeftDays}}</span>
</p> </p>
<p v-else class="date status">{{item.startTime}}{{item.expireTime}}</p> <p
<p v-if="disabled" class="tips"> v-else
class="date status"
>{{parseTime(item.startTime)}}{{parseTime(item.expireTime)}}</p>
<p v-if="item.disabled" class="tips">
<img @click="cancle" src="../../images/coupon/tips.png" /> <img @click="cancle" src="../../images/coupon/tips.png" />
<span>当前商品不可用</span> <span>当前商品不可用</span>
</p> </p>
...@@ -54,46 +57,65 @@ ...@@ -54,46 +57,65 @@
</template> </template>
<script> <script>
import NoCoupon from "@/components/coupon/no-coupon"; import NoCoupon from "@/components/coupon/no-coupon";
import { convertToYuan, parseTime } from "@/utils";
import { mapGetters, mapActions } from "vuex";
export default { export default {
components: { components: {
NoCoupon NoCoupon
}, },
props: { props: {
isShowCoupon: { showSelectCoupon: {
type: Boolean, type: Boolean,
default: true default: true
}, },
dataList: { // currentCoupon: {
type: Array, // type: Object,
default: () => [] // default: () => {
}, // return {};
goodsInfo: { // }
type: Object, // }
default: () => { // goodsInfo4Coupon: {
return { // type: Object,
price: 0, // default: () => {
goodsType: 0, // return {};
cardType: 0 // }
}; // }
}
}
}, },
data() { data() {
return { return {
couponPrice: 100, currentCouponInfo: {}
disabled: false,
isChecked: true,
currentCoupon: { couponId: "", canUseNum: 0, couponPrice: 0 }
}; };
}, },
// //
watch: { watch: {
// isShowCoupon: { isShowCoupon: {
// // 处理是否可用 // 处理是否可用
// handler(newVal) {} handler(newVal) {
// } // 如果打开了选择弹框,则重新选中已经选中的项目
if (newVal) {
this.currentCouponInfo = this.currentCoupon;
}
}
},
// 监听当前商品信息,如果价格改变,则要重新计算选择列表是否可用
goodsInfo4Coupon: {
handler(goodsInfo) {},
deep: true
}
},
computed: {
...mapGetters(['currentCoupon', 'goodsInfo4Coupon', 'selectCouponList']),
isShow: {
get() {
return this.showSelectCoupon;
},
set() {}
}
}, },
mounted() { mounted() {
...@@ -107,19 +129,32 @@ export default { ...@@ -107,19 +129,32 @@ export default {
// 查找已经选择的 // 查找已经选择的
confirm() { confirm() {
this.$emit("confirm", this.currentCoupon); this.$emit("confirm", this.currentCouponInfo);
}, },
// 切换当前选中优惠券 // 切换当前选中优惠券
toggleChecked(item) { toggleChecked(item) {
if(item.disabled) return;
if (!item.isChecked) { if (!item.isChecked) {
this.dataList.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;
} else { } else {
this.currentCouponInfo = {};
item.isChecked = false; item.isChecked = false;
} }
},
// 显示元
yuan(fen) {
return convertToYuan(fen);
},
// parseTime
parseTime(time) {
return parseTime(time, "{yyyy}-{mm}-{dd}");
} }
} }
}; };
......
...@@ -17,5 +17,10 @@ const getters = { ...@@ -17,5 +17,10 @@ const getters = {
totalCount: state => state.question.titleConfig.totalCount, totalCount: state => state.question.titleConfig.totalCount,
canRunNext: state => state.question.canRunNext, canRunNext: state => state.question.canRunNext,
webUserInfo: state => state.user.info, webUserInfo: state => state.user.info,
// 优惠券相关
currentCoupon: state => state.coupon.currentCoupon,
goodsInfo4Coupon: state => state.coupon.goodsInfo4Coupon,
selectCouponList: state => state.coupon.selectCouponList,
} }
export default getters export default getters
...@@ -3,6 +3,7 @@ import Vuex from 'vuex' ...@@ -3,6 +3,7 @@ import Vuex from 'vuex'
import coop from './modules/coop' import coop from './modules/coop'
import user from './modules/user' import user from './modules/user'
import question from './modules/question' import question from './modules/question'
import coupon from './modules/coupon';
import getters from './getters' import getters from './getters'
Vue.use(Vuex) Vue.use(Vuex)
...@@ -11,7 +12,8 @@ const store = new Vuex.Store({ ...@@ -11,7 +12,8 @@ const store = new Vuex.Store({
modules: { modules: {
coop, coop,
user, user,
question question,
coupon
}, },
getters getters
}) })
......
const coupon = {
state: {
currentCoupon: {},
goodsInfo4Coupon: {},
selectCouponList: [],
},
mutations: {
SET_CURRENT_COUPON: (state, payload) => {
state.currentCoupon = payload;
},
SET_GOODS_INFO_COUPON: (state, payload) => {
state.goodsInfo4Coupon = payload;
},
SET_SELECT_COUPON_LIST: (state, payload) => {
state.selectCouponList = payload;
},
},
actions: {
// 设置当前选中的优惠券
setCurrentCoupon({ commit }, currentCoupon) {
commit("SET_CURRENT_COUPON", currentCoupon);
},
// 设置当前商品的信息(包括:总价格, goodsType, cardType)
setGoodsInfo4Coupon({ commit }, goodsInfo4Coupon) {
commit("SET_GOODS_INFO_COUPON", goodsInfo4Coupon);
},
// 这里只处理disabled的状态
setSelectCouponList({ commit, state }, selectCouponList) {
let goodsInfo4Coupon = state.goodsInfo4Coupon;
let price = goodsInfo4Coupon.price;
let flag = false;
selectCouponList.forEach( item => {
if( price > item.requiredTotalFee) {
}
})
commit("SET_SELECT_COUPON_LIST", selectCouponList);
},
},
}
export default coupon;
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<div class="name "> <div class="name ">
优惠券 优惠券
</div> </div>
<div @click="showCouponPopup" class="coupon-select coupon-pc">100</div> <div @click="showCouponPopup" class="coupon-select coupon-pc">{{yuan(currentCoupon.discountAmount)}}</div>
</div> </div>
<div class="flex buy-way"> <div class="flex buy-way">
...@@ -79,12 +79,10 @@ ...@@ -79,12 +79,10 @@
<Loading v-show="showLoading" /> <Loading v-show="showLoading" />
<!-- 优惠券弹框 --> <!-- 优惠券弹框 -->
<CouponSelectList <CouponSelectList v-if="isShowCoupon"
:dataList="couponDataList" :showSelectCoupon="isShowCoupon"
:goodsInfo="goodsInfo4Conpon"
:isShowCoupon="isShowCoupon"
@cancle="closeCouponPopup" @cancle="closeCouponPopup"
@confirm="showCouponPopup"> @confirm="setCurrentPopup">
</CouponSelectList> </CouponSelectList>
<CourseDialog <CourseDialog
...@@ -109,6 +107,7 @@ import CouponSelectList from "@/components/coupon/coupon-select-list"; ...@@ -109,6 +107,7 @@ import CouponSelectList from "@/components/coupon/coupon-select-list";
import { wxConfig, chooseWXPay } from '@/utils/wxShare'; import { wxConfig, chooseWXPay } from '@/utils/wxShare';
import { getAPPID, getTradeType, getWebPageUrl, isWeiXin, wxOauth, debounce, getHactiveUrl } from '@/utils'; import { getAPPID, getTradeType, getWebPageUrl, isWeiXin, wxOauth, debounce, getHactiveUrl } from '@/utils';
import { mapGetters, mapActions } from "vuex"; import { mapGetters, mapActions } from "vuex";
import { convertToYuan } from "@/utils";
const isWechat = isWeiXin(); const isWechat = isWeiXin();
// wxConfig(location.href); // wxConfig(location.href);
...@@ -138,13 +137,10 @@ export default { ...@@ -138,13 +137,10 @@ export default {
isShowDialog: false, isShowDialog: false,
isShowCoupon: false, //是否展示激活弹框, isShowCoupon: false, //是否展示激活弹框,
courseUrl: "", courseUrl: "",
couponDataList: [],
currentCoupon: {couponId: '', canUseNum: 0, couponPrice: ''},
goodsInfo4Conpon: {}
} }
}, },
computed: { computed: {
...mapGetters(["userInfo", "webUserInfo"]), ...mapGetters(["userInfo", "webUserInfo", "currentCoupon", "goodsInfo4Coupon", "selectCouponList"]),
wxInfo() { wxInfo() {
return this.$store.state.user.wxInfo; return this.$store.state.user.wxInfo;
}, },
...@@ -169,9 +165,9 @@ export default { ...@@ -169,9 +165,9 @@ export default {
}, },
// 监听当前商品信息 // 监听当前商品信息
goodsInfo4Conpon: { goodsInfo4Coupon: {
handler(goodsInfo) { handler(goodsInfo) {
this.setSelectCouponList(this.selectCouponList);
}, },
deep: true deep: true
} }
...@@ -234,31 +230,40 @@ export default { ...@@ -234,31 +230,40 @@ export default {
sessionStorage.setItem('goodsDetailParams', JSON.stringify(this.$route.query)) sessionStorage.setItem('goodsDetailParams', JSON.stringify(this.$route.query))
}, },
methods: { methods: {
...mapActions(["setUserInfo"]), ...mapActions(["setUserInfo", "setCurrentCoupon", "setGoodsInfo4Coupon", "setSelectCouponList"]),
// 获取我的优惠券列表 // 查询我的可用优惠券
getCanUseCoupons() { getCanUseCoupons() {
// this.GET(`trade/coupon/app/myCoupons`, {}).then(res => {
this.GET(`trade/coupon/app/goodsCoupons`, {}).then(res => { this.GET(`trade/coupon/app/goodsCoupons`, {}).then(res => {
if (res.code == "000000") { if (res.code == "000000") {
this.couponDataList = this.handlerCouponList(res.data || []); this.handlerCouponList(res.data || []);
} }
}) })
}, },
// 处理数据
handlerCouponList(couponList) { handlerCouponList(couponList) {
if(!couponList.length) return [] if(!couponList.length) return []
let newList = [], obj = {}; let newList = [], obj = {};
this.setCurrentCoupon(JSON.parse(JSON.stringify(couponList[0])));
couponList.forEach( item => { couponList.forEach( item => {
// 是否是列表页面,否则是我的优惠券页面 // TODO 要根据商品价格及券适用类型来计算
item.isAll = false; item.disabled = this.isCanSelect();
// 是否可用 // item.disabled = !(item.couponStatus == 0 || item.couponStatus == 1);
// 是否已经选择
item.isChecked = false; item.isChecked = false;
newList.push(item); newList.push(item);
}); });
couponList[0].isChecked = true;
this.setSelectCouponList(newList);
return newList; return newList;
}, },
// 判断是否可用
isCanSelect(){
return false;
},
//获取用户信息 //获取用户信息
getUserInfo() { getUserInfo() {
...@@ -306,6 +311,13 @@ export default { ...@@ -306,6 +311,13 @@ export default {
this.isShowCoupon = true; this.isShowCoupon = true;
}, },
// 设置当前选中的优惠券
setCurrentPopup(currentCoupon) {
console.log('setCurrentPopup', currentCoupon);
this.setCurrentCoupon(currentCoupon);
this.isShowCoupon = false;
},
// tab切换 // tab切换
tabToggle(index) { tabToggle(index) {
this.curtTabIdx = index; this.curtTabIdx = index;
...@@ -319,11 +331,11 @@ export default { ...@@ -319,11 +331,11 @@ export default {
const goods = res.data; const goods = res.data;
const tabs = []; const tabs = [];
let price = goods.couponPrice || goods.preferentialPrice || goods.costPrice; let price = goods.couponPrice || goods.preferentialPrice || goods.costPrice;
this.goodsInfo4Conpon = { this.setGoodsInfo4Coupon({
price: price, price: price,
goodsType: goods.goodsType, goodsType: goods.goodsType,
cardType: goods.cardType, cardType: goods.cardType,
} });
// 获取到商品后,再获取优惠券 // 获取到商品后,再获取优惠券
this.getCanUseCoupons(); this.getCanUseCoupons();
goods.salePrice = this.formatPrice(price); goods.salePrice = this.formatPrice(price);
...@@ -397,7 +409,7 @@ export default { ...@@ -397,7 +409,7 @@ export default {
costPriceText: (costPrice / 100).toFixed(2), costPriceText: (costPrice / 100).toFixed(2),
savePrice: savePrice ? (savePrice / 100).toFixed(2) : 0, savePrice: savePrice ? (savePrice / 100).toFixed(2) : 0,
} }
this.goodsInfo4Conpon.price = price; this.goodsInfo4Coupon.price = price;
this.goodsNum = num; this.goodsNum = num;
} else if (res.code === "200006") { } else if (res.code === "200006") {
this.$store.dispatch('logout') this.$store.dispatch('logout')
...@@ -627,7 +639,12 @@ export default { ...@@ -627,7 +639,12 @@ export default {
this.$toast(res.message); this.$toast(res.message);
} }
}) })
} },
// 显示元
yuan(fen) {
return convertToYuan(fen);
},
}, },
} }
</script> </script>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册