
js
Page({
data: {
last_index: 0,//上一回滚动的位置
amplification_index: 0,//轮盘的当前滚动位置
roll_flag: true,//是否允许滚动
max_number: 8,//轮盘的全部数量
speed: 300,//速度,速度值越大,则越慢 初始化为300
finalindex: 5,//最终的奖励距离当前的位置!不是最后的几等奖!
myInterval: "",//定时器
max_speed: 40,//滚盘的最大速度
minturns: 8,//最小的圈数为2
runs_now: 0,//当前已跑步数
luck_num: 3, //获得的奖项的位置
end_amp:0, //上一次滚动的位置
start_flag:true,
lucks: ['积分+5', '谢谢参与', '积分+10', '谢谢参与', '50元卡券', '100元卡券', '谢谢参与', '积分+20'],
},
//开始滚动
startrolling: function () {
let _this = this;
if (this.data.start_flag==true){
_this.setData({
start_flag: false
})
//初始化步数
_this.data.runs_now = 0;
//当前可以点击的状态下
if (_this.data.roll_flag) {
_this.data.roll_flag = false;
//启动滚盘,
_this.rolling();
}
}
},
//滚动轮盘的动画效果
rolling: function (amplification_index) {
var _this = this;
this.data.myInterval = setTimeout(function () { _this.rolling(); }, this.data.speed);
this.data.runs_now++;//已经跑步数加一
this.data.amplification_index++;//当前的加一
//获取总步数,接口延迟问题,所以最后还是设置成1s以上
// var count_num = this.data.minturns * this.data.max_number + this.data.finalindex - this.data.last_index;
var count_num = this.data.minturns * this.data.max_number + this.data.luck_num - this.data.end_amp;
//上升期间
if (this.data.runs_now <=