freecard.js
1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Page({
data: {
freeDay: 0,
paddingH: 86,
textpadding: 508,
showAuthBtn: true
},
toPostFreeCard(merchantId, phone, userInfo) {
let para = {
merchantId,
phone
}
wx.p.api.couponsApi.tolqFreecard(para).then(res => {
wx.hideLoading()
const { errId, code, message } = res
if ((code == -1 && errId == 20313) || (code == -1 && errId == 20322)) {
wx.showModal({
title: '提示',
content: res.message,
confirmText: '确定',
showCancel: false,
confirmColor: '#F13C3D'
})
return
}
let bindInfo = {
code,
errId,
message,
data: {
sessionId: userInfo.sessionId
}
}
let temp = encodeURIComponent(JSON.stringify(bindInfo))
wx.p.storage.set('bindInfo', temp)
wx.p.router.reLaunch('/pages/tab/equity/index');
})
},
toGetFreeCardDay(merchantId) {
wx.p.api.couponsApi
.getFreeCardDay({
merchantId
})
.then(res => {
if (res) {
this.setData({
freeDay: res.freeDay || 0
})
}
})
},
async tofreeReceive() {
// 先判断登录
const loginStatus = !wx.p.isLogin
if (loginStatus) return
const userInfo = wx.p.storage.get('userInfo')
let { merchantId, phone } = userInfo
wx.p.wxApi.showLoading()
this.toPostFreeCard(merchantId, phone, userInfo)
},
onLoad(options) {
let system = wx.getSystemInfoSync()
const { merchantId } = wx.p.storage.get('merchant_info')
this.toGetFreeCardDay(merchantId)
this.setData({
paddingH: system.windowHeight * 0.11,
textpadding: system.windowHeight * 0.31
})
},
onUnload: function () {
}
})