//大转盘抽奖
var
i,
msg,
Log,
rep;
var
dial_start ={
index:-
1,
//当前转动到哪个位置,起点位置
count:
0,
//总共有多少个位置
timer:
0,
//setTimeout的ID
speed:
20,
//初始转动速度
times:
0,
//转动次数
cycle:
50,
//转动基本次数:至少需要转动多少次再进入抽奖环节
prize:-
1,
//中奖位置
init:
function(
Class){
//初始化
if(
$(
"."+
Class).
find(
".start_li").
length>
0){
$dial_start =
$(
"."+
Class);
$units =
$dial_start.
find(
".start_li");
this.
obj =
$dial_start;
this.
count =
$units.
length;
$dial_start.
find(
".start_li_"+
this.
index).
find(
".start_mask").
addClass(
"active");
};
},
roll:
function(){
//转动
var
index =
this.
index;
var
count =
this.
count;
var
dial_start =
this.
obj;
$(
dial_start).
find(
".start_li_"+
index).
find(
".start_mask").
removeClass(
"active");
index +=
1;
if(
index >
count-
1){
index =
0;
};
$(
dial_start).
find(
".start_li_"+
index).
find(
".start_mask").
addClass(
"active");
this.
index =
index;
return
false;
},
stop:
function(
index){
this.
prize =
index;
return
false;
}
};
function
roll(){
dial_start.
times +=
1;
dial_start.
roll();
//转动过程调用的是dial_start的roll方法,这里是第一次调用初始化
if (
dial_start.
times >
dial_start.
cycle+
10 &&
dial_start.
prize==
dial_start.
index) {
clearTimeout(
dial_start.
timer);
dial_start.
prize=-
1;
dial_start.
times=
0;
click=
false;
clicks =
false;
popTipShow.
alert(
'',
msg, [
'确定'],
function(
e){
var
button =
$(
e.
target).
attr(
'class');
if(
button ==
'ok'){
this.
hide();
}
});
$.
ajax({
type:
"GET",
url:Url+
"wap/Award/awardLog",
async:
true,
data:{
},
dataType:
"json",
success:
function(
result){
if(
result.
code ==
200){
Log =
result.
data;
$(
".winners_con").
remove();
$(
Log).
each(
function(
index,
data){
$(
".winners").
append(
"<div class='winners_con'><span>"+
data[
'datetime']+
"</span><span>"+
data[
'awardname']+
"</span></div>");
});
console.
log(
result.
data);
}
else{
console.
log(
result.
message);
}
}
});
}
else{
if (
dial_start.
times<
dial_start.
cycle) {
dial_start.
speed -=
10;
}
else
if(
dial_start.
times==
dial_start.
cycle) {
dial_start.
prize =
i-
1;
}
else{
if (
dial_start.
times >
dial_start.
cycle+
10 && ((
dial_start.
prize==
0 &&
dial_start.
index==
7) ||
dial_start.
prize==
dial_start.
index+
1)) {
dial_start.
speed +=
110;
}
else{
dial_start.
speed +=
20;
}
}
if (
dial_start.
speed<
40) {
dial_start.
speed=
40;
};
dial_start.
timer =
setTimeout(
roll,
dial_start.
speed);
//循环调用
}
return
false;
};
var
click=
false;
var
clicks =
false;
window.
onload=
function(){
$(
"#start_open").
click(
function(){
if(
click ==
false){
$.
ajax({
type:
"GET",
url:Url+
"wap/Award/award",
async:
true,
data:{
},
dataType:
"json",
success:
function(
result){
if(
result.
code ==
200){
rep =
result[
'data'][
'repository'];
popTipShow.
alert(
'',
"已消耗"+
rep+
"个葡萄", [
'确定'],
function(
e){
var
button =
$(
e.
target).
attr(
'class');
if(
button ==
'ok'){
this.
hide();
}
});
ware();
i =
result[
'data'][
'rid'];
dial_start.
init(
'dial_start');
msg =
result.
message;
}
else
if(
result.
code ==
0){
popTipShow.
alert(
'',
result.
message, [
'确定'],
function(
e){
var
button =
$(
e.
target).
attr(
'class');
if(
button ==
'ok'){
this.
hide();
}
});
}
else
if(
result.
code == -
1){
//能否抽奖
popTipShow.
alert(
'',
result.
message, [
'确定'],
function(
e){
var
button =
$(
e.
target).
attr(
'class');
if(
button ==
'ok'){
this.
hide();
}
});
click =
true;
}
}
});
};
if (
click) {
//click控制一次抽奖过程中不能重复点击抽奖按钮,后面的点击不响应
return
false;
}
else{
dial_start.
speed=
100;
roll();
//转圈过程不响应click事件,会将click置为false
click=
true;
//一次抽奖完成后,设置click为true,可继续抽奖
clicks =
true;
return
false;
};
});
};