stopIndex 表示停止的位置;
initMap 表示后台中奖的信息和前台页面对应关系;
转盘的转动方向为 左上角--->右上角---> 右下角---> 左下角;对应的坐标为 1 -2 -3-4-5-6-7-8-9-10-11-12
其中右下角的坐标为 7 (免单);
在停止后可以调用
coupon.showAlert();
/*
* 删除左右两端的空格
*/
function Trim(str) {
return str.replace(/(^s*)|(s*$)/g, "");
}
/*
* 定义数组
*/
function GetSide(m, n) {
// 初始化数组
var arr = [];
for (var i = 0; i < m; i++) {
arr.push([]);
for (var j = 0; j < n; j++) {
arr[i][j] = i * n + j;
}
}
// 获取数组最外圈
var resultArr = [];
var tempX = 0,
tempY = 0,
direction = "Along",
count = 0;
while (tempX >= 0 && tempX < n && tempY >= 0 && tempY < m && count < m * n) {
count++;
resultArr.push([tempY, tempX]);
if (direction == "Along") {
if (tempX == n - 1) tempY++;
else tempX++;
if (tempX == n - 1 && tempY == m - 1) direction = "Inverse"
} else {
if (tempX == 0) tempY--;
else tempX--;
if (tempX == 0 && tempY == 0) break;
}
}
return resultArr;
}
var index = 0,
// 当前亮区位置
prevIndex = 0,
// 前一位置
Speed = 300,
// 初始速度
Time, // 定义对象
arr = GetSide(4, 4),
// 初始化数组
EndIndex = 0,
// 决定在哪一格变慢
tb = document.getElementById("tb"),
// 获取tb对象
cycle = 0,
// 转动圈数
EndCycle = 0,
// 计算圈数
flag = false,
// 结束转动标志
quick = 0; // 加速
var stopIndex = '3';
btn = document.getElementById("btn1")
function StartGame() {
clearInterval(Time);
cycle = 0;
flag = false;
EndIndex = Math.floor(Math.random() * 12);
// EndCycle=Math.floor(Math.random()*4);
EndCycle = 1;
Time = setInterval(Star, Speed);
}
function stop(data){
return data+'';
}
function Star() {
// 跑马灯变速
if (flag == false) {
// 走五格开始加速
if (quick == 4) {
clearInterval(Time);
Speed = 50;
Time = setInterval(Star, Speed);
}
// 跑N圈减速
if (cycle == EndCycle + 1 && index == parseInt(EndIndex)) {
clearInterval(Time);
Speed = 300;
flag = true; // 触发结束
Time = setInterval(Star, Speed);
}
}
if (index >= arr.length) {
index = 0;
cycle++;
if(cycle >=3){
flag = true;
}
}
// 结束转动并选中号码
// trim里改成数字就可以减速,变成Endindex的话就没有减速效果了
if (flag == true && index == parseInt(Trim(stopIndex+'')) - 1) {
quick = 0;
clearInterval(Time);
coupon.showAlert();
}
tb.rows[arr[index][0]].cells[arr[index][1]].className = "playcurr";
if (index > 0) prevIndex = index - 1;
else {
prevIndex = arr.length - 1;
}
tb.rows[arr[prevIndex][0]].cells[arr[prevIndex][1]].className = "playnormal";
index++;
quick++;
}
/***
* 映射奖品关系
* */
function initMap(rewardId){
var result = "";
if(rewardId){
//5元话费
if(rewardId=="22516eb6d4ff41e7ac81169d9dacceca"){
return "2";
//500M流量
}else if(rewardId=="9d50be6cf17646d78bcc7292ce15a0fb"){
return "1";
//50元电子卷
}else if(rewardId=="e6d113bdd9bb4782ad6855b1201b9955"){
return "3";
//免单
}else if(rewardId=="793e464bfbf948fb9e93d51cfd15e670"){
return "4";
//1000个积分
}else if(rewardId=="22c7707d5c2542ea832a877fc61047e1"){
return "5";
}else if(rewardId=="-1"){
return "1";
}
}else{
return result;
}
}
系统还引用了coupon对象;js文件如下:
开始方法:coupon 中的playGame()方法;这里可以发送ajax请求;同时调用的是StartGame();方法【转盘开始转动】
在发送请求的时候;就需要查询中奖结果;然后设置stopIndex值;最多转动3全将会停止,如果转盘一直转动,那表示
stopIndex的值没有在转盘上有对应关系;
停止: coupon.showAlert(); showAlert方法,该返回中奖信息;根据转盘的对应关系;显示奖品信息即可;中奖短信;
在这个时候进行下发;
var coupon = (function($,data){
var _default = {
basePath:'',
optName:'',
channel:'weixin',
phone:'',
openid:'',
playTime:''
};
/**
* 领取方法调用
* */
var getCoupon = function(data){
$(".couponGet").on("click",function(){
var curClick = $(this);
var couponType = curClick.attr("data-value");
//20元可以直接领取
if(couponType=="VOUCHER_20151111_20"){
$.ajax({
type:'post',
url:_default.basePath+'activity/doub11Shop_saveCoupon',
data:{
"activityCode": couponType
},
dataType: "text",
success:function(data){
if(data == "LOGIN"){
window.location.href = "http://wap.nx.10086.cn/wap_emall/activity/doub11Shop_wapDoub11Index";
}else if(data == "1"){
$('#modal2').find(".am-modal-bd").html("恭喜您已成功领取20元购机券,赶快看看双11的好货吧!填写订单时购机券将会自动显示。");
$('#modal2').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
}else if(data == "0"){
$('#modal2').find(".am-modal-bd").html("不要贪心啦!购机券每人限领一次,赶快去看看双11的好货吧!填写订单时购机券将会自动显示。");
$('#modal2').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
}else if(data == "2"){
$('#modal2').find(".am-modal-bd").html("活动已结束!");
$('#modal2').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
}else{
$('#modal2').find(".am-modal-bd").html("领卷失败,请刷新后重试!");
$('#modal2').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
}
}
});
}else{
alert("分享后可以使用!");
}
});
};
/**
* 所有按钮的统一监听流程
* */
var buttonProcess = function(data){
$(".buttonProcess").on("click",function(){
var curClick = $(this);
var buttonType = curClick.attr("data-type");
var optName = curClick.attr("data-optName");
console.log(_default.phone);
console.log(_default.openid);
//设置提醒的内容--手机号和手机类型
if(buttonType == "remind"){
var phoneType = curClick.attr("data-phone");
console.log(optName);
//设置提醒
$.ajax({
type:'post',
url:_default.basePath+'activity/doub11Shop_addSMSAlert',
data:{
phone:_default.phone,
'phoneType':phoneType,
'optName':optName
} ,
dataType: "text",
success:function(data){
if(data=="OK"){
$('.modal_txt').text("亲,设置成功啦,我们将在手机抢购活动开始前发短信提醒您,请注意查收!");
$('.modal_txt').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
}else if(data=="ON"){
$('.modal_txt').text("提醒失败");
$('.modal_txt').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
}
}
});
//设置领卷的操作
}else if(buttonType=="couponGet"){
var couponType = curClick.attr("data-value");
console.log(couponType);
console.log(_default.basePath);
//20元可以直接领取
if(couponType=="VOUCHER_20151111_20"){
$.ajax({
type:'post',
url:_default.basePath+'activity/doub11Shop_saveCoupon',
data:{
"activityCode": couponType
},
dataType: "text",
success:function(data){
if(data == "LOGIN"){
window.location.href = "http://wap.nx.10086.cn/wap_emall/activity/doub11Shop_wapDoub11Index";
}else if(data == "1"){
$('.modal_txt').text("恭喜您已成功领取20元购机券,赶快看看双11的好货吧!填写订单时购机券将会自动显示。");
$('.modal_txt').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
}else if(data == "0"){
$('.modal_txt').text("不要贪心啦!购机券每人限领一次,赶快去看看双11的好货吧!填写订单时购机券将会自动显示。");
$('.modal_txt').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
}else if(data == "2"){
$('.modal_txt').text("活动已结束!");
$('.modal_txt').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
}else{
$('.modal_txt').text("领卷失败,请刷新后重试!");
$('.modal_txt').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
}
}
});
}else{
$.ajax({
type:'post',
url:_default.basePath+'activity/doub11Shop_checkVoucher',
data: {
"activityCode": couponType,
"phone":_default.phone,
},
dataType: "text",
success:function(data){
if(data == "LOGIN"){
window.location.href = "http://wap.nx.10086.cn/wap_emall/activity/doub11Shop_wapDoub11Index";
}else if(data == "OK"){
$('.modal_txt').text("不要贪心啦!购机券每人限领一次,赶快去看看双11的好货吧!填写订单时购机券将会自动显示。");
$('.modal_txt').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
$("#isUsed").val("ok");
}else{
$('.modal_bg').show();
$('.modal_share').show();
}
}
});
}
}
});
}
/**
* 统计pv uv等相关操作
* */
var totalClick=function(data){
$(".recordData").on("click",function(){
var curClick = $(this);
var optName = curClick.attr("data-optName");
console.log(optName);
$.ajax({
type:'post',
url:_default.basePath+"activity/doub11Shop_saveRecord",
data:{
optName:optName
} ,
dataType: "text",
success:function(){
}
});
});
}
/**
* 设置提醒
* */
var remind = function(data){
$(".remind").on("click",function(){
var curClick = $(this);
$.ajax({
type:'post',
url:_default.basePath+'activity/doub11Shop_addSMSAlert',
data:{
phone:_default.phone
} ,
dataType: "text",
success:function(data){
if(data=="OK"){
$('.modal_txt').text("亲,设置成功啦,我们将在手机抢购活动开始前发短信提醒您,请注意查收!");
$('.modal_txt').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
}else if(data=="ON"){
$('.modal_txt').text("提醒失败");
$('.modal_txt').show();
setTimeout(function(){
$('.modal_txt').hide();
},2500);
}
}
});
});
}
var playGame=function(data){
$(".playGame").on("click",function(){
console.log(_default.phone);
//页面减少抽奖次数
var payTimeStr = $(".payTime").eq(0).text();
var payTime = parseInt(payTimeStr) - 1;
if(parseInt(payTimeStr) <= 0){
alert("您没有抽奖机会哦~");
return ;
}
$(".payTime").text("");
$(".payTime").text(payTime);
$.ajax({
type:'post',
url:_default.basePath+"activity/doub11Shop_getDialResult",
data:{
phone:_default.phone
},
dataType: "text",
success:function(data){
var playResult = $.parseJSON(data);
console.log(playResult);
stopIndex =playResult.reward;
console.log(stopIndex);
//中奖了
if(playResult.reward!='0'){
$("#cj_tcN").css("background","url("+_default.basePath+"resources/activities/doub11Shop/images/cj_tc01.png"+")");
}else{
$("#cj_tcN").css("background","url("+_default.basePath+"resources/activities/doub11Shop/images/cj_tc02.png"+")");
}
var centent = playResult.rewardName;
if(centent.indexOf("免单")>-1){
content = '亲!恭喜您获得'+centent+',稍后我们将有专人与您联系领奖事项。';
}else{
content = '亲!恭喜您获得'+centent+',奖品将在订单成功签收后的10个工作日内返还。';
}
$(".playContent").text(playResult.rewardName);
console.log(playResult.rewardName);
StartGame(stopIndex);
}
});
});
//再玩一次内容
$(".playAgain").on("click",function(){
hideAlert();
});
}
//显示重讲
function showAlert(){
setTimeout(function(){
initPlayTime();
drawSMSAlert();
$("#lean_overlay").show();
$("#cj_tcN").show();
},1000);
}
function hideAlert(){
$("#cj_tcN").hide();
$("#lean_overlay").hide();
}
function drawSMSAlert(){
$.ajax({
type:'post',
url:_default.basePath +"activity/doub11Shop_drawSMSAlert",
data:{
phone:_default.phone
} ,
dataType: "text",
success:function(data){
console.log(data);
}
});
}
function initPlayTime(){
//查询用户查询抽奖次数
$.ajax({
type:'post',
url:_default.basePath +"activity/doub11Shop_queryUserPlayTime",
data:{
phone:_default.phone
} ,
dataType: "text",
success:function(data){
console.log("中奖内容"+data);
var result = $.parseJSON(data);
_default.playTime = result.totalCount;
$(".payTime").text(result.totalCount);
//中奖了
if(data!="1"){//background-size: 300px;
$("#cj_tcN").css({"background":"url("+_default.basePath+"activities/doub11Shop/images/cj_tc01.png"+")","width":"300px;","height":"216px","background-size":"300px"});
}else{
$("#cj_tcN").css({"background":"url("+_default.basePath+"activities/doub11Shop/images/cj_tc02.png"+")","width":"300px;","height":"216px","background-size":"300px"});
}
}
});
}
/**
* 初始化参数
* */
function initDafaultValue(data){
_default.basePath = data.basePath;
_default.phone = data.phone;
_default.openid = data.openid;
console.log(data);
$(".da_btnclose").on("click",function(){
hideAlert();
});
initPlayTime();
}
/**
* 绑定相关对象
* */
return {
getCoupon:getCoupon,
initDafaultValue:initDafaultValue,
totalClick:totalClick,
remind:remind,
buttonProcess:buttonProcess,
playGame:playGame,
showAlert:showAlert,
hideAlert:hideAlert
}
}) (jQuery);