index.js
5.18 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// packageActivity/pages/redEnvelope/index/index.js
import {
jumpAuthMixin
} from '~/mixins/index'
import {
domain
} from '~/api/env/index'
Page({
behaviors: [jumpAuthMixin],
/**
* 页面的初始数据
*/
data: {
count: 3
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
const {
options
} = this
console.log(options)
if (options.isLogin) this.getRedEnvelopeH5()
else this.jumpLoading() //直接打开时跳转、防止sessionId失效
},
async getRedEnvelopeH5() {
const res = await wx.p.router.intercept()
if (!res) {
const {
userInfo
} = this.data
let {
id,
awardInfoId,
activityId,
businessId,
source,
linkId
} = this.options
if (!activityId) {
activityId = id
this.options.activityId = id
}
if (!userInfo.nickName) return this.getNickNameAndHeadUrl()
try {
const {
sourceType
} = await wx.p.api.solitaireApi.getActivityRedEnvelopeDetail({
id: activityId
})
/**接龙奖品回显 */
if (awardInfoId) this.jumpRedEnvelopeH5({
activityId
}, () => {
this.jump()
})
else {
if (linkId) this.jumpRedEnvelopeH5({
activityId,
linkId,
source
})
else {
const {
code,
data,
errId,
message
} = await wx.p.api.questionnaireApi.bindRedEnvelopeLink({
activityId,
bindingSource: source,
wechatName: userInfo.nickName,
businessId
})
if (code == 0) {
if (data.id && data.link) {
// /**sourceType 0-自研,1-外采 */
if (sourceType == 1) {
this.showRedModel()
this.jumpUrl = data.link
} else this.jumpRedEnvelopeH5({
activityId,
linkId: data.id,
source
})
} else throw {
message,
errId
}
} else throw {
message,
errId
}
}
}
} catch ({
message,
errId
}) {
if (message) wx.showModal({
title: '温馨提示',
content: message,
confirmText: '知道了',
showCancel: false,
confirmColor: '#F13C3D',
success: function (res) {
if (res.confirm) {
if (errId == '202207218' || errId == '202207224') wx.p.router.redirectTo('/packageActivity/pages/redEnvelope/record/record')
else wx.p.router.switchTab('/pages/tab/mine/index') //错误统一跳转至我的
}
}
})
}
}
},
jumpRedEnvelopeH5({
activityId,
linkId,
source
}, callBack) {
const {
awardInfoId,
merchantId,
recordId
} = this.options, {
userInfo: {
accountId,
nickName,
unionId,
openid,
phone
},
userInfo
} = this.data, {
sessionId
} = wx.p.storage.get()
let user = encodeURIComponent(JSON.stringify({
accountId,
nickName,
unionId,
openid,
phone
})),
query = `activityId=${activityId}&merchantId=${merchantId || userInfo.merchantId}&sessionId=${sessionId}&userInfo=${user}`
if (linkId) query += `&linkId=${linkId}`
// 绑定来源 0:权益会员卡;1:调查问卷;2:群接龙
if (source > -1) query += `&source=${source}`
if (recordId) query += `&recordId=${recordId}`
if (awardInfoId) query += `&awardInfoId=${awardInfoId}`
this.linkQuery = query
if (callBack) callBack()
else this.showRedModel()
},
showRedModel() {
this.setData({
show: true
})
this.countDown()
},
countDown() {
let {
count,
isJump
} = this.data
let _this = this
if (count == 0) {
!isJump && this.jump()
if (this.timer) clearTimeout(this.timer)
return
}
this.timer = setTimeout(() => {
_this.setData({
count: count - 1
})
this.countDown()
}, 1e3)
},
jump() {
this.setData({
isJump: true,
show: false,
})
if (this.timer) clearTimeout(this.timer)
/**jumpUrl 外采链接 */
let url = this.jumpUrl ? this.jumpUrl : `${domain}/scrm-wx-red-packet/#/redEnvelope?${this.linkQuery}` //测试、预发布、生产
// url: `${domain}/dj-scrm-wx-work-main-lwk/#/?${this.linkQuery}` //开发环境
wx.p.router.redirectToH5(url)
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
}
})