东风启辰小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
3.4KB

  1. // pages/rotaryDraw/rotaryDraw.js
  2. const app = getApp()
  3. let dataList = [
  4. {prizeName:"华为P40",nickName:"啦啦啦"},
  5. {prizeName:"小米扫拖机器人",nickName:"啦啦啦"},
  6. {prizeName:"小米空调",nickName:"啦啦啦"},
  7. {prizeName:"九阳破壁机",nickName:"啦啦啦"},
  8. {prizeName:"USMILE电动牙刷",nickName:"啦啦啦"},
  9. ]
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. imgUrl: app.globalData.urlStatic,//图片路径
  16. recordDataAll:[],//所有数据
  17. recordNowNum:0,//当前数据
  18. totalNum:0,//数据总数
  19. ani:{
  20. ani1:null,
  21. ani2:null,
  22. ani3:null,
  23. ani4:null
  24. },
  25. page:1,
  26. count:5,
  27. drawAni:null
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. if (app.globalData.openid) {
  34. this.loadFun();
  35. } else {
  36. app.globalData.openidSuccessFuc = this.loadFun;
  37. }
  38. },
  39. loadFun() {
  40. // this.getRecordData();
  41. },
  42. /**
  43. * 生命周期函数--监听页面初次渲染完成
  44. */
  45. onReady: function () {
  46. },
  47. /**
  48. * 生命周期函数--监听页面显示
  49. */
  50. onShow: function () {
  51. },
  52. /**
  53. * 生命周期函数--监听页面隐藏
  54. */
  55. onHide: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面卸载
  59. */
  60. onUnload: function () {
  61. },
  62. /**
  63. * 页面相关事件处理函数--监听用户下拉动作
  64. */
  65. onPullDownRefresh: function () {
  66. },
  67. /**
  68. * 页面上拉触底事件的处理函数
  69. */
  70. onReachBottom: function () {
  71. },
  72. /**
  73. * 用户点击右上角分享
  74. */
  75. onShareAppMessage: function () {
  76. return app.sharePack();
  77. },
  78. getRecordData(){//获取中将记录数据
  79. return;
  80. app.wxRequest(app.globalData.urlRoot + "", {}, res => {
  81. if (res.code == 200 && res.data) {
  82. this.data.totalNum = res.total;
  83. for(let i=0;i<res.data.length;i++){
  84. this.data.recordDataAll.push(res.data[i]);
  85. }
  86. if(this.data.page==1){
  87. for(let i=1;i<=4;i++){
  88. setTimeout(()=>{
  89. this.aniFun(4000,"-40rpx","ani"+i);
  90. },(i-1)*1000);
  91. }
  92. }
  93. }
  94. }, this)
  95. },
  96. aniFun(duration,top,that,loop = true){
  97. var animation = wx.createAnimation({
  98. duration: duration
  99. });
  100. animation.top(top).step();
  101. this.data.ani[that] = animation.export();
  102. if(loop){
  103. if(this.data.page*this.data.count-4<=this.data.recordNowNum && this.data.recordNowNum<this.data.total){
  104. this.data.page++;
  105. this.getRecordData();
  106. }
  107. this.data.ani[that].recordText = "恭喜"+this.data.recordDataAll[this.data.recordNowNum].nickName+"获得"+this.data.recordDataAll[this.data.recordNowNum].prizeName;
  108. if(this.data.recordNowNum+1<this.data.recordDataAll.length){
  109. this.data.recordNowNum++;
  110. }else{
  111. this.data.recordNowNum=0;
  112. }
  113. }
  114. this.setData({
  115. ani: this.data.ani
  116. })
  117. if(loop){
  118. setTimeout(()=>{
  119. this.aniFun(0,"152rpx",that,false);
  120. setTimeout(()=>{
  121. this.aniFun(duration,"-40rpx",that);
  122. },50)
  123. },duration);
  124. }
  125. },
  126. startDraw(){//开始抽奖
  127. this.drawAniFun(2000,360);
  128. },
  129. drawAniFun(duration,rotate,loop=true){
  130. var animation = wx.createAnimation({
  131. duration: duration
  132. });
  133. animation.rotate(rotate).step();
  134. this.setData({
  135. drawAni:animation.export()
  136. })
  137. if(loop){
  138. setTimeout(()=>{
  139. this.drawAniFun(2000,rotate+360);
  140. },duration)
  141. }
  142. }
  143. })