index.js
9.09 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
// packageActivity/pages/solitaire/index/index.js
import {
jumpAuthMixin
} from "~/mixins/index";
const generateOptionsArray = function (count = 9) {
return Array.from({
length: count
}, (_, index) => Number(index + 1))
}
Page({
behaviors: [jumpAuthMixin],
/**
* 页面的初始数据
*/
data: {
list: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
const {
options
} = this
console.log(options,'--------')
if (options.id) this.options.relayLotteryId = options.id
if (options.isLogin) this.getGroupEnterInfo(options)
else this.jumpLoading() //直接打开时跳转、防止sessionId失效
},
async getGroupEnterInfo(options) {
//测试时需要分享测试
// let query = []
// Object.keys(options).map(key => {
// if (key != 'isLogin') query.push(`${key}=${options[key]}`)
// })
// this.shareQuery = query.join('&')
// this.noPageAuth = true
const res = await wx.p.router.intercept()
if (!res) {
const {
userInfo
} = this.data
if (!userInfo.nickName) return this.getNickNameAndHeadUrl()
try {
const _this = this
wx.getGroupEnterInfo({
async success({
iv,
encryptedData
}) {
const {
data,
code,
message
} = await wx.p.api.userApi.getOpengid({
iv,
encryptedData
})
if (code == 0 && data) {
console.log('openGid:', data)
const res = await wx.p.api.userApi.openGIdtoChatId({
merchantId: options.merchantId,
openGid: data
})
console.log('chatId:', res.data)
options.chatId = res.data || ''
this.options = options
_this.getSolitaireDetail(options)
} else throw message
},
fail(err) {
_this.getSolitaireDetail(options)
}
})
} catch (error) {
if (error) wx.p.wxApi.showToast(error)
}
}
},
/**获取用户接龙信息 */
async getSolitaireUserInfo(params) {
delete params.isLogin
try {
const {
userInfo: {
nickName: name,
phone,
openId,
unionId
}
} = this.data, {
code,
data,
message
} = await wx.p.api.solitaireApi.getSolitaireUserInfo({
...params,
name,
phone,
openId,
unionId
})
if (code == 0) {
if (data) {
/**
* recordId 记录id
* stateCode 状态码 -1.未参与 0.已参加 1.未中奖 2.已中奖
* relayContent 接龙内容
* prizeType 奖品类型 1.红包 2.优惠券 3.权益
* prizeId 奖品id (已领取时返回)
* claimState 领取状态 0.未领取 1.已领取
*/
const {
stateCode,
stateName,
relayContent,
claimState,
prizeType,
recordId,
prizeId
} = data
if (stateCode == 2) {
this.setData({
disabled: true
})
if (claimState == 0) {
if (prizeType == 1) this.bindActivityRedEnvelope(recordId)
else this.getCoupon(recordId)
} else {
if (prizeType == 1) this.getRedEnvelopeAwardInfo({
awardInfoId: prizeId,
params
})
else this.getCouponInfo(prizeId)
}
} else {
if (stateCode == 0 || stateCode == 1) this.setData({
['popupConfig.type']: stateCode == 0 ? 1 : 2,
['popupConfig.title']: stateName || '',
})
this.setData({
show: stateCode == 0 || stateCode == 1,
disabled: stateCode == 1,
['popupConfig.relayContent']: relayContent
})
}
}
} else throw message
} catch (error) {
console.log(error)
this.showGroupNoAccess(error)
}
},
async getCoupon(recordId) {
const {
activityObject: {
rewardId,
merchantId,
merchantName
}
} = this.data,
data = await wx.p.api.solitaireApi.getCoupon({
couponId: rewardId,
merchantId,
merchantName
})
if (data && data.length) {
let [info] = data
this.setCouponInfo(info)
wx.p.api.solitaireApi.recordedPrizeInfo({
prizeId: info.userCouponId,
recordId
})
} else wx.p.wxApi.showToas('奖品已发完')
},
async getCouponInfo(userCouponId) {
const info = await wx.p.api.couponsApi.couponsDetail({
userCouponId
})
info.userCouponId = userCouponId
this.setCouponInfo(info)
},
setCouponInfo(info) {
info.receiveStartTime = new Date(info.receiveStartTime).format('yyyy/MM/dd')
info.receiveEndTime = new Date(info.receiveStartTime).format('yyyy/MM/dd')
if (info.discountIntensity) info.discountIntensity = Number(info.discountIntensity / 100)
if (info.denomination) info.denomination = Number(info.denomination / 100)
info.id = info.userCouponId
this.setData({
couponInfo: info,
showCoupon: true
})
},
/**获取接龙活动详情 */
async getSolitaireDetail(params) {
try {
wx.p.wxApi.showLoading()
const res = await wx.p.api.solitaireApi.getSolitaireDetail(params)
this.getSolitaireUserInfo(params)
this.getSolitaireAewardList(params)
this.setData({
activityDetail: decodeURIComponent(wx.p.format.encodeSearchKey(res.description)),
title: res.title,
array: generateOptionsArray(res.numLimit),
loading: true,
activityObject: res
})
if (new Date(wx.p.format.iosTimeFormat(res.lotteryTime)).getTime() <= Date.now()) this.setData({
['popupConfig.numWin']: res.numWin
})
wx.p.wxApi.hideLoading()
} catch (error) {
console.log(error)
if (error) wx.p.wxApi.showToast(error)
}
},
/**获取接龙明细 */
async getSolitaireAewardList(params) {
const {
list
} = await wx.p.api.solitaireApi.getSolitaireAewardList(params)
this.setData({
list: list.reverse()
})
},
/**领取红包 */
async bindActivityRedEnvelope(recordId) {
const {
activityObject: {
rewardId,
id
},
userInfo
} = this.data
wx.p.router.redirectTo('/packageActivity/pages/redEnvelope/index/index', {
activityId: rewardId,
merchantId: userInfo.merchantId,
source: 2,
recordId,
isLogin: 1,
businessId: id
})
},
/**红包活动回显 */
async getRedEnvelopeAwardInfo({
awardInfoId,
params
}) {
const {
activityObject: {
rewardId
}
} = this.data
wx.p.router.redirectTo('/packageActivity/pages/redEnvelope/index/index', {
activityId: rewardId,
merchantId: params.merchantId,
awardInfoId,
isLogin: 1
})
},
showGroupNoAccess(title) {
this.setData({
['popupConfig.type']: 1,
['popupConfig.title']: title,
['popupConfig.showDefault']: true,
show: true,
disabled: true
})
},
bindPickerChange(e) {
this.setData({
'params.num': this.data.array[e.detail.value]
})
},
inSolitaire() {
const {
userInfo
} = this.data
this.setData({
flag: true
})
this.setData({
'params.name': userInfo.nickName
})
},
/**提交 */
async submit() {
try {
const {
params,
} = this.data, {
id: relayLotteryId,
} = this.options
console.log(params)
if (!params.name) throw '请输入名称!'
if (!params.num) throw '请选择数字!'
wx.p.wxApi.showLoading()
const {
code,
data,
message
} = await wx.p.api.solitaireApi.commitSolitaire({
relayLotteryId,
name: params.name,
relayContent: params.num,
})
wx.hideLoading()
if (code == 0) {
if (data) {
wx.p.wxApi.showToast('提交成功!')
this.setData({
disabled: true
})
this.getSolitaireAewardList({
relayLotteryId
})
} else throw message
} else this.setData({
show: true
})
} catch (error) {
wx.hideLoading()
if (error) wx.p.wxApi.showToast(error)
}
},
input(e) {
const {
value
} = e.detail, {
name
} = e.target.dataset
this.setData({
[name]: value
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
}
})