Files
yinmeng-h5/view/yinmeng/activity/midAutumnFestival/js/index.js
2023-09-25 15:47:34 +08:00

698 lines
24 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.name}</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);
$('.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);