$(function() {
// 禁止微信字体修改
(function () {
if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
handleFontSize();
} else {
if (document.addEventListener) {
document.addEventListener("WeixinJSBridgeReady", handleFontSize, false);
} else if (document.attachEvent) {
document.attachEvent("WeixinJSBridgeReady", handleFontSize);
document.attachEvent("onWeixinJSBridgeReady", handleFontSize);
}
}
function handleFontSize() {
// 设置网页字体为默认大小
WeixinJSBridge.invoke('setFontSizeCallback', {
'fontSize': 0
});
// 重写设置网页字体大小的事件
WeixinJSBridge.on('menu:setfont', function () {
WeixinJSBridge.invoke('setFontSizeCallback', {
'fontSize': 0
})
});
}
})();
var dev = false; // 测试数据开关
var $cards = $(".box li"), //所有卡牌
$maskCard = $("#mask-card"), //翻牌遮罩
length = $cards.length,
index = length, //轮流滚动的卡牌下标
data = 9999, //次数
rem = 72,
initArr = [
[80 / rem, 0],
[280 / rem, 0],
[480 / rem, 0],
[80 / rem, 300 / rem],
[280 / rem, 300 / rem],
[480 / rem, 300 / rem]
], //卡牌位置数组
clickTime = 0,
bool = false, //首次点击时不能在卡牌归位期间
timer, //轮流提示定时器
nowTab = 0;
var isFirst = true;
$("#change").html(data);
var timer_a = null;
var list_data = { // Tab 中奖名单nameList,我的奖品recordList
'nameList': '',
'recordList': ''
};
var srandom = Math.random();
var _data = '';
//url参数
var actId = GetQueryString('actId') || '';
var url = GetQueryString('json'),
opub,
opri,
drawtime = null,
drawopen = true,
getdrawdata,
tiptime = null;
var isiOS = false;
// 判断是否在url拿到json参数
if (url) {
url = JSON.parse(url);
if (url['pub']) {
opub = url['pub'];
if (!opub.p) {
opub.p = 0;
// wifilogdp([602,'json_pub_p_null']);
}
// 通过参数确认是否是ios
try {
if (opub.appCode == 'i001') {
isiOS = true;
}
} catch (e) {
console.log(e);
}
} else {
console.log('没有拿到pub参数');
// wifilogdp([602,'json_pub_null']);
}
if (url['pri']) {
opri = url['pri'];
if (!opri.uId) {
opri = {
'uId': 0
};
// wifilogdp([602,'json_pri_uId_null']);
}
} else {
opri = {
'uId': 0
};
console.log('没有拿到pri参数');
// wifilogdp([602,'json_pri_null']);
}
} else {
console.log('没有拿到json参数');
// wifilogdp([602,'json_null']);
}
if (dev) {
_data = {
"data": {
"userAwardList": [{
"awardName": "再来一次",
"type": 6,
"bookId": null
},
{
"awardName": "100成长值",
"type": 4,
"bookId": null
},
{
"awardName": "100成长值",
"type": 4,
"bookId": null
},
{
"awardName": "再来一次",
"type": 6,
"bookId": null
},
{
"awardName": "10元话费",
"type": 2,
"bookId": null
},
{
"awardName": "10元话费",
"type": 2,
"bookId": null
},
{
"awardName": "再来一次",
"type": 6,
"bookId": null
},
{
"awardName": "100成长值",
"type": 4,
"bookId": null
},
{
"awardName": "再来一次",
"type": 6,
"bookId": null
},
{
"awardName": "100成长值",
"type": 4,
"bookId": null
}
],
"drawNum": 175,
"endTime": 287798618,
"awardList": [{
"id": 77,
"name": "68元小说",
"type": 5,
"img": "http://ods51247g.bkt.clouddn.com/pubres/usercenter/watchaward/prize2.png"
},
{
"id": 78,
"name": "58看点",
"type": 1,
"img": "http://ods51247g.bkt.clouddn.com/pubres/usercenter/watchaward/prize5.png"
},
{
"id": 79,
"name": "kindle",
"type": 3,
"img": "http://ods51247g.bkt.clouddn.com/pubres/usercenter/watchaward/prize1.jpg"
},
{
"id": 81,
"name": "100成长值",
"type": 4,
"img": "http://ods51247g.bkt.clouddn.com/pubres/usercenter/watchaward/grow.png"
},
{
"id": 82,
"name": "10元话费",
"type": 2,
"img": "http://ods51247g.bkt.clouddn.com/pubres/usercenter/watchaward/huafei.jpg"
},
{
"id": 83,
"name": "100看点",
"type": 1,
"img": "http://ods51247g.bkt.clouddn.com/pubres/usercenter/watchaward/prize4.png"
}
]
},
"code": 1,
"msg": "获取列表成功"
}
// data结束
// renderData(_data);
init();
var _nameList = [{
'id': '123****8282',
'type': 1,
'name': '《斗魂1大陆》'
}, {
'id': '123****8282',
'type': 1,
'name': '《斗魂2大陆》'
}, {
'id': '123****8282',
'type': 1,
'name': '《斗魂3大陆》'
}, {
'id': '123****8282',
'type': 1,
'name': '《斗魂4大陆》'
}, {
'id': '123****8282',
'type': 1,
'name': '《斗魂5大陆》'
}, {
'id': '123****8282',
'type': 1,
'name': '《斗魂6大陆》'
}, {
'id': '123****8282',
'type': 1,
'name': '《斗魂7大陆》'
}, {
'id': '123****8282',
'type': 1,
'name': '《斗魂8大陆》'
}, {
'id': '123****8282',
'type': 1,
'name': '《斗魂9大陆》'
}, {
'id': '123****8282',
'type': 1,
'name': '《斗魂0大陆》'
}];
var _recordList = [{
'type': 1,
'name': '《斗魂1大陆》',
'url': '#1111##'
}, {
'type': 2,
'name': '12天VIP会员',
'url': '##2222##'
}, {
'type': 3,
'name': '100 代金券',
'url': ''
}, {
'type': 4,
'name': '华为 Nova 7s',
'url': '##333##'
}];
list_data.nameList = _nameList;
list_data.recordList = _recordList;
renderLi();
} else {
// 非测试数据时运行
if (!opub || opub.p < 24) {
// tipbox('您当前版本太低
请升级到最新版本参与该活动');
// wifilogdp([602,'opub_'+ (!opub ? 'null' : 'p_' + opub.p)]);
// return false;
fnGetPrizeList();
} else {
fnGetPrizeList();
}
}
// ios:i001
// 游戏开始
// 获取基本信息
function fnGetPrizeList() {
$.ajax({
url: '/api/card/getAwardList',
type: 'post',
timeout: 5000,
// dataType: 'json',
// contentType: 'application/json',
data: {
actId: actId,
},
success: function(data) {
var odata = data.data;
switch (data.code) {
case 1:
// 存储 Banner图和规则
var storage = window.localStorage;
storage.fanpaiRule = odata.rule;
storage.fanpaiImg = odata.img;
// 渲染图片及消耗看点数量
// $('.bannerImg').attr('src', odata.img);
$('.consume_num').html(odata.playAmount);
var bgColorM = odata.mainColor || '';
if (bgColorM) {
$('html,body,#wrap').css('background-color', bgColorM);
$('.banner .after').css({
'background': '-moz-linear-gradient(top, rgba(255,255,255,0) 0%, ' + bgColorM + ' 100%)',
'background': '-webkit-linear-gradient(top, rgba(255,255,255,0) 0%,' + bgColorM + ' 100%)',
'background': 'linear-gradient(to bottom, rgba(255,255,255,0) 0%,' + bgColorM + ' 100%)'
})
}
renderData(odata); // 渲染奖品展示图和名称
init(); // 初始化动画效果
// 改变数据中奖广播
list_data.nameList = []; // 清空数组
list_data.nameList = odata.win_list;
// 改变数据中奖记录
list_data.recordList = []; // 清空数组
list_data.recordList = odata.record_award;
// 渲染Tab 改变数据/中奖记录
renderLi();
break;
default:
// $('.bannerImg').attr('src', odata.img);
break;
}
},
error: function() {
$('#dialog-no').show();
/*jshint multistr: true */
$('#dialog-no .win_show').html('
' + ndataArr[i].show_name + '
'; $cards.eq(i).html(_img + _prizeName); } } // 初始化动画 function init() { bool = false; var initTime = 2; // CSS动画时间 0.5秒+0.5秒 if (isFirst) { // 第一次翻转图片 isFirst = false; var timer_showCard = setInterval(function() { $cards.addClass('hide-card'); removeImg(); // 0.5秒后删除图片 clearInterval(timer_showCard); }, initTime * 1000); // 删除图片 1/2 .hide-card 的时间 = 0.5s function removeImg() { var timer_removeImg = setInterval(function() { $cards.addClass('hide-data'); $cards.find('img').remove(); $cards.find('p').remove(); clearInterval(timer_removeImg); }, 500); } } else { initTime = 0; } // 卡牌右下角发牌 var timer_moveCard = setInterval(function() { $cards.css({ //所有卡牌放到右下角 left: 512 / rem + "rem", top: 268 / rem + "rem" }); $cards.removeClass('hide-card'); clearInterval(timer_moveCard); // 0.5秒后发牌 var timer_cardInit = setInterval(function() { cardInit(); clearInterval(timer_cardInit); }, 500); // }, (initTime + 1) * 1000); function cardInit() { //卡牌归位动画 for (var i = 0; i < length; i++) { (function(i) { var seat = setTimeout(function() { $cards.eq(i).css({ left: initArr[i][0] + "rem", top: initArr[i][1] + "rem" }); clearTimeout(seat); }, 300 * i); })(i); } // 定时选中卡牌 0为顺序选择 1为随机选择 // cardActive(1); bool = true; //卡牌归位,可以点击 } //生成从minNum到maxNum的随机数 function randomNum(minNum, maxNum) { switch (arguments.length) { case 1: return parseInt(Math.random() * minNum + 1, 10); break; case 2: return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10); break; default: return 0; break; } } //卡牌轮流选中动画 1为随机 0为顺序 function cardActive(isRandomNum) { if (isRandomNum || 1) { setTimeout(function() { timer = setInterval(function() { bool = true; //卡牌归位,可以点击 $cards.removeClass("active"); $cards.eq(randomNum(0, index)).addClass("active"); }, 1000); }, 1000); } else { setTimeout(function() { timer = setInterval(function() { bool = true; //卡牌归位,可以点击 $cards.eq(index - 1).removeClass("active"); index %= 6; $cards.eq(index).addClass("active"); index++; }, 1000); }, 1000); } } } //点击卡牌 $(".box").on("click", "li", function() { if (new Date() - clickTime > 2000 && bool) { //两次点击的间隔不能小于2秒 clickTime = new Date(); //时间更新 if (data > 0) { var speed = 200; //滑动的速度 // $('body,html').animate({ scrollTop: 0 }, speed); // 点击的时候回到顶部 //return false; fnLottery($(this)); } else { alert("没有次数了~"); } } // window.bookSotre.logClick('fanpai_index', 'dianjikapai', '', '', ''); }); // 模拟开奖结果------------------------ function initFnLottery(_liThis) { // $('.dialog_prize_img').attr('src', data.data.img); // $('.wintxt').html(_wintxt); // $('.red-body h1').html(_h1txt); $maskCard.show(); clearInterval(timer); //清除轮流选中动画 $cards.removeClass("active"); //清除轮流滚动类名 _liThis.addClass("open-card"); //添加翻牌动画 //动画监听 _liThis.on("animationend", () => { _liThis.removeClass("open-card"); //移除翻牌动画 $cards.css({ //所有卡牌放到右下角 left: 280 / rem + "rem", top: 168 / rem + "rem" }); $maskCard.hide(); win(_liThis); _liThis.off("animationend"); //解绑动画监听 }); } //中奖信息提示 // $("#close,.win,.btn").click(function () { // clickTime = new Date();//时间更新 // index = length;//卡牌选中重新从第一张开始 // init(); // }); // 渲染Tab 中奖名单和我的奖品 function renderLi(dataType) { console.log(list_data); var _dataType = dataType || ''; var _html = ''; // 中奖广播 if (_dataType == 'tab1' || _dataType == '') { var _item = list_data.nameList; $('.tab_nav li').removeClass('cur'); $('.tab_nav li').eq(0).addClass('cur'); if (_item.length == 0) { $('.tab_list').html(''); // $('.emtpy').show(); // return; ------------------- } else { $('.empty').hide(); $('.name-list').show(); for (var i = 0; i < _item.length; i++) { if (i == 10) { break; } _html += '' + data.data.awardName + '
'; var _h1txt = '恭喜获奖'; $('.dialog_prize').removeClass('thanksImg'); switch (data.data.type) { case 1: _h1txt = '谢谢参与'; _wintxt = '好可惜,差点就中了
别灰心,幸运女神总会降临的
获得一本免费书籍
《' + data.data.name + '》
恭喜您获得了' + data.data.name + '
请在VIP个人中心进行查看
'; break; case 4: _wintxt = '恭喜您获得了' + data.data.kandian + '书币
已放入您的账户余额
'; // 写入一条数据 list_data.recordList.unshift(data.data); list_data.nameList.unshift(data.data); break; case 5: _h1txt = '免费再来一次'; _wintxt = '赶快试试手气吧~
'; // 写入一条数据 list_data.recordList.unshift(data.data); list_data.nameList.unshift(data.data); break; default: _h1txt = '谢谢参与'; _wintxt = '好可惜,差点就中了
别灰心,幸运女神总会降临的
7天VIP
`) init(); window.location.reload(); }); /*$(".win,.btn").click(function () { link = true; });*/ } // 关闭弹出层 $("#close,.win,.btn").click(function() { clickTime = new Date(); //时间更新 index = length; //卡牌选中重新从第一张开始 init(); $mask.hide(); $winning.removeClass("reback"); $card.removeClass("pull"); // 渲染Tab 改变数据/中奖记录 alert(222); renderLi(nowTab); }); // 关闭dialog弹层 $('.tip_box_dialog .dialog_tip_close').click(function() { $('.tip_box_dialog').hide(); }); // 去充值 $('.tip_box_dialog .recharge').click(function() { $('.tip_box_dialog').hide(); window.bookSotre.bookStoreClick('', '6', '', ''); window.bookSotre.logClick('fanpai_index', 'dianjichongzhi', '', '', ''); }); // 跳转链接IOS-7,安卓-4 // 打开rule $('.rule').click(function() { var _json = { 'url': window.location.protocol + '//' + window.location.host + '/huodong/fanpai/activity-rules.html' }; if (isiOS) { window.bookSotre.bookStoreClick('', '7', _json.url, ''); } else { window.bookSotre.bookStoreClick('', '4', '', JSON.stringify(_json)); } }); // 领取实物 需要区分客户端 $('.tab_list').on('click', '.go_getAwardCenterList', function() { // /asg/portal/awardcenter/getAwardCenterList.do var SEARCH = $(this).attr('data-url'); if (isiOS) { var _url = window.location.protocol + '//' + window.location.host + '/asg/portal/awardcenter/getAwardCenterList.do' + SEARCH window.bookSotre.bookStoreClick('', '7', _url, ''); } else { var _json = ''; if (opub && opub.p >= 32) { _json = { 'url': window.location.protocol + '//' + window.location.host + '/php/user/awardcenter' + SEARCH }; } else { _json = { 'url': window.location.protocol + '//' + window.location.host + '/asg/portal/awardcenter/getAwardCenterList.do' + SEARCH }; } window.bookSotre.bookStoreClick('', '4', '', JSON.stringify(_json)); } }); function go_book(){ // // 领取实物 需要区分客户端 // $('.go_bookId').onclick() { // alert(111); // var bookId = $(this).attr('data-bookId'); // window.location.href="/index/book/chapter?sid="+bookId; // }); $('.go_bookId').click(function () { alert(111); }); } // go_vip 我的VIP页面 $('.tab_list').on('click', '.go_vip', function() { var iosUrl = '/phpios/vip/viphome'; var _json = { 'url': window.location.protocol + '//' + window.location.host + iosUrl }; if (isiOS) { window.bookSotre.bookStoreClick('', '7', _json.url, ''); } else { if (opub.p > 24) { window.bookSotre.bookStoreClick('', '32', '', ''); } else { openVip(); } } }); }); // window.bookSotre.logPv('fanpai_index', '', '');