feat 优惠券状态

develop
GJW200011 4 years ago
parent 2800719615
commit 01194eb66e

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

@ -16,7 +16,8 @@
<view class="_ln">有效期至{{item.end_date}}</view> <view class="_ln">有效期至{{item.end_date}}</view>
</view> </view>
<view class="_rightbtn" bindtap="collect_receive" data-id="{{item.id}}" data-index='{{index}}' wx:if="{{!item.is_received}}">领取</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>
</view> </view>
<button class="_button" bindtap="mydiscount">我的优惠券</button> <button class="_button" bindtap="mydiscount">我的优惠券</button>

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