51,412
社区成员
发帖
与我相关
我的任务
分享
<script>
$.popCtrl();
var prize = {
init: function (_opt) {
var _this = this;
var _default = {
circleCount: 2,
index: 0,
interval: 60,
count: 12,
callback: null
};
_this._opt = $.extend(_default, _opt);
_this.maxCount = _this._opt.circleCount * _this._opt.count + _this._opt.index + 1;
//console.log(_this.maxCount);
_this.curIndex = -1;
_this.prizeDom = $("#prizeBox").find(".item");
_this.timeInterval();
},
timeInterval: function (func) {
var _this = this;
_this.timeCtrl = window.setTimeout(function () {
_this.curIndex += 1;
if (_this.curIndex < _this.maxCount) {
_this.run(_this.index());
if (_this.curIndex > _this.maxCount - _this._opt.count) {
_this._opt.interval += 30;
}
_this.timeInterval();
}
else {
window.clearTimeout(_this.timeCtrl);
if (_this._opt.callback) {
_this._opt.callback();
}
}
}, _this._opt.interval);
},
index: function () {
var _this = this;
return _this.curIndex % _this._opt.count;
},
run: function (index) {
var _this = this;
_this.prizeDom.eq(index).addClass("cur");
_this.prizeDom.not(_this.prizeDom.eq(index)).removeClass("cur");
}
}
$("#beginPrize").bind("click", function () {
if ($("#beginPrize").hasClass("disabled")) {
return;
}
var count = $('#count').text();
if (count == 0) {
$('#tip').html("亲,您的抽奖次数用完了");
$('#cmd09').addClass('show');
return;
}
$("#beginPrize").addClass("disabled");
prize.init({
index:99999,
})
$.ajax({
type:"post",
url:"../luckywheel2/lottery.do",
cache:false,
success: function (data){
try{
data = eval('(' + data + ')');
}catch(e){
}
if(data != undefined){
//抽奖成功
if(data.ret==0){
if (data.data.awardInfoId==7) {
prize.init({
index: data.data.number,//奖品索引值0~15,从左上角开始顺时针旋转,
callback: function () {
$('#cmd01').addClass('show');
$('#count').html(data.data.count);
$("#beginPrize").removeClass("disabled");
}
});
}else{
prize.init({
index: data.data.number,//奖品索引值0~15,从左上角开始顺时针旋转,
callback: function () {
$('#prizeName').html(data.data.awardInfoName);
$('#infoid').val(data.data.id);
$('#count').html(data.data.count);
$('#cmd02').addClass('show');
$("#beginPrize").removeClass("disabled");
}
});
}
}else if(data.ret== "003"){
prize.init({
index: 11,//奖品索引值0~15,从左上角开始顺时针旋转,
callback: function () {
$('#tip').html("亲,您的抽奖次数用完了");
$('#cmd09').addClass('show');
$("#beginPrize").removeClass("disabled");
}
})
}else{
prize.init({
index: 11,//奖品索引值0~15,从左上角开始顺时针旋转,
callback: function () {
$('#tip').html(data.data);
$('#cmd09').addClass('show');
$("#beginPrize").removeClass("disabled");
}
})
}
}else{
prize.init({
index: 11,//奖品索引值0~15,从左上角开始顺时针旋转,
callback: function () {
$('#tip').html("网络异常,请稍后尝试");
$('#cmd09').addClass('show');
$("#beginPrize").removeClass("disabled");
}
})
}
},
error:function(){
prize.init({
index: 11,//奖品索引值0~15,从左上角开始顺时针旋转,
callback: function () {
$('#tip').html("网络异常,请稍后尝试");
$('#cmd09').addClass('show');
$("#beginPrize").removeClass("disabled");
}
})
}
})
});

