东风启辰小程序端
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.

rotaryDraw.js 6.3KB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. this.data.ani[that].recordText = "恭喜"+this.data.recordDataAll[this.data.recordNowNum].nickName+"获得"+this.data.recordDataAll[this.data.recordNowNum].awardName;
  118. if(this.data.recordNowNum+1<this.data.recordDataAll.length){
  119. this.data.recordNowNum++;
  120. }else{
  121. this.data.recordNowNum=0;
  122. }
  123. }
  124. this.setData({
  125. ani: this.data.ani
  126. })
  127. if(loop){
  128. setTimeout(()=>{
  129. this.aniFun(0,"152rpx",that,false);
  130. setTimeout(()=>{
  131. this.aniFun(duration,"-40rpx",that);
  132. },50)
  133. },duration);
  134. }
  135. },
  136. startDraw(){//开始抽奖
  137. // this.drawAniFun(3000,660);
  138. // return;
  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. // res.data.lucky = true;
  167. // res.data.awardData = {};
  168. // res.data.awardData.awardId = 19
  169. if(res.data.lucky){
  170. let timeNum = 0;
  171. let timeRotate = 0;
  172. if(res.data.awardData.awardId==19){
  173. timeNum = 3500;
  174. timeRotate = 420;
  175. }else if(res.data.awardData.awardId==20){
  176. timeNum = 4000;
  177. timeRotate = 480;
  178. }else if(res.data.awardData.awardId==23){
  179. timeNum = 5000;
  180. timeRotate = 600;
  181. }
  182. this.drawAniFun(timeNum,timeRotate);
  183. setTimeout(() => {
  184. this.setData({
  185. awardId:res.data.awardData.awardId
  186. })
  187. }, timeNum+400);
  188. }else{
  189. //1 0.12
  190. this.drawAniFun(5500,660);
  191. setTimeout(() => {
  192. btnOpen = false;
  193. this.prizeControl2();
  194. }, 6600+400);
  195. }
  196. console.log(app.globalData.luckyTokenList);
  197. }else{
  198. btnOpen = false;
  199. wx.showToast({
  200. title: res.msg,
  201. icon:"none"
  202. })
  203. }
  204. }, this)
  205. },
  206. prizeControl2(){//控制获奖弹窗显示状态
  207. this.setData({
  208. prizeShow2:!this.data.prizeShow2
  209. })
  210. },
  211. backPage(){
  212. wx.navigateBack({
  213. delta:1
  214. })
  215. },
  216. addressControl(){//立即领取
  217. this.setData({
  218. addressShow: !this.data.addressShow
  219. })
  220. if (this.data.addressShow) {
  221. app.globalData.skipType = 'mycenter';
  222. }
  223. },
  224. getAddress: function () {//获取地址
  225. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  226. if (res.code == 200) {
  227. if (res.data) {
  228. this.setData({
  229. isAddress:true
  230. })
  231. }
  232. }
  233. }, this)
  234. },
  235. getLuckyTokenList() {
  236. this.wxRequest(app.globalData.urlRoot + "wxPay/v3/getLuckyTokenList", {}, res => {
  237. if (res.code == 200) {
  238. if (res.data) {
  239. res.data.cdate = res.data.cdate ? res.data.cdate : "";
  240. app.globalData.getBuyState = res.data;
  241. if (res.data.luckyTokenList) {
  242. app.globalData.luckyTokenList = res.data.luckyTokenList;
  243. }
  244. }
  245. }
  246. }, this);
  247. }
  248. })