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

269 lines
6.5KB

  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.globalData.luckyTokenList.splice(0, 1);
  163. // this.drawAniFun(5500, 660);
  164. // setTimeout(() => {
  165. // btnOpen = false;
  166. // this.prizeControl2();
  167. // }, 5500 + 400);
  168. // return;
  169. app.wxRequest(app.globalData.urlRoot + "wxPay/v3/getLucky", {token:app.globalData.luckyTokenList[0].token}, res => {
  170. console.log(res);
  171. if (res.code == 200) {
  172. app.globalData.luckyTokenList.splice(0,1);
  173. // res.data.lucky = true;
  174. // res.data.awardData = {};
  175. // res.data.awardData.awardId = 19
  176. if(res.data.lucky){
  177. let timeNum = 0;
  178. let timeRotate = 0;
  179. if(res.data.awardData.awardId==19){
  180. timeNum = 3500;
  181. timeRotate = 420;
  182. }else if(res.data.awardData.awardId==20){
  183. timeNum = 4000;
  184. timeRotate = 480;
  185. }else if(res.data.awardData.awardId==23){
  186. timeNum = 5000;
  187. timeRotate = 600;
  188. }
  189. this.drawAniFun(timeNum,timeRotate);
  190. setTimeout(() => {
  191. this.setData({
  192. awardId:res.data.awardData.awardId
  193. })
  194. }, timeNum+400);
  195. }else{
  196. //1 0.12
  197. this.drawAniFun(5500,660);
  198. setTimeout(() => {
  199. btnOpen = false;
  200. this.prizeControl2();
  201. }, 5500+400);
  202. }
  203. console.log(app.globalData.luckyTokenList);
  204. }else{
  205. btnOpen = false;
  206. wx.showToast({
  207. title: res.msg,
  208. icon:"none"
  209. })
  210. }
  211. }, this)
  212. },
  213. prizeControl2(){//控制获奖弹窗显示状态
  214. this.setData({
  215. prizeShow2:!this.data.prizeShow2
  216. })
  217. },
  218. backPage(){
  219. wx.navigateBack({
  220. delta:1
  221. })
  222. },
  223. addressControl(){//立即领取
  224. this.setData({
  225. addressShow: !this.data.addressShow
  226. })
  227. if (this.data.addressShow) {
  228. app.globalData.skipType = 'mycenter';
  229. }
  230. },
  231. getAddress: function () {//获取地址
  232. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  233. if (res.code == 200) {
  234. if (res.data) {
  235. this.setData({
  236. isAddress:true
  237. })
  238. }
  239. }
  240. }, this)
  241. },
  242. getLuckyTokenList() {
  243. app.wxRequest(app.globalData.urlRoot + "wxPay/v3/getLuckyTokenList", {}, res => {
  244. if (res.code == 200) {
  245. if (res.data) {
  246. res.data.cdate = res.data.cdate ? res.data.cdate : "";
  247. app.globalData.getBuyState = res.data;
  248. if (res.data.luckyTokenList) {
  249. app.globalData.luckyTokenList = res.data.luckyTokenList;
  250. }
  251. }
  252. }
  253. }, this);
  254. }
  255. })