$(function () { var $cards = $(".box li"),//所有卡牌 $maskCard = $("#mask-card"),//翻牌遮罩 length = $cards.length, index = length,//轮流滚动的卡牌下标 data = { count: 5 },//次数 rem = 75, initArr = [[34 / rem, 0], [273 / rem, 0], [512 / rem, 0], [34 / rem, 268 / rem], [273 / rem, 268 / rem], [512 / rem, 268 / rem]],//卡牌位置数组 clickTime = 0, bool = false,//首次点击时不能在卡牌归位期间 dataList = [], couponId = null, errorMessge = '', playAble = true, timer,//轮流提示定时器 playCreditLimit = '',//是否展示 积分说明框 falglimitType = '', consumeTotal = '',//消耗积分 explain = $("#explain"),//积分说明框 numFalg = false,//有次数=false wcancel = $('#w-cancel'),//弹出消耗积分取消按钮 radomData = []; let baseUrl = 'https://ctest.malls.iformall.com/C'; if (window.location.origin == 'https://gametest.malls.iformall.com') { baseUrl = 'https://ctest.malls.iformall.com/C' } else if (window.location.origin == 'https://game.malls.iformall.com') { baseUrl = 'https://c.malls.iformall.com/C' } else if (window.location.origin == 'https://game.youlane.cn') { baseUrl = 'https://ciformall.youlane.cn/C' } init(); // alert('token是'+getQueryString('token')+"-------------"+'gameId是'+getQueryString('gameId')+"-------------"+'id是'+getQueryString('id')) function init() { $.ajax({ url: baseUrl + "/api/game/getOneGame",//json文件位置 type: "GET",//请求方式为get dataType: "json", //返回数据格式为json headers: { 'content-type': 'application/json', // "token":"025e5017-a268-4c21-98b3-d47b77b3ca54", "token": getQueryString('token') }, data: { id: getQueryString('id'), // id:"212380694809149440" }, success: function (res) {//请求成功完成后要执行的方法 // console.log(res) var strHtml = ""; dataList = res.data.couponIdsList; playCreditLimit = res.data.playCreditLimit falglimitType = res.data.limitType if (playCreditLimit >= '0') { explain.show() } id = res.data.id let totalWeight = 0; dataList.forEach((item, index) => { strHtml += '
  • '; strHtml += ''; strHtml += '
  • '; totalWeight += Number(item.gameWeight) for (var i = 0; i < item.gameWeight; i++) { radomData.push(item) } }) let notWinweight = 100 - totalWeight; let b = { id: null } for (var i = 0; i < notWinweight; i++) { radomData.push(b) } $('.swiper-wrapper').html(strHtml); //奖品展示 var show = new Swiper(".swiper-container", { direction: "horizontal",//水平方向滑动。 vertical为垂直方向滑动 loop: false,//是否循环 slidesPerView: 'auto' //自动根据slides的宽度来设定数量 }); getCount() } }) //卡牌归位动画 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); } //卡牌轮流选中动画 setTimeout(function () { timer = setInterval(function () { bool = true;//卡牌归位,可以点击 $cards.eq(index - 1).removeClass("active"); index %= 6; $cards.eq(index).addClass("active"); index++; }, 1000); }, 1000); } /** * 获取剩余中奖次数 */ function getCount() { $.ajax({ url: baseUrl + "/api/game/getCount",//json文件位置 type: "GET",//请求方式为get dataType: "json", //返回数据格式为json headers: { 'content-type': 'application/json', // "token":"b49fa2c4-a074-4147-afbe-6913c66705d6", "token": getQueryString('token') }, data: { gameId: getQueryString('id'), // id:"213206254531641344" }, success: function (res) {//请求成功完成后要执行的方法 if (res.code == 200) { if (res.data.playAble) { playAble = true; data.count = res.data.playLimit - res.data.playCount; $('#change').html(data.count); consumeTotal = res.data.playCredit; if (data.count <= '0') { $(integration).html(`${consumeTotal}积分/每次`); } else { $(integration).html(`当前游戏免费次数耗尽后${consumeTotal}积分/次`); } if (falglimitType == '0') { if (data.count == -1) { $('#change-box').hide(); } else { $('#change-box').html('您总共还有' + data.count + '免费刮奖机会') } } else if (falglimitType == '1') { if (data.count == -1) { $('#change-box').hide() } else { $('#change-box').html('您今天还有' + data.count + '免费刮奖机会') } } if (res.data.playLimit < '0' && playCreditLimit >= '0') { return// 不设置能免费次数且设置每次消耗积分 } if (res.data.playLimit < '0') { data.count = 1000000; $('#change-box').hide(); } else { $('#change-box').show(); } } else { playAble = false; if (res.data.playLimit <= '0') { errorMessge = '您的中奖次数已经达到上限!无法继续参加游戏!' data.count = 1000000; $('#change-box').hide(); return; } else { if (res.data.AwardLimit == res.data.AwardCount && res.data.AwardLimit != 0) { errorMessge = '您的中奖次数已经达到上限!无法继续参加游戏!' data.count = res.data.playLimit - res.data.playCount; $('#change').html(data.count); $('#change-box').html('您的中奖次数已经达到上限!无法继续参加游戏!'); $('#change-box').show(); return; } else if (res.data.playLimit == res.data.playCount) { errorMessge = '您的剩余次数为0!无法继续参加游戏!' data.count = 0; $('#change').html(0); $('#change-box').html('您的剩余次数为0!无法继续参加游戏!'); $('#change-box').show(); return; } } } } else { errorMessge = res.message; playAble = false; $('#change').html(0); $('#change-box').hide(); } } }) } /** * 记录游戏次数 */ function reduceCount(paramData) { $.ajax({ url: baseUrl + "/api/game/addActionLog",//json文件位置 type: "POST",//请求方式为get dataType: "json", //返回数据格式为json async: true, headers: { 'content-type': 'application/json;charset=UTF-8', // "token":"025e5017-a268-4c21-98b3-d47b77b3ca54" "token": getQueryString('token') }, data: JSON.stringify(paramData), success: function (res) {//请求成功完成后要执行的方法 // alert('成功了!') getCount() } }) } $('.fenxiang').click(function () { wx.ready(function () { wx.onMenuShareAppMessage({ title: "title", // 分享标题 desc: "desc", // 分享描述 link: '/pages/index/index', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: '', // 分享图标 type: '', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }); }) }) wcancel.click(function () { $("#warnning-box").hide() $("#warnning-box-bg").hide() numFalg = false; }) $("#w-button").click(function () { $("#warnning-box").hide() $("#warnning-box-bg").hide() numFalg = true; }) //点击卡牌翻转 $(".box").on("click", "li", function () { let _this = this; if (new Date() - clickTime > 2000 && bool) {//两次点击的间隔不能小于2秒 if (playAble) { if (data.count > 0) { let params = { gameId: getQueryString('id') } $maskCard.show(); clearInterval(timer);//清除轮流选中动画 $cards.removeClass("active");//清除轮流滚动类名 $(_this).addClass("open-card");//添加翻牌动画 //动画监听 $(_this).on("animationend", function () { $(_this).removeClass("open-card");//移除翻牌动画 $cards.css({//所有卡牌放到右下角 left: 512 / rem + "rem", top: 268 / rem + "rem" }); $maskCard.hide(); win(); $(_this).off("animationend");//解绑动画监听 }); if (true) { //查询中奖结果 $.ajax({ url: baseUrl + "/api/game/freeGameGo",//json文件位置 type: "POST",//请求方式为get dataType: "json", //返回数据格式为json async: true, headers: { 'content-type': 'application/json;charset=UTF-8', // "token":"025e5017-a268-4c21-98b3-d47b77b3ca54" "token": getQueryString('token') }, data: JSON.stringify(params), success: function (res) {//请求成功完成后要执行的方法 if (res.code == 200) { //保存中奖信息 getCount() if (res.data) { var toemdata = res.data if (res.data.prizeType == 1) { $('#card .win').html('积分增加+' + toemdata.credit); $('#card .win').css({ 'font-size': ' 20px', 'text-align': 'center', 'color': '#FF6600', 'line-height': '50px', "background": 'url(../common/image/prize/prize2.png) no-repeat', 'background-size': '6rem' }) $('.winning .red-body p').html('') $(".btn").html('再玩一把') } else { $('#card .win').html('') $('#card .win').css({ "background": 'url(' + toemdata.coverImg + ') no-repeat', "background-size": "cover" }); $('.winning .red-body p').html(toemdata.title + "(点击“我的”查看奖券)"); $(".btn").html('再玩一把') } } else { $('#card .win').html('') $('#card .win').css({ "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat', "background-size": "cover" }); $('.winning .red-body p').html('未中奖!(点击“我的”查看奖券)'); $(".btn").html('再玩一把') } } else { $('#card .win').html('') $('#card .win').css({ "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat', "background-size": "cover" }); $('.winning .red-body p').html('未中奖!(点击“我的”查看奖券)'); $(".btn").html('再玩一把') } } }) } else { reduceCount(paramContData); $('#card .win').css({ "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat', "background-size": "cover" }); $('.winning .red-body p').html('未中奖!(点击“我的”查看奖券)'); $(".btn").html('再玩一把') } } else { if (playCreditLimit >= '0') { if (!numFalg) {//消耗积分提示框只会弹出一次 $('#warnning-box-bg').show(); $('#warnning-box').show(); if (data.count == -1) { $('#w-title').html("将消耗" + consumeTotal + '积分'); } else { $('#w-title').html("免费次数已耗尽,将消耗" + consumeTotal + '积分'); } } else { $maskCard.show(); clearInterval(timer);//清除轮流选中动画 $cards.removeClass("active");//清除轮流滚动类名 $(_this).addClass("open-card");//添加翻牌动画 //动画监听 $(_this).on("animationend", function () { $(_this).removeClass("open-card");//移除翻牌动画 $cards.css({//所有卡牌放到右下角 left: 512 / rem + "rem", top: 268 / rem + "rem" }); $maskCard.hide(); win(); $(_this).off("animationend");//解绑动画监听 }); let params = { gameId: getQueryString('id') } $.ajax({ url: baseUrl + "/api/game/freeCridetGameGo",//json文件位置 type: "POST",//请求方式为get dataType: "json", //返回数据格式为json async: true, headers: { 'content-type': 'application/json;charset=UTF-8', // "token":"025e5017-a268-4c21-98b3-d47b77b3ca54" "token": getQueryString('token') }, data: JSON.stringify(params), success: function (res) {//请求成功完成后要执行的方法 if (res.code == 200) { if (res.data) { var toemdata = res.data if (res.data.prizeType == 1) { $('#card .win').html('积分增加+' + toemdata.credit); $('#card .win').css({ 'font-size': ' 20px', 'text-align': 'center', 'color': '#FF6600', 'line-height': '50px', "background": 'url(../common/image/prize/prize2.png) no-repeat', 'background-size': '6rem' }) $('.winning .red-body p').html('') $(".btn").html('再玩一把') } else { $('#card .win').html('') $('#card .win').css({ "background": 'url(' + toemdata.coverImg + ') no-repeat', "background-size": "cover" }); $('.winning .red-body p').html(toemdata.title + "(点击“我的”查看奖券)"); $(".btn").html('再玩一把') } } else { $('#card .win').html('') $('#card .win').css({ "background": 'url(../common/image/redPack/weizhongjiang.png) no-repeat', "background-size": "cover" }); $('.winning .red-body p').html('未中奖!(点击“我的”查看奖券)'); $(".btn").html('再玩一把') } } else if (res.code == 13101) { $('#card .win').html('') $('#card .win').css({ "background": 'url(../common/image/prize/prize2.png) no-repeat', "background-size": "cover" }); $('.winning .red-body p').css({ "line-height": "1.5rem", "font-size": "0.64rem" }) $('.winning .red-body p').html('积分不足!'); $(".btn").hide() } } }) } } else { $('#warnning-box-bg').show(); $('#warnning-box').show(); $('#w-title').html("当前可用次数已耗尽"); return } } } else { $('#warnning-box-bg').show(); $('#warnning-box').show(); $('#w-title').html(errorMessge); } } }); //点击跳回小程序奖券列表 $('#myWin').click(function () { wx.miniProgram.redirectTo({ url: '/pages/couponorder/index/index' + "?token=" + getQueryString('token') + "&gameId=" + getQueryString('gameId') + "&id=" + getQueryString('id') + '&from=h5' }) }) //中奖信息提示 $(".btn").click(function () { clickTime = new Date();//时间更新 index = length;//卡牌选中重新从第一张开始 init(); }); //关闭中奖提示页面 $("#close").click(function () { clickTime = new Date();//时间更新 index = length;//卡牌选中重新从第一张开始 init(); }); //返回首页 $("#gotoindex").click(function () { wx.miniProgram.redirectTo({ url: '/pages/index/index' }) }); });