|
- // pages/rotaryDraw/rotaryDraw.js
- const app = getApp()
- let dataList = [
- {prizeName:"华为P40",nickName:"啦啦啦"},
- {prizeName:"小米扫拖机器人",nickName:"啦啦啦"},
- {prizeName:"小米空调",nickName:"啦啦啦"},
- {prizeName:"九阳破壁机",nickName:"啦啦啦"},
- {prizeName:"USMILE电动牙刷",nickName:"啦啦啦"},
- ]
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- imgUrl: app.globalData.urlStatic,//图片路径
- recordDataAll:[],//所有数据
- recordNowNum:0,//当前数据
- totalNum:0,//数据总数
- ani:{
- ani1:null,
- ani2:null,
- ani3:null,
- ani4:null
- },
- page:1,
- count:5,
- drawAni:null
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (app.globalData.openid) {
- this.loadFun();
- } else {
- app.globalData.openidSuccessFuc = this.loadFun;
- }
- },
- loadFun() {
- // this.getRecordData();
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return app.sharePack();
- },
- getRecordData(){//获取中将记录数据
- return;
- app.wxRequest(app.globalData.urlRoot + "", {}, res => {
- if (res.code == 200 && res.data) {
- this.data.totalNum = res.total;
- for(let i=0;i<res.data.length;i++){
- this.data.recordDataAll.push(res.data[i]);
- }
- if(this.data.page==1){
- for(let i=1;i<=4;i++){
- setTimeout(()=>{
- this.aniFun(4000,"-40rpx","ani"+i);
- },(i-1)*1000);
- }
- }
- }
- }, this)
- },
- aniFun(duration,top,that,loop = true){
- var animation = wx.createAnimation({
- duration: duration
- });
- animation.top(top).step();
- this.data.ani[that] = animation.export();
- if(loop){
- if(this.data.page*this.data.count-4<=this.data.recordNowNum && this.data.recordNowNum<this.data.total){
- this.data.page++;
- this.getRecordData();
- }
- this.data.ani[that].recordText = "恭喜"+this.data.recordDataAll[this.data.recordNowNum].nickName+"获得"+this.data.recordDataAll[this.data.recordNowNum].prizeName;
- if(this.data.recordNowNum+1<this.data.recordDataAll.length){
- this.data.recordNowNum++;
- }else{
- this.data.recordNowNum=0;
- }
- }
- this.setData({
- ani: this.data.ani
- })
- if(loop){
- setTimeout(()=>{
- this.aniFun(0,"152rpx",that,false);
- setTimeout(()=>{
- this.aniFun(duration,"-40rpx",that);
- },50)
- },duration);
- }
- },
- startDraw(){//开始抽奖
- this.drawAniFun(2000,360);
- },
- drawAniFun(duration,rotate,loop=true){
- var animation = wx.createAnimation({
- duration: duration
- });
- animation.rotate(rotate).step();
- this.setData({
- drawAni:animation.export()
- })
- if(loop){
- setTimeout(()=>{
- this.drawAniFun(2000,rotate+360);
- },duration)
- }
- }
- })
|