Files
peko-h5/view/peko/activity/2023-ruffian/js/index.js
2023-11-06 10:06:06 +08:00

192 lines
6.2 KiB
JavaScript

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 rankType = 2;//默認送禮總榜
var type = 1;//默認送禮總榜
var time = null;//當前日期
var dayTime = null;//存儲日期;
// 初始化函數
$(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)
}
})
getConfig();
}, 100)
})
// 獲取配置接口
function getConfig () {
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023DoubleEleven/task/getConfig',
success (res) {
if (res.code === 200) {
// 處理任務狀態
res.data.dailyTaskList.forEach((res, i) => {
if (res.status == 1) {
$(`.page1 .activity1 .but${i + 1}`).addClass('out');
$(`.page1 .activity1 .but${i + 1}`).text('今日已領取');
}
});
// 設置日期
time = res.timestamp;
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// tab切換
$('.header .tab div').click(function () {
var i = $(this).index() + 1;
$(this).addClass('active').siblings().removeClass('active');
$('.page1').hide();
$('.page2').hide();
$(`.page${i}`).show();
if (i == 2) {
$('.page2 .listBg .dayTab div').removeClass('active');
$('.page2 .listBg .dayTab div').eq(2).addClass('active');
getRank(rankType, type);
}
})
// 獲取榜單接口
function getRank (rankType, type, date) {
$('.page2 .listBg .list li').remove();
showLoading()
networkRequest({
type: 'GEt',
url: urlPrefix + '/act/2023DoubleEleven/rank/getRank',
data: { rankType, date },
success (res) {
if (res.code === 200) {
// 處理前三
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, i) => {
$(`.page2 .listBg .topBox .no${i + 1} .tx`).attr('src', res.avatar);
$(`.page2 .listBg .topBox .no${i + 1} p`).text(res.nick);
$(`.page2 .listBg .topBox .no${i + 1} span`).text(`${type == 1 ? "勇氣值:" : "狂歡值:"}${unitProcessing(res.score, 10000, 1, 'w')}`);
})
// 非前三
var str = '';
notTop3.forEach((res, i) => {
str += `
<li>
<div class="num">${res.ranking}</div>
<img src="${res.avatar}" alt="" class="tx">
<div class="nick">${res.nick}</div>
<div class="score">${type == 1 ? "勇氣值:" : "狂歡值:"}${unitProcessing(res.score, 10000, 1, 'w')}</div>
</li>
`
})
$('.page2 .listBg .list').append(str);
// 處理自己榜單
$('.page2 .myList .num').text(res.data.meRank.ranking == 0 ? '未上榜' : res.data.meRank.ranking);
$('.page2 .myList .tx').attr('src', res.data.meRank.avatar);
$('.page2 .myList .nick').text(res.data.meRank.nick);
$('.page2 .myList .score').text(`${type == 1 ? "勇氣值:" : "狂歡值:"}${unitProcessing(res.data.meRank.score, 10000, 1, 'w')}`);
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 送禮榜和收禮榜切換
$('.page2 .listTab div').click(function () {
var i = $(this).index() + 1;
$(this).addClass('active').siblings().removeClass('active');
$('.page2 .listBg .dayTab div').removeClass('active');
$('.page2 .listBg .dayTab div').eq(2).addClass('active');
type = i;
dayTime = null;
if (i == 1) {
rankType = 2;
} else {
rankType = 4;
}
getRank(rankType, type, dayTime);
})
// 日榜和總榜切換
$('.page2 .listBg .dayTab div').click(function () {
var i = $(this).index() + 1;
$(this).addClass('active').siblings().removeClass('active');
if (i == 3) {
dayTime = null;
rankType = type == 1 ? 2 : 4;
} else if (i == 1) {
rankType = type == 1 ? 1 : 3;
dayTime = dateFormat(time - 86400000, 'yyyy-MM-dd')
} else if (i == 2) {
rankType = type == 1 ? 1 : 3;
dayTime = dateFormat(time, 'yyyy-MM-dd')
}
getRank(rankType, type, dayTime);
})
// 打開規則
$('.header .rule_iaon').click(function () {
$('.rule').show();
bodyScroolFun(true);
})
// 關閉規則
$('.rule').click(function () {
$('.rule').hide();
bodyScroolFun(false);
})