2020-08-13 08:12:57 +00:00
|
|
|
<template>
|
|
|
|
<view>
|
|
|
|
<view class='coupon-list' v-if="couponsList.length">
|
|
|
|
<view class='item acea-row row-center-wrapper' v-for="(item,index) in couponsList" :key="index">
|
|
|
|
<view class='money' :class='item.isUse ? "moneyGray" : "" '>
|
2021-03-19 10:26:43 +00:00
|
|
|
<view>¥<text class='num'>{{item.money?Number(item.money):''}}</text></view>
|
|
|
|
<view class="pic-num">满{{item.minPrice?Number(item.minPrice):''}}元可用</view>
|
2020-08-13 08:12:57 +00:00
|
|
|
</view>
|
|
|
|
<view class='text'>
|
2021-01-19 02:16:45 +00:00
|
|
|
<view class='condition line2'>
|
|
|
|
<span class='line-title' :class='(item.isUse==true || item.isUse==2)?"gray":""' v-if='item.useType===1'>通用</span>
|
|
|
|
<span class='line-title' :class='(item.isUse==true || item.isUse==2)?"gray":""' v-else-if='item.useType===3'>品类</span>
|
|
|
|
<span class='line-title' :class='(item.isUse==true || item.isUse==2)?"gray":""' v-else>商品</span>
|
2020-08-13 08:12:57 +00:00
|
|
|
<span>{{item.name}}</span>
|
|
|
|
</view>
|
|
|
|
<view class='data acea-row row-between-wrapper'>
|
2021-01-19 02:16:45 +00:00
|
|
|
<view v-if="item.day>0">领取后{{item.day}}天内可用</view>
|
|
|
|
<view v-else>{{ item.useStartTimeStr&& item.useEndTimeStr ? item.useStartTimeStr + " - " + item.useEndTimeStr : ""}}</view>
|
2020-08-13 08:12:57 +00:00
|
|
|
<view class='bnt gray' v-if="item.isUse==true">已领取</view>
|
|
|
|
<view class='bnt bg-color' v-else @click='getCoupon(item.id,index)'>立即领取</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
<view class='loadingicon acea-row row-center-wrapper' v-if="couponsList.length">
|
|
|
|
<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
|
|
|
|
</view>
|
|
|
|
<view class='noCommodity' v-else-if="!couponsList.length && loading==true">
|
|
|
|
<view class='pictrue'>
|
|
|
|
<image src='../../../static/images/noCoupon.png'></image>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
<!-- #ifdef MP -->
|
2021-05-07 10:31:36 +00:00
|
|
|
<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
|
2020-08-13 08:12:57 +00:00
|
|
|
<!-- #endif -->
|
|
|
|
</view>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import {
|
|
|
|
getCoupons,
|
|
|
|
setCouponReceive
|
|
|
|
} from '@/api/api.js';
|
|
|
|
import {
|
|
|
|
toLogin
|
|
|
|
} from '@/libs/login.js';
|
|
|
|
import {
|
|
|
|
mapGetters
|
|
|
|
} from "vuex";
|
|
|
|
// #ifdef MP
|
|
|
|
import authorize from '@/components/Authorize';
|
|
|
|
// #endif
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
// #ifdef MP
|
|
|
|
authorize
|
|
|
|
// #endif
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
couponsList: [],
|
|
|
|
loading: false,
|
|
|
|
loadend: false,
|
|
|
|
loadTitle: '加载更多',//提示语
|
|
|
|
page: 1,
|
|
|
|
limit: 20,
|
|
|
|
isAuto: false, //没有授权的不会自动授权
|
|
|
|
isShowAuth: false //是否隐藏授权
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: mapGetters(['isLogin']),
|
2021-03-19 10:26:43 +00:00
|
|
|
watch: {
|
|
|
|
isLogin: {
|
|
|
|
handler: function(newV, oldV) {
|
|
|
|
if (newV) {
|
|
|
|
this.getUseCoupons();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
deep: true
|
|
|
|
}
|
|
|
|
},
|
2020-08-13 08:12:57 +00:00
|
|
|
onLoad(){
|
|
|
|
if(this.isLogin){
|
|
|
|
this.getUseCoupons();
|
|
|
|
}else{
|
2021-05-07 10:31:36 +00:00
|
|
|
// #ifdef H5 || APP-PLUS
|
2020-08-13 08:12:57 +00:00
|
|
|
toLogin();
|
2021-05-07 10:31:36 +00:00
|
|
|
// #endif
|
|
|
|
// #ifdef MP
|
|
|
|
this.isAuto = true;
|
|
|
|
this.$set(this, 'isShowAuth', true);
|
|
|
|
// #endif
|
2020-08-13 08:12:57 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom: function () {
|
|
|
|
this.getUseCoupons();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onLoadFun(){
|
|
|
|
this.getUseCoupons();
|
|
|
|
},
|
|
|
|
// 授权关闭
|
|
|
|
authColse:function(e){
|
|
|
|
this.isShowAuth = e
|
|
|
|
},
|
|
|
|
getCoupon:function(id,index){
|
|
|
|
let that = this;
|
|
|
|
let list = that.couponsList;
|
|
|
|
let ids = [];
|
|
|
|
ids.push(id);
|
|
|
|
//领取优惠券
|
2021-02-06 09:25:18 +00:00
|
|
|
setCouponReceive(id).then(function (res) {
|
2020-08-13 08:12:57 +00:00
|
|
|
list[index].isUse = true;
|
|
|
|
that.$set(that,'couponsList',list);
|
|
|
|
that.$util.Tips({ title: '领取成功' });
|
|
|
|
},function(res){
|
2020-09-15 08:13:25 +00:00
|
|
|
return that.$util.Tips({title:res});
|
|
|
|
})
|
2020-08-13 08:12:57 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 获取领取优惠券列表
|
|
|
|
*/
|
|
|
|
getUseCoupons:function(){
|
|
|
|
let that=this
|
|
|
|
if(this.loadend) return false;
|
|
|
|
if(this.loading) return false;
|
|
|
|
getCoupons({ page: that.page, limit: that.limit }).then(res=>{
|
|
|
|
let list=res.data,loadend=list.length < that.limit;
|
|
|
|
let couponsList = that.$util.SplitArray(list, that.couponsList);
|
|
|
|
that.$set(that,'couponsList',couponsList);
|
|
|
|
that.loadend = loadend;
|
|
|
|
that.loadTitle = loadend ? '我也是有底线的' : '加载更多';
|
|
|
|
that.page = that.page + 1;
|
|
|
|
that.loading = false;
|
|
|
|
}).catch(err=>{
|
|
|
|
that.loading = false;
|
|
|
|
that.loadTitle = '加载更多';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.condition .line-title{
|
|
|
|
width:90rpx;
|
|
|
|
padding: 0 10rpx;
|
|
|
|
box-sizing: border-box;
|
|
|
|
background:rgba(255,247,247,1);
|
|
|
|
border:1px solid rgba(232,51,35,1);
|
|
|
|
opacity:1;
|
|
|
|
border-radius:20rpx;
|
|
|
|
font-size:20rpx;
|
|
|
|
color: #E83323;
|
|
|
|
margin-right: 12rpx;
|
|
|
|
}
|
|
|
|
.condition .line-title.gray{
|
|
|
|
border-color:#BBB;
|
|
|
|
color:#bbb;
|
|
|
|
background-color:#F5F5F5;
|
|
|
|
}
|
|
|
|
.coupon-list .pic-num{
|
|
|
|
color: #FFFFFF;
|
|
|
|
font-size: 24rpx;
|
|
|
|
}
|
|
|
|
</style>
|