107 lines
2.9 KiB
JavaScript
107 lines
2.9 KiB
JavaScript
let locateObj = getQueryString()
|
|
let urlPrefix = getUrlPrefix()
|
|
let luckyBagPoolInfoMaps;
|
|
// 封装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 ids;
|
|
let list = []
|
|
const getList = () => {
|
|
networkRequest({
|
|
type: 'GET',
|
|
url: urlPrefix + '/gift/luckyBag/playInfo',
|
|
success (res) {
|
|
if (res.code == 200) {
|
|
luckyBagPoolInfoMaps = res.data.luckyBagPoolInfoMap;
|
|
headerListFun(res)
|
|
} else {
|
|
toastMsg(res.message)
|
|
}
|
|
},
|
|
error () {
|
|
toastMsg('網絡錯誤')
|
|
}
|
|
})
|
|
}
|
|
$(function () {
|
|
// debug
|
|
if (EnvCheck() == 'test') {
|
|
new VConsole();
|
|
}
|
|
getInfoFromClient()
|
|
setTimeout(function () {
|
|
getList()
|
|
},50)
|
|
})
|
|
function bodyList (id) {
|
|
$('.wrap .gift_item_contain li').remove();
|
|
console.log(luckyBagPoolInfoMaps[id]);
|
|
var str = '';
|
|
luckyBagPoolInfoMaps[id].forEach((res) => {
|
|
str += `
|
|
<li>
|
|
<img src="${res.giftUrl}" alt="" class="gift_item_pic">
|
|
<span class="gift_item_name">${res.giftName}</span>
|
|
<p class="gift_item_price">
|
|
<img src="./images/diamond.png" alt="">
|
|
<span>${res.goldPrice}</span>
|
|
</p>
|
|
<span class="ratio">${res.giftRatio}%</span>
|
|
</li>
|
|
`
|
|
})
|
|
$('.wrap .gift_item_contain').append(str);
|
|
}
|
|
|
|
function headerListFun (res) {
|
|
ids = getQueryString().giftID;
|
|
res.data.luckyBagInfoList.forEach((val, i) => {
|
|
if (val.luckyBagId == ids) {
|
|
$('.select_gift_name').text(val.luckBagName);
|
|
res.data.luckyBagInfoList.unshift(res.data.luckyBagInfoList.splice(i, 1)[0])
|
|
return
|
|
}
|
|
})
|
|
// 渲染元素
|
|
var strHeader = '';
|
|
res.data.luckyBagInfoList.forEach((res, i) => {
|
|
strHeader += `
|
|
<li class="active" id='${res.luckyBagId}'>
|
|
<img src="${res.luckBagPic}" alt="">
|
|
<span>${res.luckBagName}</span>
|
|
</li>
|
|
`
|
|
});
|
|
$('.wrap .fixed_wrap .gift_list_contain .gift_list').append(strHeader);
|
|
bodyList(ids);
|
|
// 处理头部礼物位置样式
|
|
$(`.wrap .fixed_wrap .gift_list_contain .gift_list li[id=${ids}]`).addClass('active').siblings().removeClass('active');
|
|
// 点击事件
|
|
$('.wrap .fixed_wrap .gift_list_contain .gift_list li').click(function () {
|
|
ids = $(this).attr('id');
|
|
$(this).addClass('active').siblings().removeClass('active');
|
|
$('.select_gift_name').text($(this).children('span').text())
|
|
bodyList(ids);
|
|
})
|
|
}
|
|
|