东风启辰小程序端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

268 lines
6.7KB

  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.getLuckyTokenList();
  47. this.getRecordData();
  48. this.getAddress();
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面隐藏
  62. */
  63. onHide: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面卸载
  67. */
  68. onUnload: function () {
  69. timekeeping = false;
  70. },
  71. /**
  72. * 页面相关事件处理函数--监听用户下拉动作
  73. */
  74. onPullDownRefresh: function () {
  75. },
  76. /**
  77. * 页面上拉触底事件的处理函数
  78. */
  79. onReachBottom: function () {
  80. },
  81. /**
  82. * 用户点击右上角分享
  83. */
  84. onShareAppMessage: function () {
  85. return app.sharePack();
  86. },
  87. getRecordData(){//获取中将记录数据
  88. app.wxRequest(app.globalData.urlRoot + "award/getGameAwardList", {page:this.data.page,count:this.data.count,awardSource:4}, res => {
  89. if (res.code == 200 && res.data) {
  90. this.data.totalNum = res.total;
  91. for(let i=0;i<res.data.length;i++){
  92. this.data.recordDataAll.push(res.data[i]);
  93. }
  94. if(this.data.page==1){
  95. timekeeping = true;
  96. for(let i=1;i<=4;i++){
  97. setTimeout(()=>{
  98. this.aniFun(4000,"-40rpx","ani"+i);
  99. },(i-1)*1000);
  100. }
  101. }
  102. }
  103. }, this)
  104. },
  105. aniFun(duration,top,that,loop = true){
  106. if(!timekeeping) return;
  107. var animation = wx.createAnimation({
  108. duration: duration
  109. });
  110. animation.top(top).step();
  111. this.data.ani[that] = animation.export();
  112. if(loop){
  113. if(this.data.page*this.data.count-4<=this.data.recordNowNum && this.data.recordNowNum<this.data.total){
  114. this.data.page++;
  115. this.getRecordData();
  116. }
  117. if(this.data.recordDataAll && this.data.recordDataAll.length && this.data.recordDataAll[this.data.recordNowNum].awardName){
  118. this.data.ani[that].recordText = "恭喜"+(this.data.recordDataAll[this.data.recordNowNum].nickName || "XXX")+"获得"+this.data.recordDataAll[this.data.recordNowNum].awardName;
  119. if(this.data.recordNowNum+1<this.data.recordDataAll.length){
  120. this.data.recordNowNum++;
  121. }else{
  122. this.data.recordNowNum=0;
  123. }
  124. }
  125. }
  126. this.setData({
  127. ani: this.data.ani
  128. })
  129. if(loop){
  130. setTimeout(()=>{
  131. this.aniFun(0,"152rpx",that,false);
  132. setTimeout(()=>{
  133. this.aniFun(duration,"-40rpx",that);
  134. },50)
  135. },duration);
  136. }
  137. },
  138. startDraw(){//开始抽奖
  139. if(!app.globalData.luckyTokenList.length){
  140. wx.showToast({
  141. title: '抽奖次数不足',
  142. icon:"none"
  143. })
  144. return;
  145. }
  146. if(btnOpen){
  147. return;
  148. }
  149. btnOpen=true;
  150. this.getLucky();
  151. },
  152. drawAniFun(duration,rotate,loop=true){
  153. var animation = wx.createAnimation({
  154. duration: duration
  155. });
  156. animation.rotate(rotate).step();
  157. this.setData({
  158. drawAni:animation.export()
  159. })
  160. },
  161. getLucky(){
  162. app.wxRequest(app.globalData.urlRoot + "wxPay/v3/getLucky", {token:app.globalData.luckyTokenList[0].token}, res => {
  163. console.log(res);
  164. if (res.code == 200) {
  165. app.globalData.luckyTokenList.splice(0,1);
  166. if(res.data.lucky){
  167. let timeNum = 0;
  168. let timeRotate = 0;
  169. if(res.data.awardData.awardId==19){
  170. timeNum = 3500;
  171. timeRotate = 420;
  172. }else if(res.data.awardData.awardId==20){
  173. timeNum = 3833;
  174. timeRotate = 460;
  175. }else if(res.data.awardData.awardId==21){
  176. timeNum = 5500;
  177. timeRotate = 660;
  178. }else if(res.data.awardData.awardId==22){
  179. timeNum = 4500;
  180. timeRotate = 540;
  181. }else if(res.data.awardData.awardId==23){
  182. timeNum = 4833;
  183. timeRotate = 580;
  184. }else if(res.data.awardData.awardId==24){
  185. timeNum = 5166;
  186. timeRotate = 620;
  187. }
  188. this.drawAniFun(timeNum,timeRotate);
  189. setTimeout(() => {
  190. this.setData({
  191. awardId:res.data.awardData.awardId
  192. })
  193. }, timeNum+400);
  194. }else{
  195. //1 0.12
  196. this.drawAniFun(5833,700);
  197. setTimeout(() => {
  198. btnOpen = false;
  199. this.prizeControl2();
  200. }, 5833+400);
  201. }
  202. console.log(app.globalData.luckyTokenList);
  203. }else{
  204. btnOpen = false;
  205. wx.showToast({
  206. title: res.msg,
  207. icon:"none"
  208. })
  209. }
  210. }, this)
  211. },
  212. prizeControl2(){//控制获奖弹窗显示状态
  213. this.setData({
  214. prizeShow2:!this.data.prizeShow2
  215. })
  216. },
  217. backPage(){
  218. wx.navigateBack({
  219. delta:1
  220. })
  221. },
  222. addressControl(){//立即领取
  223. this.setData({
  224. addressShow: !this.data.addressShow
  225. })
  226. if (this.data.addressShow) {
  227. app.globalData.skipType = 'mycenter';
  228. }
  229. },
  230. getAddress: function () {//获取地址
  231. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  232. if (res.code == 200) {
  233. if (res.data) {
  234. this.setData({
  235. isAddress:true
  236. })
  237. }
  238. }
  239. }, this)
  240. },
  241. getLuckyTokenList() {
  242. app.wxRequest(app.globalData.urlRoot + "wxPay/v3/getLuckyTokenList", {}, res => {
  243. if (res.code == 200) {
  244. if (res.data) {
  245. res.data.cdate = res.data.cdate ? res.data.cdate : "";
  246. app.globalData.getBuyState = res.data;
  247. if (res.data.luckyTokenList) {
  248. app.globalData.luckyTokenList = res.data.luckyTokenList;
  249. }
  250. }
  251. }
  252. }, this);
  253. }
  254. })