活動(dòng)效果圖.png
/**
* 頁(yè)面的初始數(shù)據(jù)
*/
data: {
curPosition: 0,//當(dāng)前轉(zhuǎn)動(dòng)到的位置
count: 8, // 總共有多少個(gè)位置
myInterval: 0, // 定時(shí)器
speed: 300,//速度捌浩,速度值越大稽犁,則越慢 初始化為300
max_speed: 40, // 滾盤的最大速度
times: 0, // 轉(zhuǎn)動(dòng)次數(shù)
cycle: 5, // 轉(zhuǎn)動(dòng)基本次數(shù):即至少需要轉(zhuǎn)動(dòng)多少次再進(jìn)入抽獎(jiǎng)環(huán)節(jié)
prize: 0, // 中獎(jiǎng)位置
runs_now: 0,//當(dāng)前已跑步數(shù)
last_index:0,//停下來(lái)的中獎(jiǎng)位置
toastHide: true,//彈層是否展示
toastPrize: false,//是否彈出中獎(jiǎng)彈框
isGetPrize: true,//是否中獎(jiǎng)
},
//開始抽獎(jiǎng)
startGame: function(e) {
let _this = this;
_this.data.runs_now = 0;
_this.data.speed = 40;
wx.request({
url: 'test.php', //僅為示例,并非真實(shí)的接口地址
data: {
},
header: {
'content-type': 'application/json' // 默認(rèn)值
},
success (res) {
_this.setData({
prize: parseInt(res.priceType.charAt(1)),
lastNum: res.priceCount
})
_this.startRoll();
}
})
},
//開始抽獎(jiǎng)動(dòng)畫
startRoll: function () {
let _this = this;
_this.data.myInterval = setTimeout(function () { _this.startRoll(); }, _this.data.speed);
const count_num = _this.data.count * _this.data.cycle + _this.data.prize + (_this.data.count - _this.data.last_index);
_this.data.runs_now++;//已經(jīng)跑步數(shù)加一
_this.data.curPosition++;//當(dāng)前的加一
//上升期間
if (_this.data.runs_no <= (count_num/3*2)){
_this.data.speed -= 30;//加速
if (_this.data.speed <= _this.data.max_speed) {
_this.data.speed = _this.data.max_speed;//最高速度為40素跺;
}
}
//抽獎(jiǎng)結(jié)束
else if (_this.data.runs_now >= count_num) {
console.log('cancel')
clearTimeout(_this.data.myInterval);
_this.data.click = true;
_this.data.last_index = _this.data.curPosition;
let timer = setTimeout(function () {
let isGetPrize;
if (_this.data.prize == 7) {
isGetPrize = false
} else {
isGetPrize = true
}
_this.setData({
toastHide: false,
toastPrize: true,
isGetPrize
})
clearTimeout(timer)
}, 500)
}
//下降期間
else if (count_num - _this.data.runs_now <= 10) {
_this.data.speed += 20;
}
//緩沖區(qū)間
else {
_this.data.speed += 10;
if (_this.data.speed >= 100) {
_this.data.speed = 100;//最低速度為100鸟整;
}
}
if (_this.data.curPosition > _this.data.count) {//判定引镊!是否大于最大數(shù)
_this.data.curPosition = 1;
}
_this.setData(_this.data);
},