lottery.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // pages/tips/tips.js
  2. const api = require('../../utils/api.js')
  3. const util = require('../../utils/util.js')
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. first: true,
  11. isLoad: false,
  12. lotteryInfo: {
  13. award: {}
  14. },
  15. userInfo: {},
  16. bgFlag: false,
  17. animationData: {},
  18. isClick: false,
  19. ModalConfig: {
  20. visible: false,
  21. title: '',
  22. content: '',
  23. ModalType: ''
  24. },
  25. qrCode: '',
  26. howToWithdraw: false,
  27. rotate: 0,
  28. mpGzh: app.globalData.mpGzh
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. let timer = setInterval(() => {
  35. if (app.globalData.PageCallback) {
  36. clearInterval(timer)
  37. this.setData({
  38. isClick: true,
  39. userInfo: app.globalData.userInfo,
  40. isLoad: true
  41. })
  42. this.SwitchBg()
  43. }
  44. }, 200)
  45. },
  46. onShow: function () {
  47. if (this.data.isLoad) {
  48. api.getUserInfo({
  49. HideLoading: true
  50. }).then(res => {
  51. this.setData({
  52. userInfo: res.data
  53. })
  54. }, err => {
  55. console.log(err)
  56. })
  57. }
  58. api.getLotteryDetail({
  59. HideLoading: !this.data.first
  60. }).then(res => {
  61. this.setData({
  62. lotteryInfo: res.data
  63. })
  64. })
  65. if (this.data.first) {
  66. this.setData({
  67. first: false
  68. })
  69. }
  70. },
  71. SwitchBg: function (e) {
  72. setInterval(() => {
  73. this.setData({
  74. bgFlag: !this.data.bgFlag
  75. })
  76. }, 1000)
  77. },
  78. start: function (e) {
  79. // 抽奖中
  80. if (!this.data.isClick) {
  81. return false
  82. }
  83. let _self = this
  84. let award = this.data.lotteryInfo.award
  85. let length = Object.keys(award).length
  86. let deg = 360 / length
  87. this.setData({
  88. rotate: this.data.rotate - this.data.rotate % 360
  89. })
  90. api.drawLottery({
  91. HideLoading: true
  92. }).then(res => {
  93. let which = res.data.list_order
  94. let animation = wx.createAnimation({
  95. duration: 1.4 * (2160 - (which - 1) * deg),
  96. timingFunction: 'ease-in-out'
  97. })
  98. let rotate = this.data.rotate + 2160 - (which - 0.5) * deg
  99. animation.rotate(rotate).step()
  100. this.setData({
  101. animationData: animation.export(),
  102. isClick: false,
  103. rotate
  104. })
  105. setTimeout(function () {
  106. let ModelConf = {
  107. visible: true,
  108. ModalType: res.data.is_real === 2 ? 'input' : 'text'
  109. }
  110. ModelConf.title = res.data.has_award === 1 ? '很遗憾,没有中奖' : '恭喜,中奖啦'
  111. ModelConf.content = res.data.has_award === 1 ? '' : `恭喜获得${res.data.award_name}${res.data.is_real === 2 ? ',请填写相关信息领取奖励' : ''}`
  112. let { lotteryInfo } = _self.data
  113. lotteryInfo = {
  114. ...lotteryInfo,
  115. ...res.data
  116. }
  117. _self.setData({
  118. ModalConfig: ModelConf,
  119. isClick: true,
  120. lotteryInfo
  121. })
  122. }, 1.4 * (2160 - (which - 1) * deg) + 600)
  123. }, err => {
  124. this.setData({
  125. isClick: true
  126. })
  127. })
  128. },
  129. hideModal: function(e) {
  130. console.log(`获取到手机号-${e.detail}`)
  131. var animation = wx.createAnimation({
  132. transformOrigin: "50% 50%",
  133. duration: 0,
  134. timingFunction: "linear"
  135. });
  136. // animation.rotate(0).step();
  137. this.setData({
  138. animationData: animation.export(),
  139. isClick: true,
  140. ModalConfig: {
  141. visible: false
  142. }
  143. })
  144. },
  145. routeTo: function (e) {
  146. util.routeTo(e.currentTarget.dataset.url)
  147. },
  148. routeUser: function (e) {
  149. app.globalData.openGZH = true
  150. wx.switchTab({
  151. url: '/pages/user/index'
  152. })
  153. },
  154. OpenWithdraw: function (e) {
  155. console.log(this.data.qrCode)
  156. if (!this.data.qrCode) {
  157. api.getWithdrawTips().then(res => {
  158. if (res.code === 200) {
  159. this.setData({
  160. howToWithdraw: true,
  161. qrCode: res.data.image
  162. })
  163. }
  164. })
  165. } else {
  166. this.setData({
  167. howToWithdraw: true
  168. })
  169. }
  170. },
  171. hideWithdraw: function (e) {
  172. this.setData({
  173. howToWithdraw: false
  174. })
  175. }
  176. })