feat 优惠券状态

develop
GJW200011 4 years ago
parent 2800719615
commit 01194eb66e

@ -2,7 +2,11 @@
import {
httpUtil,
http,
login_check
} from '../../../../utils/util'
import {
host
} from '../../../../Gdata'
Page({
/**
@ -16,10 +20,11 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getcollect_list(options.activity_id)
if (login_check(1)) {
this.getcollect_list(options.activity_id)
}
},
getcollect_list(activity_id) {
console.log(activity_id);
http("/api/v1/bind-coupon-list", "post", {
activity_id
}).then(res => {
@ -29,19 +34,57 @@ Page({
})
},
collect_receive(e) {
http("/api/v1/bind-coupon", "post", {
activity_id: e.currentTarget.dataset.id
}).then(res => {
wx.showToast({
title: '领取成功',
icon: 'success',
mask: true
})
this.data.coupons_list[e.currentTarget.dataset.index].is_received = 1
this.setData({
coupons_list: this.data.coupons_list
})
let token = getApp().globalData.token
let uid = getApp().globalData.uid
wx.request({
url: host + '/api/v1/bind-coupon',
method: 'post',
data: { activity_id: e.currentTarget.dataset.id },
header: {
token: token,
uid: uid
},
success: res => {
console.log(res, 'res');
if (res.data.status == 200) {
wx.showToast({
title: '领取成功',
icon: 'success',
duration: 1000,
mask: true
})
this.data.coupons_list[e.currentTarget.dataset.index].is_received = 1
this.setData({
coupons_list: this.data.coupons_list
})
} else {
wx.showToast({
title: '已抢光',
icon: 'error',
duration: 1000,
mask: true
})
this.data.coupons_list[e.currentTarget.dataset.index].is_received = 2
this.setData({
coupons_list: this.data.coupons_list
})
}
}
})
// http("/api/v1/bind-coupon", "post", {
// activity_id: e.currentTarget.dataset.id
// }).then(res => {
// console.log(res);
// wx.showToast({
// title: '领取成功',
// icon: 'success',
// mask: true
// })
// // this.data.coupons_list[e.currentTarget.dataset.index].is_received = 1
// // this.setData({
// // coupons_list: this.data.coupons_list
// // })
// })
},
mydiscount() {
wx.redirectTo({

@ -16,7 +16,8 @@
<view class="_ln">有效期至{{item.end_date}}</view>
</view>
<view class="_rightbtn" bindtap="collect_receive" data-id="{{item.id}}" data-index='{{index}}' wx:if="{{!item.is_received}}">领取</view>
<view class="_rightbtn received" wx:else>已领取</view>
<view class="_rightbtn received" wx:elif='{{item.is_received==1}}'>已领取</view>
<view class="_rightbtn received" wx:elif='{{item.is_received==2}}'>已抢光</view>
</view>
</view>
<button class="_button" bindtap="mydiscount">我的优惠券</button>

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save