Files
peko-h5/view/peko/modules/rule-yinyou/js/wishingWellRule.js

85 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-09-27 15:34:30 +08:00
let urlPrefix = getUrlPrefix()
getInfoFromClient()
// 封装layer消息提醒框
let layerIndex
const showLoading = (content = '加載中...') => {
2022-09-27 15:34:30 +08:00
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'
})
}
let wishingWellList = []
const getData = (boxType = 2) => {
showLoading()
networkRequest({
type: 'GET',
url: urlPrefix + '/box/getOpenBoxRule',
data: {
boxType
},
success(res){
hideLoading(layerIndex)
if(res.code === 200){
wishingWellList = res.data
renderList()
}else{
toastMsg(res.message)
}
},
error(){
hideLoading(layerIndex)
toastMsg('網絡錯誤')
2022-09-27 15:34:30 +08:00
}
})
}
const renderList = () => {
let str = ''
wishingWellList.map(item => {
str += `
<li>
<img src="${item.prizeUrl}" alt="" class="prizeUrl">
<div>
<p class="gift-name">${item.prizeName}</p>
<p class="gift-prize">${item.platformValue}&nbsp;<img src="./images/diamond.png" alt="" class="diamond"></p>
</div>
<span class="gift-rate">${item.showRate.toFixed(2)}%</span>
</li>
`
$('ul').html(str)
})
}
$(function () {
setTimeout(() => {
getData()
}, 50)
let currentIndex = 0
$('.tab').on('click', 'div', function(){
let index = $(this).index()
if(index === currentIndex) return;
$(this).addClass('active').siblings('div').removeClass('active')
if(index){
getData(7)
}else{
getData(2)
}
currentIndex = index
})
})