Files
peko-h5/view/peko/modules/act-wishingStar/js/index.js

563 lines
18 KiB
JavaScript
Raw Normal View History

2024-02-23 12:29:08 +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'
})
}
2024-02-26 10:25:02 +08:00
var mymagicStickNum = 0;//魔法棒数量
var getRankType = 1;//1=今日奖励榜2=次数总榜
2024-02-23 12:29:08 +08:00
// 初始化函數
$(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)
}
})
2024-02-27 10:16:03 +08:00
getConfig();
2024-02-23 12:29:08 +08:00
}, 100)
})
2024-02-26 10:25:02 +08:00
// 配置接口
function getConfig () {
// showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/promiseStar/getConfig',
success (res) {
if (res.code === 200) {
mymagicStickNum = res.data.userStickNum;
2024-02-27 10:16:03 +08:00
$('.page1 .top .centon').text(mymagicStickNum);
$('.wishingPop .wishingPop_in .magicSticks b').text(mymagicStickNum);
2024-02-26 10:25:02 +08:00
var str = '';
res.data.roundList.forEach(res => {
str += `
<li>
<div class="giftBox">
2024-02-27 10:16:03 +08:00
<img src="${res.gift.picUrl}" alt="" class="giftImg">
2024-02-26 10:25:02 +08:00
</div>
<div class="giftInfo">
2024-02-27 10:16:03 +08:00
<b>${res.gift.giftName}</b>
2024-02-26 10:25:02 +08:00
<img src="./images/diamond.png" alt="" class="diamond">
2024-02-27 10:16:03 +08:00
<i>${res.gift.goldPrice}</i>
2024-02-26 10:25:02 +08:00
</div>
<div class="inventory">庫存${res.stockNum}</div>
<div class="schedule">許願進度</div>
<div class="line">
<div class="line_in">
2024-02-27 20:16:07 +08:00
<img style="width: ${res.process / res.max * 100 >= 100 ? '100' : res.process / res.max * 100}%;" src="./images/line.png" alt="">
2024-02-26 10:25:02 +08:00
</div>
<p>${res.process}/${res.max}</p>
</div>
<div class="wishIng">已許願${res.userInputNum}</div>
2024-02-27 10:16:03 +08:00
<img src="./images/wishIngBut.png" alt="" class="wishIngBut" configId=${res.configId} roundId=${res.gift.roundId} stockNum=${res.gift.stockNum}>
2024-02-26 10:25:02 +08:00
</li>
`
});
2024-02-27 10:16:03 +08:00
$('.page1 ul li').remove()
$('.page1 ul').append(str);
2024-02-26 10:25:02 +08:00
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
2024-02-26 14:18:30 +08:00
// 刷新接口
2024-02-27 20:16:07 +08:00
$('.page1 .update').click(function () {
2024-02-26 14:18:30 +08:00
getConfig();
})
2024-02-27 20:16:07 +08:00
// 榜单接口
2024-02-26 10:25:02 +08:00
function getRank (type) {
2024-02-23 12:29:08 +08:00
showLoading()
networkRequest({
type: 'get',
2024-02-26 10:25:02 +08:00
url: urlPrefix + '/promiseStar/getRank',
data: { type },
2024-02-23 12:29:08 +08:00
success (res) {
if (res.code === 200) {
2024-02-26 10:25:02 +08:00
var str = '';
res.data.rankList.forEach((res, i) => {
str += `
2024-02-27 20:16:07 +08:00
<li class='li${i + 1}'>
2024-02-26 10:25:02 +08:00
<div class="num num${i + 1}">${i + 1 > 3 ? res.ranking : ''}</div>
<img src="${res.avatar}" alt="" class="tx">
<div class="name">${res.nick}</div>
<div class="right">
<p>${res.score}</p>
<b>許願獲獎次數</b>
</div>
</li>
`
})
2024-02-27 20:16:07 +08:00
$('.page2 .listBox li').remove()
2024-02-26 10:25:02 +08:00
$('.page2 .listBox').append(str);
2024-02-27 20:16:07 +08:00
// 处理自己
2024-02-27 22:14:55 +08:00
$('.page2 .my .num').text(res.data.meRank.ranking == 0 ? '未上榜' : res.data.meRank.ranking);
$('.page2 .my .tx').attr('src', res.data.meRank.avatar);
2024-02-27 20:16:07 +08:00
$('.page2 .my .name').text(res.data.meRank.nick);
$('.page2 .my .right p').text(res.data.meRank.score);
2024-02-23 12:29:08 +08:00
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
// Tab切换
$('.header .tabBox').on('click', ' div', function () {
var i = $(this).index() + 1;
$('.header .tabBox div').removeClass('act1').removeClass('act2');
$(this).addClass(`act${i}`);
2024-02-26 10:25:02 +08:00
$('.page1,.page2').hide();
$(`.page${i}`).show();
if (i == 2) {
getRank(getRankType);
}
})
// 榜单切换
$('.page2 .listTab div').click(function () {
var i = $(this).index() + 1;
$(this).parent('.listTab').removeClass('tab1').removeClass('tab2');
$(this).parent('.listTab').addClass(`tab${i}`)
getRankType = i;
getRank(getRankType);
})
// 打开活动规则弹窗
$('.header .rule_icon').click(function () {
$('.rule').show();
bodyScroolFun(true);
})
// 关闭活动规则弹窗
$('.rule').click(function () {
$('.rule').hide();
bodyScroolFun(false);
})
var page = 1;
var isLock = true;
// 中奖记录接口
function listLuckyRecord (page) {
2024-02-27 22:14:55 +08:00
showLoading();
2024-02-26 10:25:02 +08:00
networkRequest({
type: 'get',
url: urlPrefix + '/promiseStar/listLuckyRecord',
data: { page, pageSize: 10 },
success (res) {
if (res.code === 200) {
if (res.data.length == 0) {
isLock = false;
2024-02-27 20:16:07 +08:00
} else {
var str = '';
res.data.forEach((res, i) => {
str += `
2024-02-26 10:25:02 +08:00
<li class="${i % 2 == 0 ? '' : 'liAct'}">
<div class="left">
<p>${dateFormat(res.createTime, 'hh:mm:ss')}</p>
<i>${dateFormat(res.createTime, 'yyyy-MM-dd')}</i>
</div>
<div class="right">
<p>獲得${res.gift.giftName}</p>
<i>${res.gift.goldPrice}鉆石</i>
</div>
</li>
`
2024-02-27 20:16:07 +08:00
})
$('.record .record_in .ul1').append(str);
isLock = true;
}
2024-02-26 10:25:02 +08:00
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
isLock = true;
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
// 参与记录
function listRoundRecord (page) {
2024-02-27 22:14:55 +08:00
showLoading();
2024-02-26 10:25:02 +08:00
networkRequest({
type: 'get',
url: urlPrefix + '/promiseStar/listRoundRecord',
data: { page, pageSize: 10 },
success (res) {
if (res.code === 200) {
if (res.data.length == 0) {
isLock = false;
2024-02-27 20:16:07 +08:00
} else {
var str = '';
res.data.forEach((res, i) => {
str += `
<li class="${res.luckyUser ? '' : 'liAct'}">
2024-02-26 10:25:02 +08:00
<div class="left">
<p>${dateFormat(res.createTime, 'hh:mm:ss')}</p>
<i>${dateFormat(res.createTime, 'yyyy-MM-dd')}</i>
</div>
<div class="center">
<p>許願${res.gift.giftName}</p>
<i>${res.luckyUser ? '已结束' : '進行中'}</i>
</div>
<div class="right">
<p>${res.luckyUser ? res.luckyUser.nick : ''}</p>
<i>${res.luckyUser ? '獲得' : ''}</i>
</div>
</li>
`
2024-02-27 20:16:07 +08:00
})
$('.record .record_in .ul2').append(str);
isLock = true;
}
2024-02-26 10:25:02 +08:00
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
isLock = true;
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
// 打开参与记录按钮
$('.header .record_icon').click(function () {
2024-02-27 22:14:55 +08:00
$('.record .record_in .ul1 li').remove();
2024-02-26 10:25:02 +08:00
page = 1;
isLock = true;
2024-02-27 20:16:07 +08:00
$('.record .record_in .recordtab div').removeClass('act2').removeClass('act1');
$('.record .record_in .recordtab div').eq(0).addClass('act1');
$('.record .record_in .ul1,.record .record_in .ul2').hide();
$('.record .record_in .ul1').show();
2024-02-26 10:25:02 +08:00
listLuckyRecord(page);
$('.record').show();
bodyScroolFun(true);
})
2024-02-26 14:18:30 +08:00
// 切换参与记录按钮
$('.record .record_in .recordtab div').click(function () {
var i = $(this).index() + 1;
$('.record .record_in .recordtab div').removeClass('act1').removeClass('act2');
$(this).addClass(`act${i}`);
$('.record .record_in .ul2,.record .record_in .ul1').hide();
2024-02-27 22:14:55 +08:00
page = 1;
isLock = true;
2024-02-26 14:18:30 +08:00
if (i == 1) {
2024-02-27 22:14:55 +08:00
$('.record .record_in .ul1 li').remove();
2024-02-26 14:18:30 +08:00
listLuckyRecord(page)
} else {
2024-02-27 22:14:55 +08:00
$('.record .record_in .ul2 li').remove();
2024-02-26 14:18:30 +08:00
listRoundRecord(page)
}
$(`.record .record_in .ul${i}`).show();
return false;
})
2024-02-26 10:25:02 +08:00
// 监听滚动1
$('.record .record_in .ul1').scroll(function () {
let scrollTop = $(this).scrollTop()
let scrollHeight = $('.record .record_in .ul1')[0].scrollHeight
let ulHeight = $(this).innerHeight()
if (scrollTop + ulHeight + 100 >= scrollHeight) {
if (isLock) {
// 请求下一页
2024-02-27 20:16:07 +08:00
page = page + 1;
listLuckyRecord(page)
isLock = false;
2024-02-26 10:25:02 +08:00
}
}
})
// 监听滚动2
$('.record .record_in .ul2').scroll(function () {
let scrollTop = $(this).scrollTop()
let scrollHeight = $('.record .record_in .ul2')[0].scrollHeight
let ulHeight = $(this).innerHeight()
if (scrollTop + ulHeight + 100 >= scrollHeight) {
if (isLock) {
// 请求下一页
2024-02-27 20:16:07 +08:00
page = page + 1;
listRoundRecord(page)
isLock = false;
2024-02-26 10:25:02 +08:00
}
}
})
// 关闭参与记录按钮
$('.record').click(function () {
$('.record').hide();
bodyScroolFun(false);
})
// 关闭去充值弹窗
$('.goToPay').click(function () {
$('.goToPay').hide();
bodyScroolFun(false);
})
// 关闭购买成功按钮
$('.buySuccess .buySuccess_in .buySuccessBut').click(function () {
$('.buySuccess').hide();
bodyScroolFun(false);
})
// 去充值按钮
$('.goToPay .goToPay_in .but').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內打開')
}
$('.goToPay').hide();
bodyScroolFun(false);
return false;
})
var magicStickNum = 1;
function magicStick (type, num) {
magicStickNum = Number($('.magicStick .magicStick_in input').val());
if (type == 1) {
// 加
magicStickNum++;
} else if (type == 2) {
// 减
magicStickNum--;
} else if (type == 3) {
// 快捷购买
magicStickNum += num;
} else {
}
2024-02-27 20:16:07 +08:00
magicStickNum <= 0 ? magicStickNum = 0 : magicStickNum = magicStickNum;
2024-02-26 10:25:02 +08:00
magicStickNum >= 99999999 ? magicStickNum = 99999999 : magicStickNum = magicStickNum;
$('.magicStick .magicStick_in .magicSticks b').text(magicStickNum * 100);
$('.magicStick .magicStick_in input').val(magicStickNum);
}
// 打开购买魔法棒弹窗
$('.page1 .top .but').click(function () {
$('.magicStick .magicStick_in h3').text('購買數量');
$('.magicStick').show();
bodyScroolFun(true);
})
// 魔法棒加弹窗
$('.magicStick .magicStick_in .add').click(function () {
magicStick(1)
return false;
})
// 魔法棒减弹窗
$('.magicStick .magicStick_in .decrease').click(function () {
magicStick(2)
return false;
})
// 魔法棒快捷购买弹窗
$('.magicStick .magicStick_in .quickAddition div').click(function () {
var num = Number($(this).attr('num'));
magicStick(3, num)
return false;
})
// 监听输入框的变化
$('.magicStick .magicStick_in input').on('input', function () {
magicStick();
})
// 魔法棒输入框弹窗
$('.magicStick .magicStick_in input').click(function () {
return false;
})
// 关闭购买魔法棒弹窗
$('.magicStick').click(function () {
$('.magicStick').hide();
bodyScroolFun(false);
})
// 确认购买魔法棒按钮
$('.magicStick .magicStick_in .but').click(function () {
2024-02-27 20:16:07 +08:00
if (magicStickNum <= 0) {
return toastMsg('購買數量不能小於1')
}
2024-02-26 10:25:02 +08:00
buyStick(magicStickNum)
bodyScroolFun(false);
})
// 购买魔法棒
function buyStick (num) {
showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/promiseStar/buyStick',
data: { num },
success (res) {
if (res.code === 200) {
getConfig();
2024-02-27 10:16:03 +08:00
$('.buySuccess p').text(`魔法棒${num}`);
2024-02-26 10:25:02 +08:00
$('.buySuccess').show();
bodyScroolFun(true);
magicStickNum = 1;
2024-02-27 10:16:03 +08:00
$('.magicStick .magicStick_in input').val(magicStickNum);
$('.magicStick .magicStick_in .magicSticks b').text(100);
2024-02-26 10:25:02 +08:00
} else if (res.code === 31005) {
$('.goToPay').show();
bodyScroolFun(true);
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
var wishingNum = 1;
function wishing (type, num) {
wishingNum = Number($('.wishingPop .wishingPop_in input').val());
if (type == 1) {
// 加
wishingNum++;
} else if (type == 2) {
// 减
wishingNum--;
} else if (type == 3) {
// 快捷购买
wishingNum += num;
} else {
}
2024-02-27 20:16:07 +08:00
wishingNum <= 0 ? wishingNum = 0 : wishingNum = wishingNum;
2024-02-26 10:25:02 +08:00
wishingNum >= 99999999 ? wishingNum = 99999999 : wishingNum = wishingNum;
$('.wishingPop .wishingPop_in input').val(wishingNum);
}
// 许愿加弹窗
$('.wishingPop .wishingPop_in .add').click(function () {
wishing(1)
return false;
})
// 许愿减弹窗
$('.wishingPop .wishingPop_in .decrease').click(function () {
wishing(2)
return false;
})
// 许愿快捷购买弹窗
$('.wishingPop .wishingPop_in .quickAddition div').click(function () {
var num = Number($(this).attr('num'));
wishing(3, num)
return false;
})
// 监听输入框的变化
$('.wishingPop .wishingPop_in input').on('input', function () {
wishing();
})
// 许愿输入框弹窗
$('.wishingPop .wishingPop_in input').click(function () {
return false;
})
// 关闭许愿弹窗
$('.wishingPop').click(function () {
$('.wishingPop').hide();
bodyScroolFun(false);
})
// 许愿按钮
var roundId;
2024-02-27 20:16:07 +08:00
var configId;
2024-02-27 10:16:03 +08:00
$('.page1 ul').on('click', 'li .wishIngBut', function () {
2024-02-26 10:25:02 +08:00
var stockNum = $(this).attr('stockNum');
roundId = $(this).attr('roundId');
2024-02-27 20:16:07 +08:00
configId = $(this).attr('configId');
2024-02-26 10:25:02 +08:00
if (stockNum == 0) {
toastMsg('该礼物库存不足,无法进行许愿');
return;
}
$('.wishingPop').show();
})
// 确认许愿按钮
$('.wishingPop .wishingPop_in .but').click(function () {
console.log(wishingNum < mymagicStickNum);
2024-02-27 20:16:07 +08:00
if (wishingNum <= 0) {
return toastMsg('許願數量不能小於1')
}
2024-02-26 10:25:02 +08:00
if (wishingNum > mymagicStickNum) {
$('.magicStick .magicStick_in h3').text('可用魔法棒不足,请购买');
$('.magicStick').show();
bodyScroolFun(true);
} else {
2024-02-27 20:16:07 +08:00
promise(wishingNum, configId);
2024-02-26 10:25:02 +08:00
bodyScroolFun(false);
}
})
// 许愿接口
2024-02-27 20:16:07 +08:00
function promise (num, configId) {
2024-02-26 10:25:02 +08:00
showLoading()
networkRequest({
type: 'post',
url: urlPrefix + '/promiseStar/promise',
2024-02-27 20:16:07 +08:00
data: { num, promiseId: configId },
2024-02-26 10:25:02 +08:00
success (res) {
if (res.code === 200) {
2024-02-27 10:16:03 +08:00
wishingNum = 1;
$('.wishingPop .wishingPop_in input').val(wishingNum)
2024-02-26 10:25:02 +08:00
toastMsg('参与许愿成功')
2024-02-27 20:16:07 +08:00
} else if (res.code === 5003) {
2024-02-27 10:16:03 +08:00
$('.magicStick .magicStick_in h3').text('可用魔法棒不足,请购买');
$('.magicStick').show();
2024-02-26 10:25:02 +08:00
} else {
toastMsg(res.message)
}
2024-02-27 20:16:07 +08:00
getConfig();
2024-02-26 10:25:02 +08:00
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}