LuckDraw.js
13.3 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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
import {
request
} from "../../../request/index.js";
var WxParse = require('../../../wxParse/wxParse.js');
const a = getApp()
// pages/LuckDraw/LuckDraw.js
Page({
/**
* 页面的初始数据
*/
data: {
// 活动id
id: 0,
// 活动个人信息
userMsg: '',
// 顾问id
advisers_id: 0,
// 抽奖总数据
indexData: '',
play: true,
// 活动详情富文本
content: '',
// 奖品列表
awardList: [],
DrawList: ['关于同放', '活动规则', '获奖记录'],
imagesUrl: a.globalData.baseUrl,
newurl:'www.xiaoxiangauto.com',
// 新增
titleName: '',
showBindPhone: false,
title: false,
mode: 'rect',
indicatorPos: 'bottomCenter',
effect3d: false,
// 轮播图-结束
user_id: 0, //顾问id
chou: {}, //抽奖结果
chouGui: {}, //抽奖活动规则
chouLog: [], //获奖名单
indexData: {},
show: false, //展示页面
boxCheck: false,
showShareAlert: false,
showDrawAlert: false, //抽奖次数用完提示弹框
//抽奖次数用完弹框
drawOutInfo: {
imgUrl: '../../static/image/tongzhi_icon.png',
alertTxt: '您的抽奖机会已经用完',
otherTxt: '下一次活动再试试',
share_num: 0,
btnMt: 22,
btnTxt: '好的'
},
getRequireInfo: {
imgUrl: '../../static/image/zhuyi_icon.png',
alertTxt: '请填写完整信息'
},
showActRule: false, //展示活动规则弹框
getSuccessInfo: {
imgUrl: '../../static/image/chenggong_icon.png',
alertTxt: '提交成功'
},
showGetSuccess: false, //展示领取成功提示弹框
showRequireAlert: false, //展示必填项提示弹框
showPickInfo: false, //展示填写领取信息弹框
showGetDraw: false, //抽奖获得红包弹框
//红包弹框
redPackAlert: {
bgImgUrl: '../../static/image/hongbaotanchuang_img.png',
bgPdTop: '92rpx',
bgImgWidth: '602rpx',
bgImgHeight: '825rpx',
infoWidth: '428rpx',
infoHeight: '444rpx',
infoPdTop: '300rpx',
content: [
'恭喜您,抽中10元红包',
'可在获奖记录查看'
],
time: '',
address: '',
btnList: [
/* {
btnName:'去提现',
btnWidth:'48%',
type:'navTo',
url:''
},*/
{
btnName: '去分享',
btnWidth: '100%',
type: 'share',
url: ''
}
]
},
showCouponDraw: false, //展示抵用券中奖
//抵扣券弹框
couponAlert: {
bgImgUrl: '../../static/image/diyongquan_img.png',
bgPdTop: '132rpx',
bgImgWidth: '602rpx',
bgImgHeight: '785rpx',
infoWidth: '424rpx',
infoHeight: '396rpx',
infoPdTop: '308rpx',
content: ['恭喜您,抽中1000元抵用券'],
time: '',
address: '',
btnList: [{
btnName: '去分享',
btnWidth: '100%',
type: 'share',
url: ''
/* btnName:'去领奖',
btnWidth:'100%',
type:'coupon',
url:'' */
}]
},
showSnackAlert: false, //展示零食大礼包
//零食大礼包弹框
snackAlert: {
bgImgUrl: '../../static/image/libao_img.png',
bgPdTop: '132rpx',
bgImgWidth: '602rpx',
bgImgHeight: '865rpx',
infoWidth: '424rpx',
infoHeight: '474rpx',
infoPdTop: '310rpx',
content: ['恭喜您,抽中零食大礼包'],
time: '领取时间:2020/05/05-2021/05/20',
address: '领取地址:天津市南开区长江道4s店',
btnList: [{
btnName: '去分享',
btnWidth: '100%',
type: 'share',
url: ''
/* btnName:'知道了',
btnWidth:'100%',
type:'close',
url:'' */
}]
},
showIntegralAlert: false, //展示积分
//积分弹框
integralAlert: {
bgImgUrl: '../../static/image/jifen_img_bg.png',
bgPdTop: '116rpx',
bgImgWidth: '602rpx',
bgImgHeight: '801rpx',
infoWidth: '424rpx',
infoHeight: '410rpx',
infoPdTop: '310rpx',
content: ['恭喜您,抽中10积分'],
time: '',
address: '',
btnList: [{
btnName: '去分享',
btnWidth: '100%',
type: 'share',
url: ''
/* btnName:'',
btnWidth:'100%',
type:'program',
url:'' */
}]
},
actPeopleList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
showActPeople: false, //展示活动弹框
avatar_arr: [],
colorAwardDefault: "url('../../static/image/bg_img_4.png')",
colorAwardSelect: "url('../../static/image/bg_img_5.png')",
indexSelect: 0, //被选中的奖品索引
isRunning: false, //是否正在抽奖
lun_arr: [], //奖品图片数组
guInfo: {},
// 选中的品牌和id
brand: '',
brandId: 0,
brand2: '',
brandId2: 0,
// 最新的抽奖次数
newchouNum: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (e) {
wx.setStorageSync('drawId', e.id)
if (e.userMsg) {
this.setData({
userMsg: JSON.parse(e.userMsg)
})
}
if (e.id != undefined) {
this.setData({
id: e.id
})
this.getDrawList()
this.getAdvisers()
this.getnewchouNum()
this.addLiu()
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.setData({
brand: wx.getStorageSync('brand'),
brandId: wx.getStorageSync('brandId'),
brand2: wx.getStorageSync('brand2'),
brandId2: wx.getStorageSync('brandId2')
})
},
// 获取抽奖页数据
async getDrawList() {
let that = this
const {
data: {
data
}
} = await request({
url: 'api/h5/chouData',
data: {
id: that.data.id,
}
})
let countdownPer = parseFloat((data.all_time - data.sheng_time) / data.all_time).toFixed(2)
that.setData({
indexData: data,
// 奖品列表
lun_arr: data.lun_arr,
content: data.detail,
countdownPer: countdownPer
})
WxParse.wxParse('content', 'html', that.data.content, that, 25);
if (that.data.lun_arr.length > 0) {
//奖品item设置
var awardList = [];
//间距,怎么顺眼怎么设置吧.
var topAward = 45;
var leftAward = 11;
for (var j = 0; j < 12; j++) {
if (j == 0) {
topAward = topAward;
leftAward = leftAward;
} else if (j < 4) {
topAward = topAward;
leftAward = leftAward + 132 + 12;
} else if (j < 7) {
leftAward = leftAward;
topAward = topAward + 132 + 8;
} else if (j < 10) {
leftAward = leftAward - 132 - 12;
topAward = topAward;
} else if (j < 13) {
leftAward = leftAward - 2;
topAward = topAward - 132 - 10;
}
var lun = that.data.lun_arr[j];
if (lun) {
awardList.push({
topAward: topAward,
leftAward: leftAward,
lun: lun
});
}
}
that.setData({
awardList: awardList
})
}
// 获取抽奖活动规则
request({
url: 'api/h5/chouGui',
data: {
id: that.data.id,
}
}).then(res => {
that.setData({
chouGui: res.data
})
})
// 获取抽奖活动数据
request({
url: 'api/h5/chouLog',
data: {
id: that.data.id,
}
}).then(res => {
that.setData({
chouLog: res.data.data.slice(0, 30)
})
})
},
//开始游戏
startGame: function () {
console.log(this.data.isRunning, this.data.sheng_time <= 0, this.data.indexData.sheng_time == -2, this.data.awardList.length != 12)
console.log(this.data.sheng_time,this.data.indexData.sheng_time,this.data.awardList)
if (this.data.isRunning || this.data.sheng_time <= 0 || this.data.indexData.sheng_time == -2 || this.data.awardList.length != 12) return;
console.log('通过初始化')
console.log(this.data.isRunning, this.data.sheng_time <= 0, this.data.indexData.sheng_time == -2, this.data.awardList.length != 12)
if (this.data.newchouNum == 0) {
wx.showToast({
title: '非常抱歉,您本次活动抽奖机会已经用完啦',
icon: 'none'
})
this.setData({
showDrawAlert: true
})
return
}
this.setData({
isRunning: true
})
//获取奖品
request({
url: 'api/h5/chou',
data: {
id: this.data.id,
}
}).then(res => {
this.setData({
chou: res.data.data
})
})
var _this = this;
var indexSelect = 0;
var i = 300;
var rooNum = 0;
function show() {
rooNum++
indexSelect++
indexSelect = indexSelect % 12;
_this.setData({
indexSelect: indexSelect
})
// console.log(_this.data.indexSelect,'已选中')
if (rooNum == 20) {
i = 600
}
//这里我只是简单粗暴用y=30*x+200函数做的处理.可根据自己的需求改变转盘速度
if (rooNum > 20 && _this.data.lun_arr[indexSelect].id == _this.data.chou.id) {
// var contentTxt = ''
// var btn = {
// btnName: '去分享',
// btnWidth: '100%',
// type: 'share',
// url: ''
// }
// 分享获得抽奖次数?
// if (_this.data.chou.share_num > 0) {
// contentTxt = '分享至朋友圈可获得' + _this.chou.share_num + '次抽奖机会'
// } else {
// btn = {
// btnName: '去领奖',
// btnWidth: '100%',
// type: 'coupon',
// url: '/pages/myPrize/myPrize?id=1'
// }
// }
//获取最新的抽奖次数
// if (_this.data.chou.type_id == 1) {
// _this.data.indexData.chou_num--
// } else {
// request('/api/h5/chouNum', {
// id: _this.id
// }).then((res) => {
// _this.data.indexData.chou_num = res.data.num
// })
// }
//抵用券
if (_this.data.chou.type_id == 2) {
_this.setData({
showCouponDraw: true
})
// let cc0 = _this.data.couponAlert.content[0]
// let cc1 = _this.data.couponAlert.content[1]
// let cbtn = _this.data.couponAlert.btnList[0]
// _this.setData({
// showCouponDraw : true,
// cc0:'恭喜您,抽中' + _this.data.chou.name,
// cc1:contentTxt,
// cbtn:btn
// })
// console.log(_this.data.couponAlert,'抵用券获奖信息')
}
//红包
if (_this.data.chou.type_id == 1) {
_this.setData({
showCouponDraw: true
})
}
//零食大礼包
if (_this.data.chou.type_id == 4) {
_this.setData({
showCouponDraw: true
})
}
//积分
if (_this.data.chou.type_id == 3) {
_this.setData({
showCouponDraw: true
})
}
_this.setData({
isRunning: false
})
} else {
// console.log(show,i,'定时器')
setTimeout(show, i);
}
}
show();
this.getnewchouNum()
},
// 获取顾问数据
async getAdvisers() {
let that = this
const {
data: {
data
}
} = await request({
url: 'api/h5/guInfo',
data: {
user_id: that.data.advisers_id,
}
})
// console.log(data);
// 数据为空时不显示顾问区
that.setData({
})
},
// 浏览量+1
async addLiu() {
let that = this
await request({
url: 'api/h5/addLiu',
data: {
id: that.data.id
}
})
},
// 获取最新的抽奖次数
async getnewchouNum() {
let that = this
const {
data: {
data
}
} = await request({
url: 'api/h5/chouNum',
data: {
id: that.data.id,
}
})
console.log(data, '最新抽奖次数');
that.setData({
newchouNum: data.num
})
},
// 返回顶部
returnTop() {
wx.pageScrollTo({
scrollTop: 0
});
},
// 弹出框--参与活动头像
showActpeo() {
this.setData({
showActPeople: true
})
},
// // 弹出框--关闭参与活动头像
closeActpeo() {
this.setData({
showActPeople: false
})
},
// 弹出--规则 介绍
clickActRule(e) {
let type = e.currentTarget.dataset.idx
if (type == 0) {
this.setData({
titleName: '关于同放',
showActRule: true
})
} else if (type == 1) {
this.setData({
titleName: '活动规则',
showActRule: true
})
} else if (type == 2) {
wx.navigateTo({
url: '/pages/myPrize/myPrize?drawid=' + this.data.id + '&userMsg=' + JSON.stringify(this.data.userMsg),
})
}
},
// 弹出--关闭规则介绍
clickCloseRule() {
this.setData({
showActRule: false
})
},
// 弹出--获取获奖人信息
bindPrize() {
this.setData({
showPickInfo: true
})
},
// 关闭获奖弹窗
f_d_a: function (e) {
console.log(e)
this.setData({
showCouponDraw: e.detail
})
},
// 关闭获取信息弹窗
p_z: function (e) {
this.setData({
showPickInfo: e.detail
})
},
})