940 lines
28 KiB
JavaScript
940 lines
28 KiB
JavaScript
// 指定全局变量
|
|
/*global checkVersion locateJudge EnvCheck tools erbanMask wx wxConfig VConsole androidJsObj initNav template preloadImage */
|
|
var info = {};
|
|
var browser = checkVersion();
|
|
var api = locateJudge();
|
|
var env = EnvCheck();
|
|
|
|
var shareUrl = location.origin + '/activity';
|
|
var share = {
|
|
title: '',
|
|
link: shareUrl,
|
|
imgUrl: 'https://img.erbanyy.com/new-logo.png',
|
|
desc: ''
|
|
};
|
|
// eslint-disable-next-line
|
|
function getMessage (key, value) {
|
|
info[key] = value;
|
|
}
|
|
|
|
wx.ready(function () {
|
|
wx.onMenuShareTimeline({
|
|
title: share.title,
|
|
link: share.link,
|
|
imgUrl: share.imgUrl,
|
|
desc: share.desc
|
|
});
|
|
|
|
wx.onMenuShareAppMessage({
|
|
title: share.title,
|
|
desc: share.desc,
|
|
link: share.link,
|
|
imgUrl: share.imgUrl,
|
|
type: 'link',
|
|
dataUrl: ''
|
|
});
|
|
|
|
wx.onMenuShareQQ({
|
|
title: share.title,
|
|
desc: share.desc,
|
|
link: share.link,
|
|
imgUrl: share.imgUrl
|
|
});
|
|
});
|
|
|
|
erbanMask('activity-name', 'activity-name');
|
|
initNav({
|
|
type: 2,
|
|
data: {
|
|
msg: 'wewawa',
|
|
link: share.link,
|
|
title: share.title,
|
|
showUrl: share.link,
|
|
imgUrl: share.imgUrl,
|
|
desc: share.desc
|
|
}
|
|
});
|
|
|
|
browser.weixin && wxConfig();
|
|
|
|
var requestScrollTimer
|
|
var toastTimer
|
|
var openSocketTimer
|
|
var imgTimer
|
|
var canvasTimer
|
|
var rotateTimer
|
|
var rotateTimer2
|
|
var giftTimer
|
|
|
|
clearInterval(requestScrollTimer)
|
|
requestScrollTimer = setInterval(function () {
|
|
getScrollTip()
|
|
}, 60000)
|
|
|
|
var clickTab = 0
|
|
var clickTabFlag = false
|
|
var clickNumIndex = 0
|
|
var turntable = {
|
|
0: {
|
|
rotateBol: false,
|
|
fontColor: [], // 字体颜色
|
|
colors: [
|
|
'#001D53',
|
|
'#1C2D6E'
|
|
], // 板块颜色
|
|
prizeName: [], // 奖品名称
|
|
prizeImg: [
|
|
'img/gift/gift1.png',
|
|
'img/gift/gift2.png',
|
|
'img/gift/gift3.png',
|
|
'img/gift/gift4.png',
|
|
'img/gift/gift5.png',
|
|
'img/gift/gift6.png',
|
|
'img/gift/gift7.png',
|
|
'img/gift/gift8.png'
|
|
], // 奖品图片
|
|
prizeImgArr: [], // 用于canvas绘画的图片
|
|
prizeIndex: [] // 奖品下标
|
|
},
|
|
1: {
|
|
rotateBol: false,
|
|
fontColor: [], // 字体颜色
|
|
colors: [
|
|
'#001D53',
|
|
'#1C2D6E'
|
|
], // 板块颜色
|
|
prizeName: [], // 奖品名称
|
|
prizeImg: [
|
|
'img/gift/gift1.png',
|
|
'img/gift/gift9.png',
|
|
'img/gift/gift10.png',
|
|
'img/gift/gift11.png',
|
|
'img/gift/gift12.png',
|
|
'img/gift/gift13.png',
|
|
'img/gift/gift14.png',
|
|
'img/gift/gift15.png'
|
|
], // 奖品图片
|
|
prizeImgArr: [], // 用于canvas绘画的图片
|
|
prizeIndex: [] // 奖品下标
|
|
}
|
|
}
|
|
var giftIntro = {}
|
|
|
|
$(function () {
|
|
if (env == 'test') {
|
|
new VConsole();
|
|
}
|
|
var main = {
|
|
init: function () {
|
|
this.getMsgFromDevice();
|
|
setTimeout(() => {
|
|
this.getData();
|
|
if (info.appVersion >= '1.3.6' && info.appVersion) {
|
|
$('.topNav1').show().siblings('.topNav2').hide();
|
|
} else {
|
|
$('.feedback,.topNav1').hide();
|
|
$('.topNav2').show();
|
|
}
|
|
}, 100);
|
|
this.eventRegister();
|
|
},
|
|
getMsgFromDevice: function () {
|
|
if (browser.app) {
|
|
if (browser.ios) {
|
|
window.webkit.messageHandlers.getDeviceId.postMessage(null);
|
|
window.webkit.messageHandlers.getRoomUid.postMessage(null);
|
|
} else if (browser.android) {
|
|
if (androidJsObj && typeof androidJsObj === 'object') {
|
|
info.deviceId = window.androidJsObj.getDeviceId();
|
|
info.roomUid = window.androidJsObj.getRoomUid()
|
|
}
|
|
}
|
|
|
|
info.uid = tools.nativeUtils.getUid();
|
|
info.ticket = tools.nativeUtils.getTicket();
|
|
info.appVersion = tools.nativeUtils.getAppVersion();
|
|
} else {
|
|
info.uid = 906709;
|
|
info.roomUid = 906709
|
|
info.deviceId = '8d9d6247-63a4-3acc-a164-01a6b1a3c098';
|
|
info.ticket = 'eyJhbGciOiJIUzI1NiJ9.eyJ0aWNrZXRfdHlwZSI6bnVsbCwidWlkIjo5MDYyMzgsInRpY2tldF9pZCI6IjdiZWQ2NzcwLWJmMjktNGRiYi04MzZmLTc0NzBmY2RiMDZjYSIsImV4cCI6MzYwMCwiY2xpZW50X2lkIjoiZXJiYW4tY2xpZW50In0.ye2Zv8nyZkqiT_bIWq-50qcS6_SCWmRpBjxxLX7mQvs';
|
|
}
|
|
},
|
|
|
|
eventRegister: function () {
|
|
$('.topNav .tab').on('click', function () {
|
|
if (clickTabFlag) {
|
|
return
|
|
}
|
|
$(this).addClass('active').siblings().removeClass('active')
|
|
clickTab = $(this).index()
|
|
|
|
if (clickTab === 0) {
|
|
$('.exp-container').find('.strip').removeClass('exp-2').addClass('exp-1')
|
|
$('.exp-container').removeClass('exp-container2').addClass('exp-container1')
|
|
$('.canvas').find('.container1').removeClass('second').addClass('first')
|
|
$('.canvas .pointer img').attr('src', 'img/carnival/point.png')
|
|
$('.canvas .btn img').attr('src', 'img/carnival/draw-btn.png')
|
|
preloadImg(clickTab)
|
|
} else {
|
|
$('.exp-container').find('.strip').removeClass('exp-1').addClass('exp-2')
|
|
$('.exp-container').removeClass('exp-container1').addClass('exp-container2')
|
|
$('.canvas').find('.container1').removeClass('first').addClass('second')
|
|
$('.canvas .pointer img').attr('src', 'img/carnival/point-2.png')
|
|
$('.canvas .btn img').attr('src', 'img/carnival/draw-btn-2.png')
|
|
preloadImg(clickTab)
|
|
}
|
|
|
|
info.clickStatu = false
|
|
getGiftInfo()
|
|
getticketChooseShow()
|
|
})
|
|
$('.turnNum').on('click', 'li', function () {
|
|
$(this).addClass('active').siblings().removeClass('active')
|
|
clickNumIndex = $(this).index()
|
|
})
|
|
|
|
$('.experience').on('click', '.tips', function () {
|
|
$('.exp-toast').fadeIn(300, function () {
|
|
clearTimeout(toastTimer)
|
|
toastTimer = setTimeout(function () {
|
|
$('.exp-toast').hide()
|
|
}, 8000)
|
|
})
|
|
})
|
|
|
|
$('.canvas').on('click', '.btn', function () {
|
|
if (!info.clickStatu) {
|
|
$('.toast').html('哎呀太挤了,请稍等').fadeIn(30).fadeOut(2000)
|
|
return false
|
|
}
|
|
if (turntable[clickTab].rotateBol) return
|
|
turntable[clickTab].rotateBol = true
|
|
clickTabFlag = true
|
|
var obj = {
|
|
0: 'one',
|
|
1: 'ten',
|
|
2: 'hundred'
|
|
}
|
|
$.ajax({
|
|
headers: {
|
|
pub_ticket: info.ticket
|
|
},
|
|
type: 'POST',
|
|
url: api + '/activities/draw/turnTable',
|
|
data: {
|
|
uid: info.uid,
|
|
ticket: info.ticket,
|
|
roomUid: info.roomUid,
|
|
sendMessage: true,
|
|
ruleType: obj[clickNumIndex],
|
|
drawType: (clickTab === 0) ? 'turntable1' : 'turntable2',
|
|
deviceId: info.deviceId
|
|
},
|
|
success: function (res) {
|
|
if (res.code === 200) {
|
|
var maxValue = 0
|
|
var prizeId
|
|
var item
|
|
for (var i in res.data.prizeItemList) {
|
|
if (res.data.prizeItemList[i].platformValue > maxValue) {
|
|
maxValue = res.data.prizeItemList[i].platformValue
|
|
prizeId = res.data.prizeItemList[i].prizeId
|
|
item = turntable[clickTab].prizeIndex.indexOf(prizeId)
|
|
if (item == -1) {
|
|
item = 0
|
|
}
|
|
}
|
|
console.log(item);
|
|
}
|
|
// ---------------- 用户抽奖记录接口 -----------
|
|
$.ajax({
|
|
headers: {
|
|
pub_ticket: info.ticket
|
|
},
|
|
type: 'POST',
|
|
url: api + '/activities/draw/saveLog',
|
|
data: {
|
|
ticket: info.ticket,
|
|
uid: info.uid,
|
|
prizeids: JSON.stringify(res.data.prizeIdList),
|
|
prizeIndex: item,
|
|
createdTime: res.data.prizeItemList[0].createTime,
|
|
prizeIdList: JSON.stringify(turntable[clickTab].prizeIndex)
|
|
},
|
|
success: function (res) {
|
|
// eslint-disable-next-line no-empty
|
|
if (res.code !== 200) console.log(res.message)
|
|
},
|
|
error: function (err) {
|
|
console.log('报错了:', err)
|
|
}
|
|
})
|
|
// ------------------ 用户抽奖记录接口 ------------
|
|
$('.info').find('.ticketNum').html(res.data.remainKeyNum)
|
|
rotateFunc(item, 8, res.data.prizeItemList, res.data.prizeIdList, clickTab)
|
|
clearTimeout(rotateTimer)
|
|
rotateTimer = setTimeout(function () {
|
|
clickTabFlag = false
|
|
clearTimeout(rotateTimer)
|
|
}, 3000)
|
|
clearTimeout(rotateTimer2)
|
|
rotateTimer2 = setTimeout(function () {
|
|
turntable[clickTab].rotateBol = false
|
|
}, 1000)
|
|
} else if (res.code === 10000) {
|
|
// 门票不足
|
|
$('.status-mask').find('.title').html('游玩失败')
|
|
$('.status-mask').find('.tips').html('亲,门票不足了哦~')
|
|
$('.status-mask').find('.btn').addClass('toGather').html('去收集')
|
|
$('.shade,.status-mask').show()
|
|
clickTabFlag = false
|
|
turntable[clickTab].rotateBol = false
|
|
} else if (res.code === 21111) {
|
|
// 游玩限制
|
|
$('.status-mask').find('.title').html('本日游玩限制')
|
|
$('.status-mask').find('.tips').html('今日游玩次数已达上限哦~')
|
|
$('.status-mask').find('.btn').removeClass('toGather').html('知道了')
|
|
$('.shade,.status-mask').show()
|
|
clickTabFlag = false
|
|
} else {
|
|
turntable[clickTab].rotateBol = false
|
|
clickTabFlag = false
|
|
$('.toast').html(res.message).fadeIn(30).fadeOut(3000)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
$('.status-mask').on('click', '.btn', function () {
|
|
if ($(this).hasClass('toGather')) {
|
|
$('.status-mask').hide()
|
|
$('.shade').hide()
|
|
window.location.href = './index.html'
|
|
} else {
|
|
$('.status-mask').hide()
|
|
$('.shade').hide()
|
|
}
|
|
})
|
|
|
|
$('.shade').on('click', function () {
|
|
$('.status-mask').hide()
|
|
$('.gather-mask').hide()
|
|
$('.shade').hide()
|
|
})
|
|
|
|
$('.help').on('click', function () {
|
|
$('.rule-mask').animate({
|
|
top: 0
|
|
}, 500)
|
|
})
|
|
$('.rule-mask').on('click', '.back', function () {
|
|
$('.rule-mask').animate({
|
|
top: -1000
|
|
}, 500)
|
|
})
|
|
|
|
$('.rank-btn').on('click', function () {
|
|
renderRank(false)
|
|
})
|
|
$('.rank-mask .tab').on('click', 'li', function () {
|
|
rankTabIndex = $(this).index()
|
|
$(this).addClass('active').siblings().removeClass('active')
|
|
renderRank(true)
|
|
})
|
|
$('.rank-mask').on('click', '.back', function () {
|
|
$('.rank-mask').animate({
|
|
top: -1000
|
|
}, 500)
|
|
})
|
|
|
|
$('.status-mask').on('click', '.btn', function () {
|
|
$('.shade').hide()
|
|
$('.status-mask').hide()
|
|
})
|
|
|
|
$('.record-btn').on('click', function () {
|
|
renderRecord(false)
|
|
})
|
|
$('.record-mask .tab').on('click', 'li', function () {
|
|
recordTabIndex = $(this).index()
|
|
recordPageNum = 1
|
|
scrollFlag = false
|
|
$('.record-mask').find('.content').scrollTop(0)
|
|
$(this).addClass('active').siblings().removeClass('active')
|
|
renderRecord(true)
|
|
})
|
|
$('.record-mask').on('click', '.back', function () {
|
|
$('.record-mask').animate({
|
|
top: -1000
|
|
}, 500)
|
|
})
|
|
$('.record-mask .content').scroll(function () {
|
|
var scrollH = $(this).scrollTop()
|
|
var contentH = $('.record-container').height()
|
|
var viewH = $(this).height()
|
|
if (Math.ceil(viewH + scrollH) >= contentH) {
|
|
if (scrollFlag) {
|
|
return
|
|
}
|
|
scrollFlag = !scrollFlag
|
|
recordPageNum++
|
|
renderRecord(true)
|
|
}
|
|
})
|
|
$('.feedback').on('click', function () {
|
|
tools.nativeUtils.jumpAppointPage('FEEDPACK_PAGE', 'DRAW');
|
|
})
|
|
},
|
|
getData: function () {
|
|
getScrollTip()
|
|
getticketChooseShow()
|
|
openSocket()
|
|
getExp()
|
|
getTicketNum()
|
|
preloadImg(clickTab)
|
|
getGiftInfo()
|
|
}
|
|
};
|
|
|
|
main.init();
|
|
});
|
|
|
|
var scrollTimer
|
|
var tabTimer
|
|
var times
|
|
// var timeFlag = 0
|
|
var timeTimer
|
|
// var cacheLine = 0
|
|
var rankTabIndex = 0
|
|
var recordTabIndex = 0
|
|
var recordPageNum = 1
|
|
|
|
// 获取滚屏数据
|
|
function getScrollTip () {
|
|
$('.container').hide()
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: api + '/activities/draw/queryPrizeMsg',
|
|
success: function (res) {
|
|
if (res.code === 200) {
|
|
for (var i in res.data) {
|
|
if (res.data[i].nick.length > 4) {
|
|
res.data[i].nick = res.data[i].nick.substring(0, 4) + '...'
|
|
}
|
|
if (res.data[i].drawType === 1) {
|
|
res.data[i]['table'] = '墨城烟柳'
|
|
} else {
|
|
res.data[i]['table'] = '清风煮酒'
|
|
}
|
|
}
|
|
res.data.push(res.data[0])
|
|
var _data = {
|
|
scrollMaskList: res.data
|
|
}
|
|
$('.container').html(template('scrollTmp', _data))
|
|
$('.container').show()
|
|
animateScroll()
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
// 获取礼物信息
|
|
function getGiftInfo () {
|
|
turntable[clickTab].prizeIndex = []
|
|
// turntable[0].prizeImg = [];
|
|
// turntable[1].prizeImg = [];
|
|
giftIntro['giftIdArr'] = []
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: api + '/activities/draw/queryPrizeInfo',
|
|
timeout: 15000, // 超时时间:30秒
|
|
data: {
|
|
drawType: (clickTab === 0) ? 'turntable1' : 'turntable2'
|
|
},
|
|
success: function (res) {
|
|
if (res.code === 200) {
|
|
for (var i in res.data) {
|
|
turntable[clickTab].prizeIndex.push(res.data[i].prizeId)
|
|
giftIntro.giftIdArr.push(res.data[i].prizeId)
|
|
// if(clickTab === 0) {
|
|
// turntable[0].prizeImg.push(res.data[i].prizeImgUrl)
|
|
// }else{
|
|
// turntable[1].prizeImg.push(res.data[i].prizeImgUrl)
|
|
// }
|
|
}
|
|
// preloadImg(clickTab)
|
|
// 成功后可点击
|
|
info.clickStatu = true
|
|
} else {
|
|
$('.toast').html(res.message).fadeIn(30).fadeOut(2000)
|
|
}
|
|
},
|
|
error: function (res) {
|
|
$('.toast').html('哎呀太挤了,请稍等').fadeIn(30).fadeOut(2000)
|
|
}
|
|
})
|
|
}
|
|
|
|
// 滚屏
|
|
function animateScroll () {
|
|
var length = $('.scrollMask').find('.container').height()
|
|
var _top = 0
|
|
clearInterval(scrollTimer)
|
|
scrollTimer = setInterval(function () {
|
|
if (length + _top > 30) {
|
|
_top -= 30
|
|
} else {
|
|
$('.scrollMask').find('.container').css({
|
|
top: 0
|
|
})
|
|
_top = 0
|
|
}
|
|
$('.scrollMask').find('.container').stop(true, true).animate({
|
|
top: _top
|
|
})
|
|
}, 2000)
|
|
}
|
|
|
|
// 获取消耗数据
|
|
function getticketChooseShow () {
|
|
var drawObj = {
|
|
0: 'turntable1',
|
|
1: 'turntable2'
|
|
}
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: api + '/activities/draw/queryTicketRule',
|
|
data: {
|
|
drawType: drawObj[clickTab]
|
|
},
|
|
success: function (res) {
|
|
if (res.code === 200) {
|
|
// $('.turnNum').find('.num').eq(0).html(res.data.one + '次')
|
|
$('.turnNum').find('.ticket').eq(0).html('消耗' + res.data.one + '门票')
|
|
// $('.turnNum').find('.num').eq(1).html(res.data.ten + '次')
|
|
$('.turnNum').find('.ticket').eq(1).html('消耗' + res.data.ten + '门票')
|
|
// $('.turnNum').find('.num').eq(2).html(res.data.hundred + '次')
|
|
$('.turnNum').find('.ticket').eq(2).html('消耗' + res.data.hundred + '门票')
|
|
|
|
if (clickTab === 0) {
|
|
$('.turnNum').find('li').removeClass('joy').addClass('ball')
|
|
} else {
|
|
$('.turnNum').find('li').removeClass('ball').addClass('joy')
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
// 打开socket链接
|
|
function openSocket () {
|
|
var socket = null
|
|
var cacheType = 0
|
|
if (typeof (WebSocket) === 'undefined') {
|
|
alert('暂不支持转盘socket')
|
|
} else {
|
|
var _url = (window.location.href.match('apibeta') || window.location.href.match('local')) ? 'http://apibeta.qxjiaoyou.com:8081' : 'https://api.qxjiaoyou.com:8081'
|
|
if (window.location.href.match('preview')) {
|
|
_url = 'https://preview.qxjiaoyou.com:8081'
|
|
}
|
|
var socketUrl = _url + '/websocket/activity/' + info.roomUid
|
|
socketUrl = socketUrl.replace('https', 'wss').replace('http', 'ws')
|
|
if (socket !== null) {
|
|
socket.close()
|
|
socket = null
|
|
}
|
|
socket = new WebSocket(socketUrl)
|
|
|
|
socket.onopen = function () {
|
|
// 监听开启socket后的判断逻辑
|
|
clearInterval(tabTimer)
|
|
tabTimer = setInterval(function () {
|
|
if (cacheType !== clickTab) {
|
|
cacheType = clickTab
|
|
getExp()
|
|
}
|
|
}, 10)
|
|
}
|
|
|
|
socket.onmessage = function (res) {
|
|
// 监听服务端发送过来的数据
|
|
|
|
var data = JSON.parse(res.data)
|
|
if (data.data) {
|
|
renderExp(data.data)
|
|
}
|
|
}
|
|
|
|
socket.onclose = function () {
|
|
socket = null
|
|
clearTimeout(openSocketTimer)
|
|
openSocketTimer = setTimeout(function () {
|
|
openSocket()
|
|
}, 5000)
|
|
}
|
|
|
|
socket.onerror = function () {
|
|
console.log('socket错误')
|
|
}
|
|
}
|
|
}
|
|
|
|
// 渲染经验值
|
|
function getExp () {
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: api + '/activities/draw/getRunawayData',
|
|
data: {
|
|
drawType: (clickTab === 0) ? 'turntable1' : 'turntable2',
|
|
roomUid: info.roomUid
|
|
},
|
|
success: function (res) {
|
|
if (res.code === 200) {
|
|
renderExp(res.data)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
var tableFlag
|
|
function renderExp (val) {
|
|
// console.log(val)
|
|
tableFlag = (val.drawType === 'turntable1') ? 0 : 1
|
|
if (val.runawaySwitch) {
|
|
$('.experience').show()
|
|
}
|
|
|
|
// 进度条计算
|
|
if (tableFlag === clickTab) {
|
|
var height = $('.exp-container').height()
|
|
var percentage = val.curValue / val.runawayConfigValue
|
|
var _top
|
|
_top = height * percentage
|
|
$('.strip').stop(true).animate({
|
|
height: _top
|
|
}, 200)
|
|
$('.experience').find('.maxNum').html(val.runawayConfigValue)
|
|
$('.experience').find('.num').html(val.curValue)
|
|
}
|
|
// 进度条计算
|
|
|
|
// 礼物显示
|
|
if (JSON.stringify(val.poolPrize) !== '{}') {
|
|
if (val.poolTime > 0 && tableFlag === clickTab) {
|
|
renderTime(val)
|
|
}
|
|
// if (val.poolTime === val.runawayConfigTime && tableFlag === clickTab) {
|
|
// timeFlag = 1
|
|
// $('.giftBox').removeClass('hide')
|
|
// renderTime(val.poolTime)
|
|
// $('.giftBox').find('img').attr('src', val.poolPrize.prizeImgUrl)
|
|
// }
|
|
} else {
|
|
$('.giftBox').addClass('hide')
|
|
}
|
|
}
|
|
|
|
// 渲染倒计时
|
|
function renderTime (val) {
|
|
times = val.poolTime
|
|
$('.giftBox').find('img').attr('src', val.poolPrize.prizeImgUrl)
|
|
$('.giftBox').removeClass('hide')
|
|
$('.experience').find('.times').html(times + '秒')
|
|
clearInterval(timeTimer)
|
|
timeTimer = setInterval(function () {
|
|
times--
|
|
if (times === 0) {
|
|
// timeFlag = 0
|
|
clearInterval(timeTimer)
|
|
$('.giftBox').addClass('hide')
|
|
}
|
|
$('.experience').find('.times').html(times + '秒')
|
|
}, 1000)
|
|
}
|
|
|
|
// 获取门票数
|
|
function getTicketNum () {
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: api + '/activities/draw/queryTicketNum',
|
|
data: {
|
|
uid: info.uid
|
|
},
|
|
success: function (res) {
|
|
if (res.code === 200) {
|
|
$('.info').find('.ticketNum').html(res.data.num)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
// 预加载图片
|
|
function preloadImg (val) {
|
|
var img = {
|
|
imageArr: turntable[val].prizeImg,
|
|
doneFunc: function () {
|
|
clearInterval(imgTimer)
|
|
imgTimer = setTimeout(function () {
|
|
getCanvas(val)
|
|
}, 50)
|
|
}
|
|
}
|
|
preloadImage(img)
|
|
}
|
|
|
|
// 转盘
|
|
function getCanvas (val) {
|
|
var img
|
|
if (val === 0) {
|
|
$('#table').show()
|
|
$('#table2').hide()
|
|
} else {
|
|
$('#table').hide()
|
|
$('#table2').show()
|
|
}
|
|
for (let i in turntable[val].prizeImg) {
|
|
img = new Image()
|
|
img.src = turntable[val].prizeImg[i]
|
|
turntable[val].prizeImgArr.push(img)
|
|
}
|
|
var count = turntable[val].prizeImg.length
|
|
img.onload = function () {
|
|
var baseAngle = Math.PI * 2 / count
|
|
var _circle = (val === 0) ? document.getElementById('table') : document.getElementById('table2')
|
|
var circle = _circle.getContext('2d')
|
|
clearTimeout(canvasTimer)
|
|
canvasTimer = setTimeout(function () {
|
|
for (var i = 0; i < turntable[val].prizeImg.length; i++) {
|
|
circle.save()
|
|
circle.translate(_circle.width / 2, _circle.height / 2)
|
|
circle.strokeStyle = 'transparent'
|
|
var angle = i * baseAngle
|
|
var colorIndex = i % 2
|
|
circle.fillStyle = turntable[val].colors[colorIndex]
|
|
circle.beginPath()
|
|
circle.moveTo(0, 0)
|
|
circle.arc(0, 0, 214, angle, angle + baseAngle, false)
|
|
circle.stroke()
|
|
circle.fill()
|
|
circle.rotate(angle + baseAngle / 2 + Math.PI / 2)
|
|
circle.imageSmoothEnabled = false
|
|
circle.drawImage(turntable[val].prizeImgArr[i], -55, -210, 100, 100)
|
|
circle.restore()
|
|
}
|
|
clearTimeout(canvasTimer)
|
|
}, 10)
|
|
}
|
|
}
|
|
|
|
// 旋转
|
|
function rotateFunc (item, count, data, idList, val) {
|
|
// $('.canvas').css({
|
|
// transform: 'scale(.5)'
|
|
// })
|
|
giftIntro['gatherId'] = item
|
|
giftIntro['gatherIdList'] = idList
|
|
console.log(giftIntro);
|
|
var baseAngle = 360 / count
|
|
var angle = 360 * 3 / 4 - (item * baseAngle) - baseAngle / 2
|
|
giftIntro['angle'] = angle
|
|
var $rotate = (val === 0) ? $('#table') : $('#table2')
|
|
$rotate.stopRotate()
|
|
$rotate.rotate({
|
|
angle: 0,
|
|
animateTo: angle + 360 * 5,
|
|
duration: 3000,
|
|
callback: function () {
|
|
// 获取弹窗渲染
|
|
var $data = {
|
|
gatherList: data
|
|
}
|
|
$('.gift-list').html(template('gatherListTmp', $data))
|
|
$('.gather-mask').show()
|
|
$('.shade').show()
|
|
clearTimeout(giftTimer)
|
|
giftTimer = setTimeout(function () {
|
|
$('.gather-mask').hide()
|
|
$('.shade').hide()
|
|
clearTimeout(giftTimer)
|
|
}, 1500)
|
|
}
|
|
})
|
|
}
|
|
|
|
// 渲染排行榜
|
|
function renderRank (val) {
|
|
var tipsObj = {
|
|
0: '抽奖票数越多,排名越高哦~每日零点重置',
|
|
1: '获得奖励价值越高,排名越高哦~每日零点重置'
|
|
}
|
|
var urlObj = {
|
|
0: '/activities/rank/ticketList',
|
|
1: '/activities/rank/giftList'
|
|
}
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: api + urlObj[rankTabIndex],
|
|
data: {
|
|
uid: info.uid
|
|
},
|
|
success: function (res) {
|
|
if (res.code === 200) {
|
|
$('.rank-mask').find('.tips p').html(tipsObj[rankTabIndex])
|
|
for (var i in res.data.rankVoList) {
|
|
if (res.data.rankVoList[i].nick.length > 5) {
|
|
res.data.rankVoList[i].nick = res.data.rankVoList[i].nick.substring(0, 5) + '...'
|
|
}
|
|
if (i > 0) {
|
|
var distance = res.data.rankVoList[i - 1].value - res.data.rankVoList[i].value
|
|
if (distance > 10000) {
|
|
res.data.rankVoList[i]['distance'] = (distance / 10000).toFixed(1) + '万'
|
|
} else {
|
|
res.data.rankVoList[i]['distance'] = distance
|
|
}
|
|
}
|
|
}
|
|
if (!val) {
|
|
$('.rank-mask').animate({
|
|
top: 0
|
|
}, 500, function () {
|
|
var $data = {
|
|
rankList: res.data.rankVoList
|
|
}
|
|
$('.rank-container').html(template('rankListTmp', $data)).fadeIn(500)
|
|
})
|
|
} else {
|
|
var $data = {
|
|
rankList: res.data.rankVoList
|
|
}
|
|
$('.rank-container').fadeOut(500, function () {
|
|
$('.rank-container').html(template('rankListTmp', $data))
|
|
}).fadeIn(500)
|
|
}
|
|
|
|
if (res.data.myRank.nick.length > 5) {
|
|
res.data.myRank.nick = res.data.myRank.nick.substring(0, 5) + '...'
|
|
}
|
|
if (res.data.myRank.value > 10000) {
|
|
res.data.myRank.value = (res.data.myRank.value / 10000).toFixed(1) + '万'
|
|
}
|
|
|
|
$('.mine').find('.rank-num').html(res.data.myRank.rank)
|
|
$('.mine').find('.avatar img').attr('src', res.data.myRank.avatar)
|
|
$('.mine').find('.nick').html(res.data.myRank.nick)
|
|
if (rankTabIndex === 0) {
|
|
$('.mine').find('.score').html('我的捧场值:' + res.data.myRank.value)
|
|
} else {
|
|
$('.mine').find('.score').html('我的迷人值:' + res.data.myRank.value)
|
|
}
|
|
if (res.data.myRank.rank < 21) {
|
|
if (res.data.myRank.rank > 10 && res.data.myRank.rank < 21) {
|
|
$('.mine').find('.num').html(res.data.myRank.diffValue)
|
|
$('.mine').find('.distance').html('距上榜')
|
|
} else if (res.data.myRank.rank < 11 && res.data.myRank.rank > 1) {
|
|
$('.mine').find('.num').html(res.data.myRank.diffValue)
|
|
$('.mine').find('.distance').html('距上名')
|
|
} else {
|
|
$('.mine').find('.num').html(res.data.myRank.diffValue)
|
|
}
|
|
} else {
|
|
$('.mine').find('.num').html(res.data.myRank.diffValue)
|
|
$('.mine').find('.distance').html('未上榜')
|
|
}
|
|
// 跳转个人主页
|
|
$('.rank-container').on('click', '.avatar', function () {
|
|
var uid = $(this).attr('data-uid');
|
|
tools.nativeUtils.jumpAppointPage('PERSON_PAGE', uid);
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
var recordCache = []
|
|
var scrollFlag = false
|
|
var recordTimer
|
|
// 渲染抽奖记录
|
|
function renderRecord (val) {
|
|
var typeObj = {
|
|
0: 'time',
|
|
1: 'worth'
|
|
}
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: api + '/activities/draw/drawRecord',
|
|
data: {
|
|
uid: info.uid,
|
|
sortType: typeObj[recordTabIndex],
|
|
page: recordPageNum,
|
|
pageSize: 10
|
|
},
|
|
success: function (res) {
|
|
if (res.code === 200) {
|
|
if (res.data.length === 0) {
|
|
return
|
|
}
|
|
if (recordTabIndex === 0) {
|
|
for (var i in res.data) {
|
|
var date = new Date(res.data[i].createTime)
|
|
var year = date.getFullYear()
|
|
var month = date.getMonth() + 1
|
|
var day = date.getDate()
|
|
var hour = date.getHours()
|
|
var minute = date.getMinutes()
|
|
var second = date.getSeconds()
|
|
res.data[i].ymd = year + '-' + month + '-' + day
|
|
res.data[i].hms = hour + ':' + minute + ':' + second
|
|
}
|
|
}
|
|
if (scrollFlag) {
|
|
if (res.data.length > 0) {
|
|
for (var j in res.data) {
|
|
recordCache.push(res.data[j])
|
|
}
|
|
} else {
|
|
$('.loading').html('暂无更多数据')
|
|
}
|
|
var $data2 = {
|
|
recordList: recordCache,
|
|
// eslint-disable-next-line no-unneeded-ternary
|
|
worth: (recordTabIndex === 1) ? true : false
|
|
}
|
|
$('.loading').show()
|
|
clearTimeout(recordTimer)
|
|
recordTimer = setTimeout(function () {
|
|
$('.loading').hide()
|
|
$('.record-container').html(template('recordTmp', $data2))
|
|
scrollFlag = !scrollFlag
|
|
}, 2000)
|
|
return
|
|
}
|
|
if (!val) {
|
|
recordCache = []
|
|
$('.record-mask').animate({
|
|
top: 0
|
|
}, 500, function () {
|
|
recordCache = res.data
|
|
var $data = {
|
|
recordList: recordCache,
|
|
// eslint-disable-next-line no-unneeded-ternary
|
|
worth: (recordTabIndex === 1) ? true : false
|
|
}
|
|
$('.record-container').html(template('recordTmp', $data)).fadeIn(500)
|
|
})
|
|
} else {
|
|
recordCache = []
|
|
recordCache = res.data
|
|
var $data = {
|
|
recordList: recordCache,
|
|
// eslint-disable-next-line no-unneeded-ternary
|
|
worth: (recordTabIndex === 1) ? true : false
|
|
}
|
|
$('.record-container').fadeOut(500, function () {
|
|
$('.record-container').html(template('recordTmp', $data))
|
|
}).fadeIn(500)
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|