|
|
const app = getApp()
|
|
|
let timer;
|
|
|
let cjIn = false;
|
|
|
let cjChange = 0; //抽奖过程KEY
|
|
|
var interval = null;
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
prizeList: [{
|
|
|
id: '001',
|
|
|
index: 1,
|
|
|
imgsrc: '/images/shoubiao.png',
|
|
|
prizeName: '奖品名称111'
|
|
|
},
|
|
|
{
|
|
|
id: '002',
|
|
|
index: 2,
|
|
|
imgsrc: '/images/shoubiao.png',
|
|
|
prizeName: '奖品名称222'
|
|
|
},
|
|
|
{
|
|
|
id: '003',
|
|
|
index: 3,
|
|
|
imgsrc: '/images/shoubiao.png',
|
|
|
prizeName: '奖品名称333'
|
|
|
},
|
|
|
{
|
|
|
id: '004',
|
|
|
index: 4,
|
|
|
imgsrc: '/images/shoubiao.png',
|
|
|
prizeName: '奖品名称444'
|
|
|
},
|
|
|
{
|
|
|
id: '005',
|
|
|
index: 5,
|
|
|
imgsrc: '/images/shoubiao.png',
|
|
|
prizeName: '奖品名称555'
|
|
|
},
|
|
|
{
|
|
|
id: '006',
|
|
|
index: 6,
|
|
|
imgsrc: '/images/shoubiao.png',
|
|
|
prizeName: '奖品名称666'
|
|
|
},
|
|
|
{
|
|
|
id: '007',
|
|
|
index: 7,
|
|
|
imgsrc: '/images/shoubiao.png',
|
|
|
prizeName: '奖品名称777'
|
|
|
},
|
|
|
{
|
|
|
id: '008',
|
|
|
index: 8,
|
|
|
imgsrc: '/images/shoubiao.png',
|
|
|
prizeName: '奖品名称88888888888888'
|
|
|
},
|
|
|
],
|
|
|
|
|
|
cjChange: null, //抽奖过程KEY
|
|
|
prizeResult: null, //抽奖结果KEY
|
|
|
prizeName: null, //抽奖结果KEY对应的奖品名称
|
|
|
|
|
|
showAgain: false, //是否抽奖后显示再抽一次按钮
|
|
|
choujiang: false,
|
|
|
listzhong: [],
|
|
|
residue_total: '',
|
|
|
days: '',
|
|
|
hours: '',
|
|
|
minutes: '',
|
|
|
seconds: '',
|
|
|
beginchou: true,
|
|
|
text: ''
|
|
|
|
|
|
},
|
|
|
|
|
|
// 获取信息
|
|
|
getinfo() {
|
|
|
let that = this;
|
|
|
let url = '/gift/get_setting'
|
|
|
let params = {
|
|
|
|
|
|
}
|
|
|
app.post(url, params).then((res) => {
|
|
|
console.log(res, 373784478)
|
|
|
that.setData({
|
|
|
residue_total: res.msg.residue_total
|
|
|
})
|
|
|
if (res.msg.residue_time == 0) {
|
|
|
that.setData({
|
|
|
beginchou: false
|
|
|
})
|
|
|
}
|
|
|
|
|
|
|
|
|
var totalSecond = res.msg.residue_time;
|
|
|
// var totalSecond = r.countdown;
|
|
|
interval = setInterval(function () {
|
|
|
// 秒数
|
|
|
var second = totalSecond;
|
|
|
|
|
|
// 天数位
|
|
|
var day = Math.floor(second / 3600 / 24);
|
|
|
var dayStr = day.toString();
|
|
|
if (dayStr.length == 1) dayStr = '0' + dayStr;
|
|
|
// 小时位
|
|
|
var hr = Math.floor((second - day * 3600 * 24) / 3600);
|
|
|
var hrStr = hr.toString();
|
|
|
if (hrStr.length == 1) hrStr = '0' + hrStr;
|
|
|
// 分钟位
|
|
|
var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60);
|
|
|
var minStr = min.toString();
|
|
|
if (minStr.length == 1) minStr = '0' + minStr;
|
|
|
// 秒位
|
|
|
var sec = second - day * 3600 * 24 - hr * 3600 - min * 60;
|
|
|
var secStr = sec.toString();
|
|
|
if (secStr.length == 1) secStr = '0' + secStr;
|
|
|
that.setData({
|
|
|
days: dayStr,
|
|
|
hours: hrStr,
|
|
|
minutes: minStr,
|
|
|
seconds: secStr,
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
totalSecond--;
|
|
|
if (totalSecond <= 0) {
|
|
|
clearInterval(interval);
|
|
|
// uni.showToast({
|
|
|
// title: '活动已结束',
|
|
|
// icon: 'none'
|
|
|
// });
|
|
|
// 倒计时结束
|
|
|
//that.countDown();
|
|
|
that.setData({
|
|
|
days: "00",
|
|
|
hours: "00",
|
|
|
minutes: "00",
|
|
|
seconds: "00",
|
|
|
beginchou: false
|
|
|
// endactive:true
|
|
|
})
|
|
|
}
|
|
|
}.bind(this), 1000);
|
|
|
})
|
|
|
},
|
|
|
// 开始抽奖
|
|
|
startchou() {
|
|
|
wx.showToast({
|
|
|
title: '抽奖还未开始,敬请期待',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
},
|
|
|
// 活动规则
|
|
|
guize() {
|
|
|
wx.navigateTo({
|
|
|
url: '/packageA/pages/rule/rule',
|
|
|
})
|
|
|
},
|
|
|
// 中奖纪录
|
|
|
zhongjilu() {
|
|
|
wx.navigateTo({
|
|
|
url: '/packageA/pages/record/record',
|
|
|
})
|
|
|
},
|
|
|
|
|
|
// 获取礼物的接口
|
|
|
getpresent() {
|
|
|
let that = this;
|
|
|
let url = '/gift/get_gift'
|
|
|
let params = {
|
|
|
|
|
|
}
|
|
|
app.post(url, params).then((res) => {
|
|
|
console.log(res)
|
|
|
|
|
|
that.setData({
|
|
|
prizeList: res.msg
|
|
|
})
|
|
|
|
|
|
let newprizeList = that.data.prizeList;
|
|
|
newprizeList.forEach(function (value, index, array) {
|
|
|
value.index = index + 1
|
|
|
})
|
|
|
|
|
|
that.setData({
|
|
|
prizeList: newprizeList
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//抽奖操作
|
|
|
cj() {
|
|
|
console.log(38483484)
|
|
|
// if(cjIn){
|
|
|
// console.log(9999)
|
|
|
// return;
|
|
|
// }else{
|
|
|
// cjIn = true;
|
|
|
// }
|
|
|
|
|
|
let This = this;
|
|
|
This.setData({
|
|
|
// 不能再抽奖
|
|
|
choujiang: true
|
|
|
})
|
|
|
|
|
|
|
|
|
// 获取抽到的礼物
|
|
|
let url = '/gift/extract'
|
|
|
let params = {
|
|
|
|
|
|
}
|
|
|
let res = {}
|
|
|
app.post(url, params).then((res) => {
|
|
|
console.log(res)
|
|
|
This.setData({
|
|
|
text: res
|
|
|
})
|
|
|
|
|
|
let newprizeList = This.data.prizeList;
|
|
|
newprizeList.forEach(function (value, index, array) {
|
|
|
if (value.id == res.msg.id) {
|
|
|
console.log(value)
|
|
|
res = {
|
|
|
stutus: 1,
|
|
|
prizeResult: value.index,
|
|
|
prizeName: value.name,
|
|
|
|
|
|
}
|
|
|
|
|
|
console.log(666554433, res)
|
|
|
if (res.stutus == 1) {
|
|
|
setTimeout(function () {
|
|
|
clearInterval(timer);
|
|
|
timer = setInterval(This.changePrize, 160);
|
|
|
setTimeout(function () {
|
|
|
clearInterval(timer);
|
|
|
timer = setInterval(This.changePrize, 300);
|
|
|
|
|
|
setTimeout(function () {
|
|
|
This.setData({
|
|
|
prizeResult: res.prizeResult,
|
|
|
prizeName: res.prizeName,
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}, 1000)
|
|
|
}, 1000)
|
|
|
}, 2000)
|
|
|
|
|
|
cjIn = false;
|
|
|
cjChange = 0; //抽奖过程KEY
|
|
|
|
|
|
|
|
|
This.setData({
|
|
|
cjChange: null, //抽奖过程KEY
|
|
|
prizeResult: null, //抽奖结果KEY
|
|
|
prizeName: null, //抽奖结果KEY对应的奖品名称
|
|
|
showAgain: false, //是否抽奖后显示再抽一次按钮
|
|
|
});
|
|
|
}
|
|
|
clearInterval(timer);
|
|
|
timer = setInterval(This.changePrize, 80);
|
|
|
|
|
|
}
|
|
|
})
|
|
|
}).catch((err) => {
|
|
|
console.log(err)
|
|
|
This.setData({
|
|
|
// 可再次抽奖
|
|
|
choujiang: false,
|
|
|
cjIn: false
|
|
|
})
|
|
|
console.log(This.data.choujiang)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// test start
|
|
|
// res = {
|
|
|
// stutus:1,
|
|
|
// prizeResult:1,
|
|
|
// prizeName:'奖品名称88888888888888',
|
|
|
|
|
|
// }
|
|
|
// console.log(999999,res)
|
|
|
|
|
|
// test end
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
//抽奖过程奖品切换
|
|
|
changePrize() {
|
|
|
cjChange++;
|
|
|
cjChange = cjChange > 8 ? 1 : cjChange;
|
|
|
|
|
|
let This = this;
|
|
|
This.setData({
|
|
|
cjChange: cjChange
|
|
|
});
|
|
|
|
|
|
if (This.data.prizeResult == cjChange) {
|
|
|
clearInterval(timer);
|
|
|
This.setData({
|
|
|
showAgain: true,
|
|
|
// 可以再次抽奖
|
|
|
choujiang: false
|
|
|
});
|
|
|
if (This.data.text.msg.id == 8) {
|
|
|
wx.showToast({
|
|
|
title: '很遗憾,您没有中奖~',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
title: '恭喜您中了' + text.msg.name + '奖品',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
}
|
|
|
|
|
|
This.getinfo()
|
|
|
This.zhongjianglist()
|
|
|
console.log('获得奖品:' + This.data.prizeName)
|
|
|
}
|
|
|
},
|
|
|
//点击再抽一次按钮
|
|
|
againBtn() {
|
|
|
cjIn = false;
|
|
|
cjChange = 0; //抽奖过程KEY
|
|
|
|
|
|
let This = this;
|
|
|
This.setData({
|
|
|
cjChange: null, //抽奖过程KEY
|
|
|
prizeResult: null, //抽奖结果KEY
|
|
|
prizeName: null, //抽奖结果KEY对应的奖品名称
|
|
|
showAgain: false, //是否抽奖后显示再抽一次按钮
|
|
|
});
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
onReady: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function () {
|
|
|
this.getpresent();
|
|
|
// 获取中将记录
|
|
|
this.zhongjianglist()
|
|
|
// 获取信息
|
|
|
this.getinfo()
|
|
|
},
|
|
|
// 获取中奖名单
|
|
|
getzhongjianlist() {
|
|
|
|
|
|
let that = this;
|
|
|
|
|
|
let url = '/gift/get_gift_log1'
|
|
|
let params = {
|
|
|
|
|
|
}
|
|
|
console.log(999999999)
|
|
|
app.post(url, params).then((res) => {
|
|
|
console.log(res, 中奖纪录)
|
|
|
|
|
|
|
|
|
})
|
|
|
},
|
|
|
|
|
|
// 获取礼物的接口
|
|
|
zhongjianglist() {
|
|
|
console.log(347883443)
|
|
|
let that = this;
|
|
|
let url = '/gift/get_gift_log1'
|
|
|
let params = {
|
|
|
|
|
|
}
|
|
|
app.post(url, params).then((res) => {
|
|
|
console.log(res)
|
|
|
that.setData({
|
|
|
listzhong: res.msg
|
|
|
})
|
|
|
|
|
|
|
|
|
})
|
|
|
},
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
onHide: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
onUnload: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 用户点击右上角分享
|
|
|
*/
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
}
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|