Files
peko-h5/view/peko/activity/midAutumnFestival/js/index.js

699 lines
24 KiB
JavaScript
Raw Normal View History

2023-09-22 11:31: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'
})
}
var curDate; //當天日期;
var rankType = 1; //排行榜類型1=送禮日榜2=送禮總榜3=收禮日榜4=收禮總榜);
var type = 'a';//a:送禮b:收禮;
var type2 = 'a';//a:日榜b:總榜;
var data = null;//默認日榜;
var roomUid = null;//房間uid;
var isEndTime = false;
var moonCakeNum = 0;//我的
var page = 1;//抽獎頁碼
var drawPageSizeLack = true;//抽獎鎖
var drawLock = true;//控制抽獎鎖
var dynamicWorldId;//話題id
var timeOut2;//時間戳存儲器
var leftTime;//倒計時暫存
// 初始化函數
$(function () {
getInfoFromClient()
setTimeout(function () {
// 頁面全屏
if (browser.app) {
if (browser.android) {
window.androidJsObj.initShowNav(false)
} else {
window.webkit.messageHandlers.initShowNav.postMessage(0)
}
};
// 頂部返回事件
$('.back').click(() => {
if (browser.android) {
window.androidJsObj.closeWebView()
} else {
window.webkit.messageHandlers.closeWebView.postMessage(null)
}
})
swiperFun();
getConfig();
getRecommendRoom();
jackpotConfig();
}, 100)
})
// 獲取月餅券接口
function getDrawConfig () {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023MidAutumn/draw/getConfig',
success (res) {
if (res.code === 200) {
moonCakeNum = res.data.moonCakeNum;
$('.page1 .play2 .playBox2 .task .moonSecurities').text(`我的月餅劵:${moonCakeNum}`);
$('.page1 .play3 .draw .moom').text(`我的月餅券:${moonCakeNum}`);
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 獲取房間Uid接口
function getRecommendRoom () {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/home/tab/home/one',
success (res) {
if (res.code === 200) {
roomUid = res.data;
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 獲取瓜分接口
function jackpotConfig () {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023MidAutumn/jackpot/getConfig',
success (res) {
if (res.code === 200) {
// 處理瓜分按鈕狀態
$('.page1 .play1 .bRuleBg .guafenBut').attr('src', res.data.allotStatus == 0 ? './images/guafenBut2.png' : res.data.allotStatus == 1 ? './images/guafenBut.png' : './images/guafenBut3.png')
if (res.data.allotStatus == 1) {
$('.page1 .play1 .bRuleBg .guafenBut').attr('click', 1);
}
// 設置當前獎池數量
$('.page1 .play1 .playBox .dosBg b').text(res.data.jackpotDiamonds);
// 設置倒計時
leftTime = res.data.jackpotEndTime - res.timestamp;
if (leftTime >= 0) {
countup();
}else{
$('.page1 .play1 .playBox .dosBg p').html(`<span class="span1">00</span>時<span class="span2">00</span>分<span class="span3">00</span>秒`)
}
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 倒計時
function countup () {
clearTimeout(timeOut2)
//獲取當前時間
var d = 0;
var h = 0;
var m = 0;
var s = 0;
//定義變量 d,h,m,s保存倒計時的時間
var d, h, m, s;
if (leftTime >= 0) {
d = getzf(Math.floor(leftTime / 1000 / 60 / 60 / 24));
h = getzf(Math.floor(leftTime / 1000 / 60 / 60 % 24));
m = getzf(Math.floor(leftTime / 1000 / 60 % 60));
s = getzf(Math.floor(leftTime / 1000 % 60));
//將倒計時賦值到div中
$('.page1 .play1 .playBox .dosBg p .span1').text(h)
$('.page1 .play1 .playBox .dosBg p .span2').text(m)
$('.page1 .play1 .playBox .dosBg p .span3').text(s)
leftTime = leftTime - 1000;
//遞歸每秒調⽤countTime⽅法顯⽰動態時間效果
} else {
location.reload();
return
}
timeOut2 = setTimeout(countup, 1000);
}
//補0操作
function getzf (num) {
if (parseInt(num) < 10) {
num = '0' + num;
}
return num;
}
// 獲取首頁任務接口
function getConfig () {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023MidAutumn/task/getConfig',
success (res) {
if (res.code === 200) {
// 設置話題id
dynamicWorldId = res.data.worldId;
// 判斷活動結束時間
if (res.timestamp > res.data.endTime) {
isEndTime = true;
$('.endActivity').show();
}
// 我的月餅券
moonCakeNum = res.data.moonCakeNum;
$('.page1 .play2 .playBox2 .task .moonSecurities').text(`我的月餅劵:${moonCakeNum}`);
$('.page1 .play3 .draw .moom').text(`我的月餅券:${moonCakeNum}`);
// 處理每日任務狀態
res.data.dailyTaskList.forEach((res, i) => {
$(`.page1 .play2 .playBox2 .task .taks${i + 1} .but`).attr('src', res.btnStatus == 1 ? './images/taskBut2.png' : './images/taskBut.png');
$(`.page1 .play2 .playBox2 .task .taks${i + 1} .but`).attr('click', res.btnStatus == 0 ? '0' : '1');
if (i == 0) {
$(`.page1 .play2 .playBox2 .task .taks${i + 1} p`).text(`登錄活動頁(${res.cur}/${res.need})`);
}
if (i == 1) {
$(`.page1 .play2 .playBox2 .task .taks${i + 1} p`).text(`發佈#中秋快樂#話題的動態(${res.cur}/${res.need})`);
}
})
// 處理循環任務狀態
res.data.loopTaskList.forEach((res, i) => {
$(`.page1 .play2 .playBox2 .task .taks${i + 3} .but`).attr('src', res.btnStatus == 1 ? './images/taskBut2.png' : './images/taskBut.png');
$(`.page1 .play2 .playBox2 .task .taks${i + 3} p b`).text(`今日已獲得 ${res.loop}`)
})
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 獲取榜單接口
function getRank (rankType, date) {
$('.page2 .listBox .ul ul li').remove();
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023MidAutumn/rank/getRank',
data: { rankType, date },
success (res) {
if (res.code === 200) {
// 設置當天日期
curDate = res.data.curDate;
// 處理日期
if (res.data.dateList) {
res.data.dateList.forEach((res, i) => {
$('.page2 .listBox .time div').eq(i).text(`${res[6]}.${res[8]}${res[9]}`);
$('.page2 .listBox .time div').eq(i).attr('data', res);
if (res == curDate && date == null) {
$('.page2 .listBox .time div').removeClass('active')
$('.page2 .listBox .time div').eq(i).addClass('active');
}
})
}
// 處理自己榜單
$('.page2 .listBox .my .tx').attr('src', res.data.meRank.avatar);
$('.page2 .listBox .my .num').text(res.data.meRank.ranking == 0 ? '未上榜' : res.data.meRank.ranking);
$('.page2 .listBox .my .name').text(res.data.meRank.nick);
$('.page2 .listBox .my .sore').text(`${rankType == 1 || rankType == 2 ? "思慕值:" : "寄情值:"}${unitProcessing(res.data.meRank.score, 10000, 1, 'w')}`);
// 處理前三
var top3 = res.data.rankList.slice(0, 3);
var notTop3 = res.data.rankList.slice(3);
// 處理前傘三
if (top3.length < 3) {
let arr = new Array(3 - top3.length).fill({
avatar: './images/logo.png',
nick: '虛位以待',
score: "0"
})
top3.push(...arr)
}
top3.forEach((res, index) => {
$(`.page2 .listBox .noBg .no${index + 1} .tx`).attr('src', res.avatar);
$(`.page2 .listBox .noBg .no${index + 1} p`).text(res.nick);
$(`.page2 .listBox .noBg .no${index + 1} b`).text(`${rankType == 1 || rankType == 2 ? "思慕值:" : "寄情值:"}${unitProcessing(res.score, 10000, 1, 'w')}`);
})
// 非前三
var str = '';
notTop3.forEach((res, i) => {
str += `
<li>
<div class="num">${res.ranking}</div>
<img src="./images/txBg.png" alt="" class="txBg">
<img src="${res.avatar}" alt="" class="tx">
<div class="name">${res.nick}</div>
<div class="sore">${rankType == 1 || rankType == 2 ? "思慕值:" : "寄情值:"}${unitProcessing(res.score, 10000, 1, 'w')}</div>
</li>
`
})
$('.page2 .listBox .ul ul').append(str);
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 送禮和收禮榜單切換
$('.page2 .listBox .listTab div').click(function () {
var i = $(this).index() + 1;
$('.page2 .listBox .listTab div').removeClass('listTab_active1').removeClass('listTab_active2');
$(this).addClass(`listTab_active${i}`);
$('.page2 .listBox .listText').attr('src', `./images/listText${i}.png`)
if (i == 1) {
type = 'a';
rankType = type2 == "a" ? 1 : 2;
getRank(rankType);
} else {
type = 'b';
rankType = type2 == "a" ? 3 : 4;
getRank(rankType);
}
})
// 日榜總榜切換
$('.page2 .listBox .dayTab div').click(function () {
var i = $(this).index() + 1;
$('.page2 .listBox .dayTab div').removeClass('day_active1').removeClass('day_active2');
$(this).addClass(`day_active${i}`);
if (i == 1) {
$('.page2 .listBox .time').show()
type2 = 'a';
rankType = type == "a" ? 1 : 3;
getRank(rankType);
} else {
$('.page2 .listBox .time').hide()
type2 = 'b';
rankType = type == "a" ? 2 : 4;
getRank(rankType);
}
})
// 日榜切換日期
$('.page2 .listBox .time div').click(function () {
var datas = $(this).attr('data');
$(this).addClass('active').siblings().removeClass('active');
rankType = type == "a" ? 1 : 3;//排行榜類型1=甜蜜日榜2=甜蜜總榜3=愛意日榜4=愛意總榜)
data = datas;
getRank(rankType, data);
})
// 查看規則邏輯
$('.page2 .listBox .listRule_icon').click(function () {
if (rankType == 1 || rankType == 2) {
$('.listrule1 .listrule1_in .box img').attr('src', './images/listrule1_in.png');
$('.listrule1').show();
bodyScroolFun(true);
} else {
$('.listrule2 .listrule2_in .box img').attr('src', './images/listrule2_in.png');
$('.listrule2').show();
bodyScroolFun(true);
}
})
// TAB玩法&榜單tab切換
$('.tab div').click(function () {
var i = $(this).index() + 1;
if (i == 2) {
getRank(rankType, data);
} else {
if (isEndTime) {
toastMsg('活動已結束~')
return
}
}
$(this).addClass(`tab_active${i}`).siblings().removeClass('tab_active1').removeClass('tab_active2')
$('.page1').hide();
$('.page2').hide();
$(`.page${i}`).show();
})
// 禮物輪播
function swiperFun () {
var mySwiper = new Swiper('.swiper', {
// direction: "vertical",
loop: true,
autoplay: {
delay: 3500,//
disableOnInteraction: false
}
})
}
// 月餅玩法切換
$('.stab div').click(function () {
var i = $(this).index() + 1;
$('.play1').hide();
$('.play2').hide();
$('.play3').hide();
$(`.play${i}`).show();
if (i == 1) {
jackpotConfig();
}
if (i == 3) {
getDrawConfig();
}
})
// 抽一次兌換機
$('.page1 .play3 .draw .but1').click(function () {
if (moonCakeNum <= 0) {
toastMsg('月餅券不足,請參加任務獲取~');
return
}
if (drawLock) {
drawLock = false;
draw(1);
}
})
// 抽全部兌換機
$('.page1 .play3 .draw .but10').click(function () {
if (moonCakeNum <= 0) {
toastMsg('月餅券不足,請參加任務獲取~');
return
}
if (drawLock) {
drawLock = false;
draw(null);
}
})
// 抽獎接口
function draw (num) {
$('.exchange .box ul li').remove();
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023MidAutumn/draw/draw',
data: { num },
success (res) {
if (res.code === 200) {
var str = '';
// 1頭飾2銘牌3氣泡4座駕5禮物
res.data.forEach(res => {
str += `
<li>
<img class="${res.type == 1 ? 'type1' : res.type == 2 ? 'type2' : res.type == 3 ? 'type3' : res.type == 4 ? 'type4' : res.type == 5 ? 'type5' : ''}" src="${res.pic}" alt="">
<b>x${res.num}</b>
<p>${res.desc}</p>
</li>
`})
$('.exchange .box ul').append(str);
letGo(res.data[0].seq - 1);
getDrawConfig();
} else {
drawLock = true;
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
drawLock = true;
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 兌換機滑動初始化
var valRem = [];
for (let index = 0; index < 11; index++) {
valRem[index] = `-${2.2666666667 * (index)}rem`
}
// 兌換機滑動
function letGo (res) {
$(".page1 .play3 .draw .drawBg .drawBox .drawBoxAll").css({ "top": "0rem" });
var val = valRem[res];
$(".page1 .play3 .draw .drawBg .drawBox .drawBoxAll").animate({ "top": "0rem" }, 0, "linear", function () {
$(this).animate({ "top": valRem[valRem.length - 1] }, 1300, "linear", function () {
$(this).animate({ "top": val }, 0, "linear", function () {
$('.exchange').show();
bodyScroolFun(true);
drawLock = true;
});
});
});
}
// 打開規則彈窗
$('.header .rule_icon').click(function () {
$('.rule').show();
bodyScroolFun(true);
})
// 關閉規則彈窗
$('.rule').click(function () {
$('.rule').hide();
bodyScroolFun(false);
})
// 關閉瓜分記錄彈窗
$('.dividerecordsBg').click(function () {
$('.dividerecordsBg').hide();
bodyScroolFun(false);
})
// 打開兌換記錄彈窗
$('.page1 .play3 .draw .dhjl').click(function () {
page = 1;
$('.duihuanBg .dividerecordsBg_in .ul .list').remove();
drawPageRecord(page)
})
// 獲取抽獎記錄
function drawPageRecord (page) {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023MidAutumn/draw/pageRecord',
data: { page, size: 20 },
success (res) {
if (res.code === 200) {
if (res.data.length == 0) {
drawPageSizeLack = false;
hideLoading(layerIndex)
$('.duihuanBg .dividerecordsBg_in .ul').append(str);
drawPageSizeLack = true;
$('.duihuanBg').show();
return;
}
var str = '';
res.data.forEach((res, i) => {
str += `
<div class="list">
<span>
${dateFormat(res.createTime, 'yyyy/MM/dd')}<br>
${dateFormat(res.createTime, 'hh:mm:ss')}
</span>
<p>${res.rewardDesc}</p>
</div>
`
})
$('.duihuanBg .dividerecordsBg_in .ul').append(str);
drawPageSizeLack = true;
$('.duihuanBg').show();
bodyScroolFun(true);
} else {
drawPageSizeLack = true;
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
drawPageSizeLack = true;
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
//檢測抽獎記錄是否到達底部
$(".duihuanBg .dividerecordsBg_in .ul").scroll(function () {
var divHeight = $(this).height();
var nScrollHeight = $(this)[0].scrollHeight;
var nScrollTop = $(this)[0].scrollTop;
if (nScrollTop + divHeight + 50 >= nScrollHeight) {
console.log("到達底部了");
if (drawPageSizeLack) {
drawPageSizeLack = false;
page++;
drawPageRecord(page)
}
}
});
// 打開瓜分記錄彈窗
$('.page1 .play1 .playBox .dividerecords').click(function () {
jackpotListRecord();
})
// 獲取抽獎記錄
function jackpotListRecord (page) {
$('.dividerecordsBg .dividerecordsBg_in .ul .list').remove();
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023MidAutumn/jackpot/listRecord',
data: { page, size: 20 },
success (res) {
if (res.code === 200) {
var str = '';
res.data.forEach((res, i) => {
str += `
<div class="list">
<span>
${dateFormat(res.time, 'yyyy/MM/dd')}<br>
${dateFormat(res.time, 'hh:mm:ss')}
</span>
<p>${res.diamonds}</p>
</div>
`
})
$('.dividerecordsBg .dividerecordsBg_in .ul').append(str);
$('.dividerecordsBg').show();
bodyScroolFun(true);
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 關閉兌換記錄彈窗
$('.duihuanBg').click(function () {
$('.duihuanBg').hide();
bodyScroolFun(false);
})
// 打開瓜分彈窗
$('.page1 .play1 .bRuleBg .guafenBut').click(function () {
var bool = $(this).attr('click');
if (bool == 1) {
jackpotAllotJackpot();
}
})
// 瓜分鉆石接口
function jackpotAllotJackpot () {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023MidAutumn/jackpot/allotJackpot',
success (res) {
if (res.code === 200) {
$('.carveup .carveup_in p').text(`鉆石${res.data}`);
$('.carveup').show();
bodyScroolFun(true);
jackpotConfig();
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 關閉瓜分彈窗
$('.carveup').click(function () {
$('.carveup').hide();
bodyScroolFun(false);
})
// 關閉榜單規則彈窗
$('.listrule1,.listrule2').click(function () {
$('.listrule1,.listrule2').hide();
bodyScroolFun(false);
})
// 關閉兌換機彈窗
$('.exchange .box .but').click(function () {
$('.exchange').hide();
bodyScroolFun(false);
})
// 活動結束彈窗
$('.endActivity .endActivity_in .but').click(function () {
$('.tab div').removeClass('tab_active1');
$('.tab div').eq(1).addClass('tab_active2');
$('.page1').hide();
$(`.page2`).show();
$('.endActivity').hide();
bodyScroolFun(false);
getRank(rankType, data);
})
// 去贈送福袋按鈕
$('.page1 .play1 .bRuleBg .goSengBut').click(function () {
if (browser.ios) {
window.webkit.messageHandlers.openRoomForGiftId.postMessage(JSON.stringify({ uid: roomUid, giftId: 0 }))
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openRoomForGiftId(roomUid, 0);
}
}
})
// 完成首頁任務按鈕2
$('.page1 .play2 .playBox2 .task .taks2 .but').click(function () {
var bool = $(this).attr('click');
if (bool == 1) {
return;
}
if (browser.app) {
if (browser.ios) {
window.webkit.messageHandlers.jumpAppointPage.postMessage(JSON.stringify({ routerType: 75, routerVal: dynamicWorldId }))
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
tools.nativeUtils.jumpAppointPage('DONG_TAI', dynamicWorldId);
}
}
} else {
toastMsg('請在app內打開')
}
})
// 完成首頁循環任務按鈕
$('.page1 .play2 .playBox2 .task .taks3 .but,.page1 .play2 .playBox2 .task .taks4 .but,.page1 .play2 .playBox2 .task .taks5 .but').click(function () {
if (browser.ios) {
window.webkit.messageHandlers.openRoomForGiftId.postMessage(JSON.stringify({ uid: roomUid, giftId: 0 }))
} else if (browser.android) {
if (androidJsObj && typeof androidJsObj === 'object') {
window.androidJsObj.openRoomForGiftId(roomUid, 0);
}
}
})
//返回頁面 重新請求接口
var hiddenProperty = 'hidden' in document ? 'hidden' :
'webkitHidden' in document ? 'webkitHidden' :
'mozHidden' in document ? 'mozHidden' : null;
var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
var onVisibilityChange = function () {
if (!document[hiddenProperty]) {
location.reload()
}
}
document.addEventListener(visibilityChangeEvent, onVisibilityChange);