Files
peko-h5/view/peko/activity/act-kitchen/js/index.js

490 lines
21 KiB
JavaScript
Raw Normal View History

2023-09-25 22:14:31 +08:00
let urlPrefix = getUrlPrefix()
let browser = checkVersion()
let env = EnvCheck();
if (env == 'test') {
new VConsole();
}
// 封裝layer消息提醒框
let layerIndex
const showLoading = (content = '加載中...') => {
layer.open({
type: 2,
shadeClose: false,
content,
success (e) {
layerIndex = $(e).attr('index')
}
})
}
const hideLoading = (index) => {
layer.close(index)
}
const toastMsg = (content = '操作完成', time = 2) => {
layer.open({
content,
time,
skin: 'msg'
})
2023-09-27 17:53:23 +08:00
}
2023-09-28 16:08:27 +08:00
var diamonds = 0;//存儲當前用戶鉆石余額
var gearPosition = 100;//當前檔位;
var roundId;//當前進行輪的roundId;
var timer;//定時器存儲
var countupTimes;//存儲每個階段倒計時剩余時間戳;
2023-09-27 17:53:23 +08:00
var userComeinTime, startTime, drawStageStartTime, showResultStageStartTime, endTime;
2023-09-28 16:08:27 +08:00
var circulate = 0;//等待開獎中動效計時
var circulateTime;//存儲開獎中動效計時器
2023-09-27 17:53:23 +08:00
// 榜單類型1是鉆石榜2是歐皇榜
let type = 1
let pageSize = 20
let page = 1
let pageSizeLack = true;
2023-09-27 17:53:23 +08:00
$(function () {
getInfoFromClient()
setTimeout(function () {
getNewestAct();
}, 100)
})
// 獲取用戶相關信息
function getUserInfo () {
networkRequest({
type: 'GET',
url: urlPrefix + '/act/luckySea/getUserActInfo',
success (res) {
if (res.code === 200) {
diamonds = res.data.diamonds;
$('.my .right b').text(`今日獎勵: ${unitProcessing(res.data.todayReward, 100000, 1, 'w')}`);
$('.my .left b').text(`鉆石余額: ${unitProcessing(res.data.diamonds, 100000, 1, 'w')}`);
} else {
toastMsg(res.message)
return
}
},
error (err) {
toastMsg('網絡錯誤,請退出重進')
}
})
}
2023-09-28 16:08:27 +08:00
// 獲取最新一次的深海奇緣活動信息
2023-09-27 17:53:23 +08:00
function getNewestAct () {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/luckySea/getNewestAct',
data: { count: 10 },
success (res) {
if (res.code === 200) {
2023-09-28 16:08:27 +08:00
// 處理往輪結果傳參
2023-09-27 17:53:23 +08:00
roundId = res.data.roundId;
listLuckySeaActInfo(roundId);
if ($.isEmptyObject(res.data) || res.data.status === 4) {
return showLoading('服務器正在維護中...')
} else {
if (res.timestamp >= res.data.endTime) { //請求的還是上一輪的數據,重新請求
console.log('請求的還是上一輪的數據,必須重新請求');
showLoading()
timer = setTimeout(() => {
getNewestAct()
}, 600);
2023-09-28 16:08:27 +08:00
} else {//活動狀態(1: 選擇階段 2:正在開獎 3:已經開獎)
2023-09-27 17:53:23 +08:00
userComeinTime = res.timestamp
startTime = res.data.startTime
drawStageStartTime = res.data.drawStageStartTime
showResultStageStartTime = res.data.showResultStageStartTime
endTime = res.data.endTime
clearInterval(circulateTime);
2023-09-28 10:08:53 +08:00
listItem(roundId);
2023-09-27 17:53:23 +08:00
if (startTime <= userComeinTime && userComeinTime < drawStageStartTime) {
2023-09-28 16:08:27 +08:00
// 第一階段
console.log("第一階段");
2023-09-27 17:53:23 +08:00
countupTimes = Math.floor(((drawStageStartTime - startTime) - (userComeinTime - startTime)) / 1000 + 1);
countup(1);
$('.masks').hide();
$('.result_popup').hide();
} else if (drawStageStartTime <= userComeinTime && userComeinTime < showResultStageStartTime) {
2023-09-28 16:08:27 +08:00
// 第二階段
console.log("第二階段");
2023-09-27 17:53:23 +08:00
countupTimes = Math.floor(((showResultStageStartTime - drawStageStartTime) - (userComeinTime - drawStageStartTime)) / 1000 + 1);
countup(2);
circulateTime = setInterval(function () {
circulate = circulate > 8 ? 0 : circulate;
circulate++;
$('.box .box_in .sBox .sBox1').removeClass('sBox_active');
$(`.box .box_in .item${circulate} .sBox1`).addClass('sBox_active');
$('.box .box_in .sBox .qp').hide();
$('.masks').show();
}, 100);
} else if (showResultStageStartTime <= userComeinTime && userComeinTime < endTime) {
2023-09-28 16:08:27 +08:00
// 第三階段
console.log("第三階段");
2023-09-27 17:53:23 +08:00
countupTimes = Math.floor(((endTime - showResultStageStartTime) - (userComeinTime - showResultStageStartTime)) / 1000 + 1);
countup(3);
2023-09-28 16:08:27 +08:00
// 渲染本輪結果
2023-09-27 17:53:23 +08:00
var str = '';
$('.result_popup .result_popup_in .resultList li').remove();
res.data.drawItemList.forEach(res => {
str += `
<li>
<img src="${res.drawName == '洋蔥' ? './images/1.png' : res.drawName == '番茄' ? './images/2.png' : res.drawName == '蘑菇' ? './images/3.png' : res.drawName == '土豆' ? './images/4.png' : res.drawName == '大閘蟹' ? './images/5.png' : res.drawName == '魚' ? './images/6.png' : res.drawName == '雞肉' ? './images/7.png' : res.drawName == '龍蝦' ? './images/8.png' : res.drawImageUrl}" alt="">
<div class="name">${res.drawName}</div>
</li>
`
})
$('.result_popup .result_popup_in .resultList').append(str);
2023-09-28 16:08:27 +08:00
// 渲染本輪投入和產出
2023-09-27 17:53:23 +08:00
var costPieceNum = 0;
res.data.userDrawResult.drawRecords.forEach((res, i) => {
costPieceNum = costPieceNum + res.costPieceNum;
})
$('.result_popup .result_popup_in .income .p1 b').text(costPieceNum);
$('.result_popup .result_popup_in .income .p2 b').text(res.data.userDrawResult.prizeDiamonds);
// 處理前三
var top3 = res.data.rankUserList.slice(0, 3);
if (top3.length < 3) {
let arr = new Array(3 - top3.length).fill({
avatar: './images/logo.png',
nick: '虛位以待',
prizeDiamonds: ""
})
top3.push(...arr)
}
// 渲染前三
top3.forEach((res, i) => {
$(`.result_popup .result_popup_in .no .no${i + 1} .tx`).attr('src', res.avatar);
$(`.result_popup .result_popup_in .no .no${i + 1} .tx`).attr('uid', res.uid);
$(`.result_popup .result_popup_in .no .no${i + 1} .name`).text(res.nick);
$(`.result_popup .result_popup_in .no .no${i + 1} p b`).text(res.prizeDiamonds);
})
$('.result_popup').show();
}
}
}
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 倒計時
function countup (status) {
timer = setInterval(() => {
countupTimes--
if (countupTimes <= 0) {
if (status == 1) {
2023-09-28 10:08:53 +08:00
$('.box .boxTitle').html(`請選擇:<b>${countupTimes}</b> 秒`);
2023-09-27 17:53:23 +08:00
} else if (status == 2) {
circulate = 0;
2023-09-28 16:08:27 +08:00
$('.box .boxTitle').html(`開獎中:<b>${countupTimes}</b> 秒`);
2023-09-27 17:53:23 +08:00
} else {
2023-09-28 16:08:27 +08:00
$('.box .boxTitle').html(`下一輪:<b>${countupTimes}</b> 秒`);
2023-09-28 10:08:53 +08:00
$('.result_popup .result_popup_in .result_popup_inTitle b').html(`${countupTimes}`);
2023-09-27 17:53:23 +08:00
}
getNewestAct();
clearInterval(timer);
} else {
if (status == 1) {
$('.box .boxTitle').html(`請選擇:<b>${countupTimes}</b> 秒`);
} else if (status == 2) {
2023-09-28 16:08:27 +08:00
$('.box .boxTitle').html(`開獎中:<b>${countupTimes}</b> 秒`);
2023-09-27 17:53:23 +08:00
} else {
2023-09-28 16:08:27 +08:00
$('.box .boxTitle').html(`下一輪:<b>${countupTimes}</b> 秒`);
2023-09-27 17:53:23 +08:00
$('.result_popup .result_popup_in .result_popup_inTitle b').html(`${countupTimes}`);
}
}
}, 1000);
}
2023-09-28 16:08:27 +08:00
// 渲染抽獎列錶
2023-09-27 17:53:23 +08:00
function listItem (roundId) {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/luckySea/listItem',
data: { roundId },
success (res) {
if (res.code === 200) {
res.data.forEach((res, i) => {
$(`.box .box_in .item${i + 1}`).attr('id', res.id);
$(`.box .box_in .item${i + 1} .sBox1 img`).attr('src', res.name == '洋蔥' ? './images/1.png' : res.name == '番茄' ? './images/2.png' : res.name == '蘑菇' ? './images/3.png' : res.name == '土豆' ? './images/4.png' : res.name == '大閘蟹' ? './images/5.png' : res.name == '魚' ? './images/6.png' : res.name == '雞肉' ? './images/7.png' : res.name == '龍蝦' ? './images/8.png' : res.imgUrl);
$(`.box .box_in .item${i + 1} .qp p b`).text(res.costPieceNum);
$(`.box .box_in .item${i + 1} .bei`).text('x' + res.multiple);
$(`.box .box_in .item${i + 1} .SboxText`).text(res.name);
if (res.costPieceNum > 0) {
$(`.box .box_in .item${i + 1} .qp`).show();
$(`.box .box_in .item${i + 1} .sBox1 `).addClass('sBox_active');
} else {
$(`.box .box_in .item${i + 1} .qp`).hide();
$(`.box .box_in .item${i + 1} .sBox1 `).removeClass('sBox_active');
}
})
2023-09-27 18:12:11 +08:00
$('.box .box_in .sBox').show();
getUserInfo();
2023-09-27 17:53:23 +08:00
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
2023-09-28 16:08:27 +08:00
// 獲取往輪結果
2023-09-27 17:53:23 +08:00
function listLuckySeaActInfo (roundId) {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/luckySea/listLuckySeaActInfo',
data: { count: 10, roundId },
success (res) {
if (res.code === 200) {
res.data.forEach((res, i) => {
if (res.drawItemList.length > 1) {
2023-09-28 16:08:27 +08:00
if (res.drawName == '葷菜狂歡') {
2023-09-27 17:53:23 +08:00
$(`.resultOut .sqp_in${i + 1} `).attr('src', './images/rou.png');
} else {
$(`.resultOut .sqp_in${i + 1} `).attr('src', './images/su.png');
}
} else {
// $(`.resultOut .sqp_in${i + 1} `).attr('src', res.drawItemList[0].drawImageUrl);
$(`.resultOut .sqp_in${i + 1} `).attr('src', res.drawItemList[0].drawName == '洋蔥' ? './images/1.png' : res.drawItemList[0].drawName == '番茄' ? './images/2.png' : res.drawItemList[0].drawName == '蘑菇' ? './images/3.png' : res.drawItemList[0].drawName == '土豆' ? './images/4.png' : res.drawItemList[0].drawName == '大閘蟹' ? './images/5.png' : res.drawItemList[0].drawName == '魚' ? './images/6.png' : res.drawItemList[0].drawName == '雞肉' ? './images/7.png' : res.drawItemList[0].drawName == '龍蝦' ? './images/8.png' : res.drawItemList[0].drawImageUrl);
}
});
2023-09-27 18:12:11 +08:00
$('.resultOut .sqp_in').show();
2023-09-27 17:53:23 +08:00
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
2023-09-28 16:08:27 +08:00
// 檔位切換
2023-09-27 17:53:23 +08:00
$('.box .tab div').click(function () {
var i = $(this).index() + 1;
$(this).addClass('active').siblings().removeClass('active');
gearPosition = i == 1 ? 100 : i == 2 ? 1000 : 10000;
})
2023-09-28 16:08:27 +08:00
// 抽獎接口
2023-09-27 17:53:23 +08:00
function draw (itemId, tais) {
// showLoading()
networkRequest({
type: 'POST',
url: urlPrefix + '/act/luckySea/draw',
data: { itemId, num: gearPosition },
success (res) {
if (res.code === 200) {
listItem(roundId);
getUserInfo();
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
2023-09-28 16:08:27 +08:00
// 選擇食材按鈕
2023-09-27 17:53:23 +08:00
$('.box .box_in .sBox').click(function () {
var id = $(this).attr('id');
draw(id, $(this));
})
2023-09-28 16:08:27 +08:00
// 去充值按鈕
2023-09-27 17:53:23 +08:00
$('.my div .add').click(function () {
if (browser.app) {
if (browser.android) {
let channel = pubInfo.deviceInfo.channel;
console.log(pubInfo.deviceInfo);
if (channel == "google") {
window.androidJsObj.openChargePage(6);
} else {
window.androidJsObj.openChargePage(6);
window.location.href = urlPrefix + '/peko/modules/pay/index.html?channelType=4';
}
} else if (browser.ios) {
let channel = pubInfo.deviceInfo.channel;
if (channel == "appstore") {
window.webkit.messageHandlers.openChargePage.postMessage(null);
} else {
window.webkit.messageHandlers.chargePayClickPage.postMessage(6);
window.location.href = urlPrefix + '/peko/modules/pay/index.html?channelType=4';
}
}
} else {
toastMsg('請在app內打開')
}
})
2023-09-28 16:08:27 +08:00
// 打開規則彈窗
2023-09-27 17:53:23 +08:00
$('.header .rule_icon').click(function () {
$('.shade-mask').show()
})
2023-09-28 16:08:27 +08:00
// 關閉規則彈窗
2023-09-27 17:53:23 +08:00
$('.shade-mask').click(function () {
$('.shade-mask').hide()
})
2023-09-28 16:08:27 +08:00
// 打開遊戲記錄
2023-09-27 17:53:23 +08:00
$('.header .record_icon').click(function () {
window.location.href = './record.html'
})
2023-09-28 16:08:27 +08:00
// 關閉排行榜
2023-09-27 17:53:23 +08:00
$('.shade-mask-rank').click(function () {
$('.shade-mask-rank').hide()
return false;
})
// 監聽今日排名按鈕點擊事件
$('.header .rank_icon').click(function () {
$('.shade-mask-rank .shade-content-rank .other-rank li').remove();
page = 1;
getListRank(type, page);
2023-09-27 17:53:23 +08:00
$('.shade-mask-rank').show()
})
// 監聽今日排名tab
$('.tab-wrap').on('click', 'span', function () {
page = 1;
type = $(this).index() + 1;
$(this).addClass('active').siblings().removeClass('active');
$('.shade-mask-rank .shade-content-rank .other-rank li').remove();
getListRank(type, page);
2023-09-27 17:53:23 +08:00
return false;
})
function getListRank (type, page) {
networkRequest({
type: 'GET',
url: urlPrefix + '/act/luckySea/listRank',
data: {
type,
page,
pageSize
},
success (res) {
if (res.code === 200) {
if (page == 1) {
2023-09-28 16:08:27 +08:00
// 處理第一名
$('.shade-mask-rank .shade-content-rank .rank-top .topthree-wrap .info-wrap').remove();
let topOne = res.data.rankList.slice(0, 1)
if (topOne.length === 0) {
let arr = new Array(len).fill({
nick: '虛位以待',
avatar: './images/logo.png',
num: ''
})
topThreeArr.push(...arr)
2023-09-27 17:53:23 +08:00
}
var topOneStr = ''
topOne.forEach(item => {
topOneStr += `
<div class="info-wrap" uid="${item.uid}">
<div class="avatar">
<p></p>
<img src="${item.avatar}" alt="">
</div>
<p class="diamond-num" style="display:${type == 1 ? 'none' : 'block'}">${type == 1 ? '' : item.num}</p>
<p class="nick">${item.nick.length > 5 ? item.nick.slice(0, 5) + '...' : item.nick}</p>
</div>
`
})
$('.shade-mask-rank .shade-content-rank .rank-top .topthree-wrap').append(topOneStr);
2023-09-28 16:08:27 +08:00
//處理底部數據
let erbanNo = res.data.myRankInfo.erbanNo
let myIndex;
res.data.rankList.findIndex((item, index) => {
if (item.erbanNo == erbanNo) { myIndex = index; };
})
if (myIndex) {
$('.mine-rank').html('未上榜')
2023-09-27 17:53:23 +08:00
} else {
$('.mine-rank').html(myIndex + 1)
2023-09-27 17:53:23 +08:00
}
$('.shade-mask-rank .shade-content-rank .mine .mine-rank').text(myIndex + 1);
$('.shade-mask-rank .shade-content-rank .mine .mine-diamond-num').text(type == 1 ? `${unitProcessing(res.data.myRankInfo.num, 10000, 1, 'w')}` : `猜中 ${res.data.myRankInfo.num}`);
$('.shade-mask-rank .shade-content-rank .mine .mine-info img').attr('src', res.data.myRankInfo.avatar);
$('.shade-mask-rank .shade-content-rank .mine .mine-info .mine-nick').text(res.data.myRankInfo.nick.length > 5 ? res.data.myRankInfo.nick.slice(0, 5) + '...' : res.data.myRankInfo.nick)
}
if (res.data.rankList.length > 0) {
2023-09-28 16:08:27 +08:00
// 非前第一數據
var str = '';
var list = res.data.rankList.slice(1);
list.forEach((item, i) => {
str += `
<li uid="${item.uid}">
<span class="index">${i + 2}</span>
<div class="others-info">
<img src="${item.avatar}" alt="">
<span class="others-nick">${item.nick.length > 5 ? item.nick.slice(0, 5) + '...' : item.nick}</span>
</div>
2023-09-28 16:19:48 +08:00
<span class="others-diamond-num">${type == 1 ? `${unitProcessing(item.num, 10000, 1, 'w')}` : `猜中 ${item.num}`}</span>
</li>
`
});
$('.shade-mask-rank .shade-content-rank .other-rank').append(str);
pageSizeLack = true;
} else {
pageSizeLack = false;
2023-09-27 17:53:23 +08:00
}
} else {
pageSizeLack = true;
2023-09-27 17:53:23 +08:00
toastMsg(res.message)
}
},
error (err) {
pageSizeLack = true;
2023-09-27 17:53:23 +08:00
toastMsg('網絡錯誤')
}
})
}
2023-09-28 16:08:27 +08:00
// 檢測榜單是否滑到底部
$(".shade-mask-rank .shade-content-rank .other-rank").scroll(function () {
var divHeight = $(this).height();
var nScrollHeight = $(this)[0].scrollHeight;
var nScrollTop = $(this)[0].scrollTop;
if (nScrollTop + divHeight + 50 >= nScrollHeight) {
console.log("到達底部了");
if (pageSizeLack) {
pageSizeLack = false;
page++;
getListRank(type, page)
2023-09-27 17:53:23 +08:00
}
}
});
2023-09-28 16:08:27 +08:00
// 取消余額不足彈窗
2023-09-27 17:53:23 +08:00
$('.cancel-btn').click(function () {
$('.shade-mask-fragmentNum').hide();
})
2023-09-28 16:08:27 +08:00
// 取消余額不足跳轉彈窗按鈕
2023-09-27 17:53:23 +08:00
$('.shade-mask-fragmentNum .shade-content-fragmentNum .fragmentNum-btn-wrap .confirm-btn').click(function () {
if (browser.app) {
if (browser.android) {
let channel = pubInfo.deviceInfo.channel;
console.log(pubInfo.deviceInfo);
if (channel == "google") {
window.androidJsObj.openChargePage(6);
} else {
window.androidJsObj.openChargePage(6);
window.location.href = urlPrefix + '/peko/modules/pay/index.html?channelType=4';
}
} else if (browser.ios) {
let channel = pubInfo.deviceInfo.channel;
if (channel == "appstore") {
window.webkit.messageHandlers.openChargePage.postMessage(null);
} else {
window.webkit.messageHandlers.chargePayClickPage.postMessage(6);
window.location.href = urlPrefix + '/peko/modules/pay/index.html?channelType=4';
}
}
} else {
toastMsg('請在app內打開')
}
$('.shade-mask-fragmentNum').hide()
})