229 lines
7.7 KiB
JavaScript
229 lines
7.7 KiB
JavaScript
let urlPrefix = getUrlPrefix()
|
|
|
|
let isSelectHw = false
|
|
let isSelectDay = false
|
|
let hwPrice = 0
|
|
let selectDays = 0
|
|
|
|
let prodIDArr = [];
|
|
let headwearArr = [];//獲取頭飾
|
|
let giftNameArr = [];//禮物名稱數組
|
|
|
|
let limitPurchaseSwitch //後臺是否開啟限購
|
|
let remainDayArr = [];//用戶剩余購買天數數組
|
|
let userRemainDay;//用戶剩余購買天數
|
|
|
|
let isNeedUpgrade
|
|
|
|
const toastMsg = (content = '操作完成', time = 2) => {
|
|
layer.open({
|
|
content,
|
|
skin: 'msg',
|
|
time
|
|
});
|
|
}
|
|
// 獲取頭飾請求
|
|
function headwearFun() {
|
|
networkRequest({
|
|
type: 'GET',
|
|
url: urlPrefix + '/seekElfin/product/list',
|
|
data: {
|
|
uid: pubInfo.uid
|
|
},
|
|
success: function (res) {
|
|
if (res.code == 200) {
|
|
res.data.forEach(res => {
|
|
if (res.prodId == 1) {
|
|
prodIDArr[0] = res.prodId
|
|
} else if (res.prodId == 2){
|
|
prodIDArr[1] = res.prodId
|
|
} else {
|
|
prodIDArr[2] = res.prodId
|
|
}
|
|
})
|
|
console.log('prodIDArr', prodIDArr);
|
|
headwearArr = res.data;
|
|
// 設置頭飾
|
|
headwearArr.map((item, index) => {
|
|
giftNameArr[index] = item.giftName
|
|
$('.headwear-wrap .headwear-item').eq(index).find('.pic-wrap img').attr("src", headwearArr[index].headwearPic)
|
|
})
|
|
console.log('giftNameArr', giftNameArr);
|
|
} else if (res.code == 80002) {
|
|
isNeedUpgrade = true
|
|
return toastMsg('當前版本過低,請前往升級最高版本使用~')
|
|
}
|
|
},
|
|
error: function (res) {
|
|
console.log(res, '報錯啦');
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
// 廣告輪播
|
|
function advertising() {
|
|
networkRequest({
|
|
type: 'GET',
|
|
url: urlPrefix + '/seekElfin/draw/list',
|
|
data: {
|
|
count: 20
|
|
},
|
|
success: function (res) {
|
|
if (res.code == 200) {
|
|
// console.log(res.data)
|
|
let result = ''
|
|
res.data.forEach(res => {
|
|
result += `
|
|
<li>
|
|
<img src="./image/laba.png" alt="">
|
|
<div>恭喜!<span class="nick">${res.nick.length > 4 ? res.nick.slice(0, 4)+'...' : res.nick}</span> 購買${res.prodName}尋找到小精靈獲得<span class="diamond-num">${res.giftName}</span></div>
|
|
</li>
|
|
`
|
|
})
|
|
$('.ul1').append(result)
|
|
var num = $(".ul1").find("li").length;
|
|
if (num > 1) {
|
|
setInterval(function () {
|
|
$('.ul1').animate({
|
|
marginTop: "-0.32rem"
|
|
}, 200, function () {
|
|
$(this).css({
|
|
marginTop: "0"
|
|
}).find("li:first").appendTo(this);
|
|
});
|
|
}, 2000);
|
|
}
|
|
}
|
|
},
|
|
error: function (res) {
|
|
console.log(res, '報錯啦');
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
// 獲取頭飾限購信息
|
|
function getLimitInfo() {
|
|
networkRequest({
|
|
type: 'GET',
|
|
url: urlPrefix + '/seekElfin/limit/purchase/display',
|
|
success: function (res) {
|
|
if (res.code == 200) {
|
|
limitPurchaseSwitch = res.data.limitPurchaseSwitch
|
|
if (limitPurchaseSwitch) {
|
|
list = res.data.list
|
|
let str = ''
|
|
list.map((item) => {
|
|
remainDayArr.push(item.remainDay)
|
|
str += `
|
|
<div class="headwear-info">
|
|
<div class="hw-pic"><img src="${item.headwearPic}" alt=""></div>
|
|
<div class="hw-name">${item.prodName} (1天)</div>
|
|
<div class="hw-days">還可購<span>${item.remainDay}</span>天</div>
|
|
</div>
|
|
`
|
|
})
|
|
console.log(remainDayArr);
|
|
$('.headwear-info-wrap').html(str)
|
|
$('.shade-mask').show()
|
|
$('body').css('overflow', 'hidden')
|
|
}
|
|
}
|
|
},
|
|
error: function (res) {
|
|
console.log(res, '報錯啦');
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
$(function () {
|
|
sessionStorage.clear()
|
|
if (EnvCheck() == 'test') {
|
|
new VConsole();
|
|
}
|
|
getInfoFromClient()
|
|
setTimeout(() => {
|
|
headwearFun()//獲取頭飾
|
|
advertising()//通告欄滾動調用
|
|
getLimitInfo()//後臺是否配置開啟限購
|
|
}, 50)
|
|
|
|
|
|
$('.headwear-wrap').on('click', '.headwear-item', function () {
|
|
let index = $(this).index()
|
|
console.log(index);
|
|
userRemainDay = remainDayArr[index]
|
|
$(this).find('.pic-wrap').addClass('active')
|
|
$(this).siblings('div').find('.pic-wrap').removeClass('active')
|
|
isSelectHw = true
|
|
|
|
if (!index) {
|
|
hwPrice = 1000;
|
|
let obj = {
|
|
'diamondNum': 1000,
|
|
'selectSrc': $('.headwear-wrap .headwear-item').eq(index).find('.pic-wrap img').attr('src'),
|
|
'prodID': prodIDArr[index],
|
|
limitPurchaseSwitch: limitPurchaseSwitch,
|
|
userRemainDay,
|
|
giftName: giftNameArr[index]
|
|
}
|
|
window.sessionStorage.setItem('userSelectInfo', JSON.stringify(obj))
|
|
} else if (index == 1) {
|
|
hwPrice = 10000;
|
|
let obj = {
|
|
'diamondNum': 10000,
|
|
'selectSrc': $('.headwear-wrap .headwear-item').eq(index).find('.pic-wrap img').attr('src'),
|
|
'prodID': prodIDArr[index],
|
|
limitPurchaseSwitch: limitPurchaseSwitch,
|
|
userRemainDay,
|
|
giftName: giftNameArr[index]
|
|
}
|
|
window.sessionStorage.setItem('userSelectInfo', JSON.stringify(obj))
|
|
} else {
|
|
hwPrice = 100000;
|
|
let obj = {
|
|
'diamondNum': 100000,
|
|
'selectSrc': $('.headwear-wrap .headwear-item').eq(index).find('.pic-wrap img').attr('src'),
|
|
'prodID': prodIDArr[index],
|
|
limitPurchaseSwitch: limitPurchaseSwitch,
|
|
userRemainDay,
|
|
giftName: giftNameArr[index]
|
|
}
|
|
window.sessionStorage.setItem('userSelectInfo', JSON.stringify(obj))
|
|
}
|
|
|
|
if (isSelectHw && isSelectDay) $('.total-price span').html(hwPrice * selectDays)
|
|
})
|
|
|
|
$('.select-item').on('click', 'p', function () {
|
|
isSelectDay = true
|
|
selectDays = $(this).index() + 1
|
|
window.sessionStorage.setItem('selectDays', selectDays)
|
|
$(this).addClass('active').siblings('p').removeClass('active')
|
|
if (isSelectHw && isSelectDay) $('.total-price span').html(hwPrice * selectDays)
|
|
})
|
|
|
|
$('.buy-btn').on('click', () => {
|
|
if (isNeedUpgrade) return toastMsg('當前版本過低,請前往升級最高版本使用~');
|
|
if (!isSelectHw) return toastMsg('請選擇頭飾');
|
|
if (!isSelectDay) return toastMsg('請選擇購買天數');
|
|
if (selectDays > userRemainDay) return toastMsg('購買頭飾不能超過限購天數');
|
|
window.location.href = './main.html'
|
|
})
|
|
|
|
$('.know').on('click', function () {
|
|
$('.shade-mask').hide()
|
|
$('body').css('overflow', 'auto')
|
|
})
|
|
})
|
|
|
|
|
|
window.onpageshow = function(e){
|
|
if (e.persisted) {
|
|
window.location.reload()
|
|
}
|
|
}
|
|
|