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

5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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].nickName && this.data.recordDataAll[this.data.recordNowNum].awardName){
  118. this.data.ani[that].recordText = "恭喜"+this.data.recordDataAll[this.data.recordNowNum].nickName+"获得"+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. // this.drawAniFun(3000,660);
  140. // return;
  141. if(!app.globalData.luckyTokenList.length){
  142. wx.showToast({
  143. title: '抽奖次数不足',
  144. icon:"none"
  145. })
  146. return;
  147. }
  148. if(btnOpen){
  149. return;
  150. }
  151. btnOpen=true;
  152. this.getLucky();
  153. },
  154. drawAniFun(duration,rotate,loop=true){
  155. var animation = wx.createAnimation({
  156. duration: duration
  157. });
  158. animation.rotate(rotate).step();
  159. this.setData({
  160. drawAni:animation.export()
  161. })
  162. },
  163. getLucky(){
  164. // app.globalData.luckyTokenList.splice(0, 1);
  165. // this.drawAniFun(5500, 660);
  166. // setTimeout(() => {
  167. // btnOpen = false;
  168. // this.prizeControl2();
  169. // }, 5500 + 400);
  170. // return;
  171. app.wxRequest(app.globalData.urlRoot + "wxPay/v3/getLucky", {token:app.globalData.luckyTokenList[0].token}, res => {
  172. console.log(res);
  173. if (res.code == 200) {
  174. app.globalData.luckyTokenList.splice(0,1);
  175. // res.data.lucky = true;
  176. // res.data.awardData = {};
  177. // res.data.awardData.awardId = 19
  178. if(res.data.lucky){
  179. let timeNum = 0;
  180. let timeRotate = 0;
  181. if(res.data.awardData.awardId==19){
  182. timeNum = 3500;
  183. timeRotate = 420;
  184. }else if(res.data.awardData.awardId==20){
  185. timeNum = 4000;
  186. timeRotate = 480;
  187. }else if(res.data.awardData.awardId==23){
  188. timeNum = 5000;
  189. timeRotate = 600;
  190. }
  191. this.drawAniFun(timeNum,timeRotate);
  192. setTimeout(() => {
  193. this.setData({
  194. awardId:res.data.awardData.awardId
  195. })
  196. }, timeNum+400);
  197. }else{
  198. //1 0.12
  199. this.drawAniFun(5500,660);
  200. setTimeout(() => {
  201. btnOpen = false;
  202. this.prizeControl2();
  203. }, 5500+400);
  204. }
  205. console.log(app.globalData.luckyTokenList);
  206. }else{
  207. btnOpen = false;
  208. wx.showToast({
  209. title: res.msg,
  210. icon:"none"
  211. })
  212. }
  213. }, this)
  214. },
  215. prizeControl2(){//控制获奖弹窗显示状态
  216. this.setData({
  217. prizeShow2:!this.data.prizeShow2
  218. })
  219. },
  220. backPage(){
  221. wx.navigateBack({
  222. delta:1
  223. })
  224. },
  225. addressControl(){//立即领取
  226. this.setData({
  227. addressShow: !this.data.addressShow
  228. })
  229. if (this.data.addressShow) {
  230. app.globalData.skipType = 'mycenter';
  231. }
  232. },
  233. getAddress: function () {//获取地址
  234. app.wxRequest(app.globalData.urlRoot + "address/getAddressV2", {}, res => {
  235. if (res.code == 200) {
  236. if (res.data) {
  237. this.setData({
  238. isAddress:true
  239. })
  240. }
  241. }
  242. }, this)
  243. },
  244. getLuckyTokenList() {
  245. app.wxRequest(app.globalData.urlRoot + "wxPay/v3/getLuckyTokenList", {}, res => {
  246. if (res.code == 200) {
  247. if (res.data) {
  248. res.data.cdate = res.data.cdate ? res.data.cdate : "";
  249. app.globalData.getBuyState = res.data.success;
  250. if (res.data.luckyTokenList) {
  251. app.globalData.luckyTokenList = res.data.luckyTokenList;
  252. }
  253. }
  254. }
  255. }, this);
  256. }
  257. })