东风启辰小程序端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

248 lines
5.9KB

  1. // pages/rotaryDraw/rotaryDraw.js
  2. const app = getApp()
  3. let timekeeping = true;
  4. let dataList = [
  5. {awardName:"华为P40",nickName:"啦啦啦"},
  6. {awardName:"小米扫拖机器人",nickName:"啦啦啦"},
  7. {awardName:"小米空调",nickName:"啦啦啦"},
  8. {awardName:"九阳破壁机",nickName:"啦啦啦"},
  9. {awardName:"USMILE电动牙刷",nickName:"啦啦啦"},
  10. ]
  11. let btnOpen = false;//是否正在抽奖
  12. Page({
  13. /**
  14. * 页面的初始数据
  15. */
  16. data: {
  17. imgUrl: app.globalData.urlStatic,//图片路径
  18. recordDataAll:[],//所有数据
  19. recordNowNum:0,//当前数据
  20. totalNum:0,//数据总数
  21. ani:{
  22. ani1:null,
  23. ani2:null,
  24. ani3:null,
  25. ani4:null
  26. },
  27. page:1,
  28. count:20,
  29. drawAni:null,
  30. prizeShow2:false,//是否显示未中奖
  31. awardId:0,//中奖id
  32. addressShow:false,
  33. isAddress:false,//是否有地址
  34. },
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad: function (options) {
  39. if (app.globalData.openid) {
  40. this.loadFun();
  41. } else {
  42. app.globalData.openidSuccessFuc = this.loadFun;
  43. }
  44. },
  45. loadFun() {
  46. this.getRecordData();
  47. this.getAddress();
  48. },
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面显示
  56. */
  57. onShow: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面隐藏
  61. */
  62. onHide: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面卸载
  66. */
  67. onUnload: function () {
  68. timekeeping = false;
  69. },
  70. /**
  71. * 页面相关事件处理函数--监听用户下拉动作
  72. */
  73. onPullDownRefresh: function () {
  74. },
  75. /**
  76. * 页面上拉触底事件的处理函数
  77. */
  78. onReachBottom: function () {
  79. },
  80. /**
  81. * 用户点击右上角分享
  82. */
  83. onShareAppMessage: function () {
  84. return app.sharePack();
  85. },
  86. getRecordData(){//获取中将记录数据
  87. app.wxRequest(app.globalData.urlRoot + "award/getGameAwardList", {page:this.data.page,count:this.data.count,awardSource:4}, res => {
  88. if (res.code == 200 && res.data) {
  89. this.data.totalNum = res.total;
  90. for(let i=0;i<res.data.length;i++){
  91. this.data.recordDataAll.push(res.data[i]);
  92. }
  93. if(this.data.page==1){
  94. timekeeping = true;
  95. for(let i=1;i<=4;i++){
  96. setTimeout(()=>{
  97. this.aniFun(4000,"-40rpx","ani"+i);
  98. },(i-1)*1000);
  99. }
  100. }
  101. }
  102. }, this)
  103. },
  104. aniFun(duration,top,that,loop = true){
  105. if(!timekeeping) return;
  106. var animation = wx.createAnimation({
  107. duration: duration
  108. });
  109. animation.top(top).step();
  110. this.data.ani[that] = animation.export();
  111. if(loop){
  112. if(this.data.page*this.data.count-4<=this.data.recordNowNum && this.data.recordNowNum<this.data.total){
  113. this.data.page++;
  114. this.getRecordData();
  115. }
  116. this.data.ani[that].recordText = "恭喜"+this.data.recordDataAll[this.data.recordNowNum].nickName+"获得"+this.data.recordDataAll[this.data.recordNowNum].awardName;
  117. if(this.data.recordNowNum+1<this.data.recordDataAll.length){
  118. this.data.recordNowNum++;
  119. }else{
  120. this.data.recordNowNum=0;
  121. }
  122. }
  123. this.setData({
  124. ani: this.data.ani
  125. })
  126. if(loop){
  127. setTimeout(()=>{
  128. this.aniFun(0,"152rpx",that,false);
  129. setTimeout(()=>{
  130. this.aniFun(duration,"-40rpx",that);
  131. },50)
  132. },duration);
  133. }
  134. },
  135. startDraw(){//开始抽奖
  136. // this.drawAniFun(5500,660);
  137. // return;
  138. if(!app.globalData.luckyTokenList.length){
  139. wx.showToast({
  140. title: '抽奖次数不足',
  141. icon:"none"
  142. })
  143. return;
  144. }
  145. if(btnOpen){
  146. return;
  147. }
  148. btnOpen=true;
  149. this.getLucky();
  150. },
  151. drawAniFun(duration,rotate,loop=true){
  152. var animation = wx.createAnimation({
  153. duration: duration
  154. });
  155. animation.rotate(rotate).step();
  156. this.setData({
  157. drawAni:animation.export()
  158. })
  159. },
  160. getLucky(){
  161. app.wxRequest(app.globalData.urlRoot + "wxPay/v3/getLucky", {token:app.globalData.luckyTokenList[0].token}, res => {
  162. console.log(res);
  163. if (res.code == 200) {
  164. app.globalData.luckyTokenList.splice(0,1);
  165. // res.data.lucky = true;
  166. // res.data.awardData = {};
  167. // res.data.awardData.awardId = 19
  168. if(res.data.lucky){
  169. let timeNum = 0;
  170. let timeRotate = 0;
  171. if(res.data.awardData.awardId==19){
  172. timeNum = 3500;
  173. timeRotate = 420;
  174. }else if(res.data.awardData.awardId==20){
  175. timeNum = 4000;
  176. timeRotate = 480;
  177. }else if(res.data.awardData.awardId==23){
  178. timeNum = 5000;
  179. timeRotate = 600;
  180. }
  181. this.drawAniFun(timeNum,timeRotate);
  182. setTimeout(() => {
  183. this.setData({
  184. awardId:res.data.awardData.awardId
  185. })
  186. }, timeNum+400);
  187. }else{
  188. //1 0.12
  189. this.drawAniFun(5500,660);
  190. setTimeout(() => {
  191. btnOpen = false;
  192. this.prizeControl2();
  193. }, 6600+400);
  194. }
  195. console.log(app.globalData.luckyTokenList);
  196. }else{
  197. btnOpen = false;
  198. wx.showToast({
  199. title: res.msg,
  200. icon:"none"
  201. })
  202. }
  203. }, this)
  204. },
  205. prizeControl2(){//控制获奖弹窗显示状态
  206. this.setData({
  207. prizeShow2:!this.data.prizeShow2
  208. })
  209. },
  210. backPage(){
  211. wx.navigateBack({
  212. delta:1
  213. })
  214. },
  215. addressControl(){//立即领取
  216. this.setData({
  217. addressShow: !this.data.addressShow
  218. })
  219. if (this.data.addressShow) {
  220. app.globalData.skipType = 'mycenter';
  221. }
  222. },
  223. getAddress: function () {//获取地址
  224. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  225. if (res.code == 200) {
  226. if (res.data) {
  227. this.setData({
  228. isAddress:true
  229. })
  230. }
  231. }
  232. }, this)
  233. }
  234. })