214 lines
8.7 KiB
JavaScript
214 lines
8.7 KiB
JavaScript
var browser = checkVersion();
|
||
const urlPrefix = getUrlPrefix();//判断正式环境或者测试环境
|
||
getInfoFromClient();
|
||
let getDataArr = [];//初始化接口返回结果;
|
||
let undoneStatus = 0;//未集齐
|
||
let OutTimeStatus = 1;//集齐但时间未开始
|
||
let lotteryStatus = 2;//可开奖状态
|
||
let outLotteryStatus = 3;//未集齐时间结束状态
|
||
let drawDegreeArr = [];//瓜分金币之后的数据
|
||
let drawDegree = null;//剩余瓜分次数
|
||
let timeQuery = null;
|
||
let time = null;
|
||
$(function () {
|
||
// debug
|
||
if (EnvCheck() == 'test') {
|
||
new VConsole();
|
||
}
|
||
setTimeout(function () {
|
||
getData();
|
||
}, 30)
|
||
|
||
|
||
// 初始化接口
|
||
function getData() {
|
||
networkRequest({
|
||
type: 'GET',
|
||
url: urlPrefix + '/activity/fortune/getUserFortuneInfo',
|
||
data: {
|
||
uid: pubInfo.uid,
|
||
},
|
||
success: function (res) {
|
||
if (res.code == 200) {
|
||
getDataArr = res.data;
|
||
// console.log(getDataArr)
|
||
drawDegree = res.data.awardNum;
|
||
console.log(drawDegree);
|
||
if (res.timestamp < res.data.collectStartTime) {
|
||
$('.foca_boxOut').css({ display: 'block' });
|
||
$('.foca_card .card .card_number').css({ display: 'none' });
|
||
getDataStyle(getDataArr, res);
|
||
console.log('活动未开始')
|
||
} else {
|
||
$('.foca_boxOut').css({ display: 'none' });
|
||
$('.foca_card .card .card_number').css({ display: 'block' });
|
||
getDataStyle(getDataArr, res)
|
||
countTime()
|
||
}
|
||
}
|
||
},
|
||
error: function (res) {
|
||
console.log(res, '报错啦');
|
||
}
|
||
})
|
||
}
|
||
function getDataStyle(data, res) {
|
||
// 判断状态
|
||
// getDataArr.drawStatus = 1;
|
||
if (res.timestamp < res.data.collectStartTime) {
|
||
focaBoxFun('none', 'none', 'none', 'none', 'none');
|
||
} else {
|
||
if (getDataArr.drawStatus == undoneStatus) {
|
||
focaBoxFun('block', 'none', 'none', 'none', 'none');
|
||
} else if (getDataArr.drawStatus == OutTimeStatus) {
|
||
focaBoxFun('none', 'block', 'none', 'none', 'none');
|
||
$('.foca_box1 .foca_text b').text(getDataArr.awardNum)//已获得领取次数
|
||
} else if (getDataArr.drawStatus == lotteryStatus) {
|
||
focaBoxFun('none', 'none', 'block', 'none', 'none');
|
||
$('.foca_box3 .foca_last b').text(getDataArr.allGold)//设置瓜分总金币
|
||
$(' .foca_box3 .foca_text b').text(getDataArr.awardNum)//剩余领取次数
|
||
if (getDataArr.awardNum == 0) {
|
||
$('.foca_box3 .foca_but').css({ "background": "url(./image/failBut.png) no-repeat", "background-size": "100%" })
|
||
}
|
||
} else if (getDataArr.drawStatus == outLotteryStatus) {
|
||
focaBoxFun('none', 'none', 'none', 'block', 'none');
|
||
}
|
||
}
|
||
// 头饰和座驾
|
||
$('.headwearTop .top img').attr('src', data.headUrl);
|
||
$('.headwearBottom .top img').attr('src', data.carUrl);
|
||
// 福卡数量
|
||
data.prizeList.forEach((res, index) => {
|
||
$('.foca .foca_card .card').children('div')[index].innerText = res.prizeNum;
|
||
});
|
||
// 集卡人数
|
||
$('.title_people b').text(data.peopleNum);
|
||
|
||
}
|
||
|
||
// 点击领取事件
|
||
let status = true;
|
||
$('.foca_box3 .foca_but').click(function () {
|
||
console.log(drawDegreeArr)
|
||
console.log('剩余次数:' + drawDegree);
|
||
$('.foca_box3 .foca_text b').text(drawDegree)//剩余瓜分次数
|
||
if (drawDegree > 0) {
|
||
if (getDataArr.awardNum > 0) {
|
||
if (status) {
|
||
status = false;
|
||
networkRequest({
|
||
type: 'post',
|
||
url: urlPrefix + '/activity/fortune/receiveAward',
|
||
data: {
|
||
uid: pubInfo.uid,
|
||
ticket: pubInfo.ticket,
|
||
},
|
||
success: function (res) {
|
||
if (res.code == 200) {
|
||
console.log(res.data)
|
||
drawDegreeArr = res.data;
|
||
drawDegree = res.data.awardNum;
|
||
awardAfterFun(res.data);
|
||
if (res.data.awardNum == 0) {
|
||
$('.foca_box3 .foca_but').css({ background: 'url(./image/failBut.png) no-repeat', 'background-size': "100% 100%" })
|
||
}
|
||
status = true;
|
||
} else if (res.code == 10007) {
|
||
window.location.reload();
|
||
}
|
||
},
|
||
error: function (res) {
|
||
status = true;
|
||
console.log(res, '报错啦');
|
||
}
|
||
})
|
||
} else {
|
||
console.log('还没请求完')
|
||
}
|
||
|
||
} else {
|
||
focaBoxFun('none', 'none', 'none', 'block', 'none');
|
||
}
|
||
} else {
|
||
console.log(drawDegreeArr)
|
||
$('.foca_box3 .foca_but').css({ background: 'url(./image/failBut.png) no-repeat', 'background-size': "100% 100%" })
|
||
console.log('剩余瓜分次数不足')
|
||
}
|
||
})
|
||
// 弹窗关闭按钮
|
||
$('.pop_up .pop_up_box img').click(function () {
|
||
$('.pop_up').css({ display: "none" })
|
||
})
|
||
// 倒计时
|
||
function countTime() {
|
||
//获取当前时间
|
||
var date = new Date();
|
||
var now = date.getTime();
|
||
//设置截止时间
|
||
var end = getDataArr.collectEndTime; //结束时间;
|
||
|
||
//时间差
|
||
var leftTime = end - now;
|
||
// console.log(leftTime)
|
||
//定义变量 d,h,m,s保存倒计时的时间
|
||
var d, h, m, s;
|
||
if (leftTime >= 0) {
|
||
d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
|
||
h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
|
||
m = Math.floor(leftTime / 1000 / 60 % 60);
|
||
s = Math.floor(leftTime / 1000 % 60);
|
||
}
|
||
//将倒计时赋值到div中
|
||
if (leftTime > 0) {
|
||
if (getDataArr.drawStatus == undoneStatus) {
|
||
$('.foca_box .dd').text(d)
|
||
$('.foca_box .hh').text(h)
|
||
$('.foca_box .mm').text(m)
|
||
$('.foca_box .ss').text(s)
|
||
} else if (getDataArr.drawStatus == OutTimeStatus) {
|
||
$('.foca_box1 .dd').text(d)
|
||
$('.foca_box1 .hh').text(h)
|
||
$('.foca_box1 .mm').text(m)
|
||
$('.foca_box1 .ss').text(s)
|
||
}
|
||
console.log('倒计时中')
|
||
// startTime++;
|
||
} else if (leftTime <= 0) {
|
||
console.log(leftTime);
|
||
console.log('倒计时结束');
|
||
// window.location.reload();//刷新当前页面
|
||
clearInterval(time);
|
||
|
||
// if (getDataArr.awardNum == 0) {
|
||
// focaBoxFun('none', 'none', 'none', 'block', 'none');
|
||
// } else
|
||
if (getDataArr.awardNum != 0 && getDataArr.drawStatus == OutTimeStatus) {
|
||
$('.foca_text b').text(getDataArr.awardNum);
|
||
focaBoxFun('none', 'none', 'none', 'none', 'block');
|
||
} else if (getDataArr.awardNum != 0 && getDataArr.drawStatus == lotteryStatus) {
|
||
$('.foca_text b').text(getDataArr.awardNum);
|
||
focaBoxFun('none', 'none', 'block', 'none', 'none');
|
||
}
|
||
|
||
return;
|
||
}
|
||
//递归每秒调用countTime方法,显示动态时间效果
|
||
time = setTimeout(countTime, 1000);
|
||
}
|
||
// 点击领取后的处理
|
||
function awardAfterFun(data) {
|
||
$('.pop_up .pop_up_box span').text(data.activeGold + '鉆石');//当前瓜分金币数量
|
||
$('.foca_box3 .foca_last b').text(data.allGold);//瓜分后的总金币数
|
||
$('.foca_box3 .foca_text b').text(data.awardNum)//剩余瓜分次数
|
||
$('.pop_up').css({ display: "block" })
|
||
}
|
||
// 福卡样式
|
||
function focaBoxFun(value, value1, value3, value4, value11) {
|
||
$('.foca_box').css({ display: value });
|
||
$('.foca_box1').css({ display: value1 });
|
||
$('.foca_box11').css({ display: value11 });
|
||
// $('.foca_box2').css({ display: value2 });
|
||
$('.foca_box3').css({ display: value3 });
|
||
$('.foca_box4').css({ display: value4 });
|
||
}
|
||
}) |