|
- // pages/rotaryDraw/rotaryDraw.js
- const app = getApp()
- let timekeeping = true;
- let dataList = [
- {awardName:"华为P40",nickName:"啦啦啦"},
- {awardName:"小米扫拖机器人",nickName:"啦啦啦"},
- {awardName:"小米空调",nickName:"啦啦啦"},
- {awardName:"九阳破壁机",nickName:"啦啦啦"},
- {awardName:"USMILE电动牙刷",nickName:"啦啦啦"},
- ]
- let btnOpen = false;//是否正在抽奖
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- imgUrl: app.globalData.urlStatic,//图片路径
- recordDataAll:[],//所有数据
- recordNowNum:0,//当前数据
- totalNum:0,//数据总数
- ani:{
- ani1:null,
- ani2:null,
- ani3:null,
- ani4:null
- },
- page:1,
- count:20,
- drawAni:null,
- prizeShow2:false,//是否显示未中奖
- awardId:0,//中奖id
- addressShow:false,
- isAddress:false,//是否有地址
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (app.globalData.openid) {
- this.loadFun();
- } else {
- app.globalData.openidSuccessFuc = this.loadFun;
- }
- },
- loadFun() {
- this.getLuckyTokenList();
- this.getRecordData();
- this.getAddress();
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- timekeeping = false;
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return app.sharePack();
- },
- getRecordData(){//获取中将记录数据
- app.wxRequest(app.globalData.urlRoot + "award/getGameAwardList", {page:this.data.page,count:this.data.count,awardSource:4}, 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){
- timekeeping = true;
- for(let i=1;i<=4;i++){
- setTimeout(()=>{
- this.aniFun(4000,"-40rpx","ani"+i);
- },(i-1)*1000);
- }
- }
- }
- }, this)
- },
- aniFun(duration,top,that,loop = true){
- if(!timekeeping) return;
- 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].awardName;
- 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(3000,660);
- // return;
- if(!app.globalData.luckyTokenList.length){
- wx.showToast({
- title: '抽奖次数不足',
- icon:"none"
- })
- return;
- }
- if(btnOpen){
- return;
- }
- btnOpen=true;
- this.getLucky();
- },
- drawAniFun(duration,rotate,loop=true){
- var animation = wx.createAnimation({
- duration: duration
- });
- animation.rotate(rotate).step();
- this.setData({
- drawAni:animation.export()
- })
- },
- getLucky(){
- app.wxRequest(app.globalData.urlRoot + "wxPay/v3/getLucky", {token:app.globalData.luckyTokenList[0].token}, res => {
- console.log(res);
- if (res.code == 200) {
- app.globalData.luckyTokenList.splice(0,1);
- // res.data.lucky = true;
- // res.data.awardData = {};
- // res.data.awardData.awardId = 19
- if(res.data.lucky){
- let timeNum = 0;
- let timeRotate = 0;
- if(res.data.awardData.awardId==19){
- timeNum = 3500;
- timeRotate = 420;
- }else if(res.data.awardData.awardId==20){
- timeNum = 4000;
- timeRotate = 480;
- }else if(res.data.awardData.awardId==23){
- timeNum = 5000;
- timeRotate = 600;
- }
- this.drawAniFun(timeNum,timeRotate);
- setTimeout(() => {
- this.setData({
- awardId:res.data.awardData.awardId
- })
- }, timeNum+400);
- }else{
- //1 0.12
- this.drawAniFun(5500,660);
- setTimeout(() => {
- btnOpen = false;
- this.prizeControl2();
- }, 6600+400);
- }
- console.log(app.globalData.luckyTokenList);
- }else{
- btnOpen = false;
- wx.showToast({
- title: res.msg,
- icon:"none"
- })
- }
- }, this)
- },
- prizeControl2(){//控制获奖弹窗显示状态
- this.setData({
- prizeShow2:!this.data.prizeShow2
- })
- },
- backPage(){
- wx.navigateBack({
- delta:1
- })
- },
- addressControl(){//立即领取
- this.setData({
- addressShow: !this.data.addressShow
- })
- if (this.data.addressShow) {
- app.globalData.skipType = 'mycenter';
- }
- },
- getAddress: function () {//获取地址
- app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
- if (res.code == 200) {
- if (res.data) {
- this.setData({
- isAddress:true
- })
- }
- }
- }, this)
- },
- getLuckyTokenList() {
- this.wxRequest(app.globalData.urlRoot + "wxPay/v3/getLuckyTokenList", {}, res => {
- if (res.code == 200) {
- if (res.data) {
- res.data.cdate = res.data.cdate ? res.data.cdate : "";
- app.globalData.getBuyState = res.data;
- if (res.data.luckyTokenList) {
- app.globalData.luckyTokenList = res.data.luckyTokenList;
- }
- }
- }
- }, this);
- }
- })
|