lottery.js 5.5 KB

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