zhuanpan.js
3.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
let timer;
let cjIn = false;
let cjChange = 0; //抽奖过程KEY
Page({
/**
* 页面的初始数据
*/
data: {
prizeList:[
{id:'001',index:1,imgsrc:'https://www.baidu.com/img/bd_logo1.png',prizeName:'奖品名称111'},
{id:'002',index:2,imgsrc:'https://www.baidu.com/img/bd_logo1.png',prizeName:'奖品名称222'},
{id:'003',index:3,imgsrc:'https://www.baidu.com/img/bd_logo1.png',prizeName:'奖品名称333'},
{id:'004',index:4,imgsrc:'https://www.baidu.com/img/bd_logo1.png',prizeName:'奖品名称444'},
{id:'005',index:5,imgsrc:'https://www.baidu.com/img/bd_logo1.png',prizeName:'奖品名称555'},
{id:'006',index:6,imgsrc:'https://www.baidu.com/img/bd_logo1.png',prizeName:'奖品名称666'},
{id:'007',index:7,imgsrc:'https://www.baidu.com/img/bd_logo1.png',prizeName:'奖品名称777'},
{id:'008',index:8,imgsrc:'https://www.baidu.com/img/bd_logo1.png',prizeName:'奖品名称88888888888888'},
],
cjChange:null, //抽奖过程KEY
prizeResult:null, //抽奖结果KEY
prizeName:null, //抽奖结果KEY对应的奖品名称
showAgain:false , //是否抽奖后显示再抽一次按钮
},
//抽奖操作
cj(){
if(cjIn){
return;
}else{
cjIn = true;
}
let This = this;
clearInterval(timer);
timer = setInterval(This.changePrize,80);
// test start
let res = {
stutus:1,
prizeResult:8,
prizeName:'奖品名称88888888888888',
}
if(res.stutus == 1){
setTimeout(function(){
clearInterval(timer);
timer = setInterval(This.changePrize,160);
setTimeout(function(){
clearInterval(timer);
timer = setInterval(This.changePrize,300);
setTimeout(function(){
This.setData({
prizeResult:res.prizeResult,
prizeName:res.prizeName,
});
},1000)
},1000)
},2000)
}
// test end
},
//抽奖过程奖品切换
changePrize(){
cjChange ++;
cjChange = cjChange > 8 ? 1 : cjChange;
let This = this;
This.setData({
cjChange:cjChange
});
if(This.data.prizeResult == cjChange){
clearInterval(timer);
This.setData({
showAgain:true
});
console.log('获得奖品:' + This.data.prizeName)
}
},
//点击再抽一次按钮
againBtn(){
cjIn = false;
cjChange = 0; //抽奖过程KEY
let This = this;
This.setData({
cjChange:null, //抽奖过程KEY
prizeResult:null, //抽奖结果KEY
prizeName:null, //抽奖结果KEY对应的奖品名称
showAgain:false , //是否抽奖后显示再抽一次按钮
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})