lottery.js 4.7 KB

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