detail.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // pages/luckDraw/detail.js
  2. import LuckDraw from '../../api/luck-draw'
  3. import {getMobileCache, getPhoneNumber} from '../../utils/user'
  4. const app = getApp();
  5. const DEFAULT_GIFTS = [
  6. { icoUrl: '', text: '' }, { iconUrl: '', text: '' },{ icoUrl: '', text: '' }, { icoUrl: '', text: ''},
  7. { icoUrl: '', text: ''}, { icoUrl: '', text: '' }, { icoUrl: '', text: ''}, { icoUrl: '', text: '' }
  8. ];
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. activityId: 0,
  15. forbidTurn: false,
  16. giftList: DEFAULT_GIFTS,
  17. allNum: 1000,
  18. remainNum: 128,
  19. remainNumSplits: [],
  20. showHitPrizeDlg: false,
  21. showNoHitPrizeDlg: false,
  22. showPage: true
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. if (!options.id) {
  29. app.showToast ('入参错误');
  30. wx.navigateTo({
  31. url: './index',
  32. })
  33. return
  34. }
  35. this.data.activityId = options.id
  36. this.loadActivity()
  37. this.getDrawTimes()
  38. },
  39. loadActivity: function() {
  40. LuckDraw.getActivityDetail(this.data.activityId).then(resp => {
  41. if (resp.code == 200 && resp.data != null) {
  42. this.mapDataToView(resp.data)
  43. }
  44. }).catch(_ => {
  45. console.log(_)
  46. app.showToast ('活动不存在');
  47. wx.navigateTo({
  48. url: './index',
  49. })
  50. return
  51. })
  52. },
  53. /**
  54. * 获取次数
  55. */
  56. getDrawTimes: function() {
  57. LuckDraw.getTimes(this.data.activityId, getMobileCache()).then(res => {
  58. if (res.code == 200) {
  59. this.setData({
  60. remainNum: res.data.remainTimes,
  61. allNum: res.data.allTimes,
  62. })
  63. this.setRemainNumSplits()
  64. }
  65. }).catch(_ => {})
  66. },
  67. /**
  68. * 活动数据映射
  69. */
  70. mapDataToView: function(activity) {
  71. activity.goodsItemList.forEach(v => {
  72. const pos = parseInt(v.pos || 0)
  73. if (pos > 0) {
  74. if (this.data.giftList[pos-1].isLoaded) {
  75. return true
  76. }
  77. this.data.giftList[pos - 1].isLoaded = true
  78. this.data.giftList[pos - 1].text = v.goodsName
  79. this.data.giftList[pos - 1].iconUrl = v.goodsSmallImage
  80. this.data.giftList[pos - 1].hitIconUrl = v.goodsBigImage
  81. this.data.giftList[pos - 1].goodsId = v.goodsId
  82. this.data.giftList[pos - 1].couponId = v.couponId
  83. this.data.giftList[pos - 1].isSpecial = v.isSpecial
  84. this.data.giftList[pos - 1].hitDesc = v.hitDesc
  85. this.data.giftList[pos - 1].active = false
  86. }
  87. })
  88. this.setData({
  89. activityTitle: activity.activityTitle,
  90. showBeginTime: activity.showBeginTime,
  91. showEndTime: activity.showEndTime,
  92. beginTime: activity.beginTime,
  93. endTime: activity.endTime,
  94. timeType: activity.timeType,
  95. giftList: this.data.giftList,
  96. ruleDesc: activity.ruleDesc || ''
  97. })
  98. },
  99. /**
  100. * 开始转动奖品,抽奖
  101. */
  102. turnPrize: function() {
  103. console.log("开始抽奖")
  104. },
  105. /**
  106. * 生命周期函数--监听页面初次渲染完成
  107. */
  108. onReady: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面显示
  112. */
  113. onShow: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload: function () {
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh: function () {
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom: function () {
  134. },
  135. /**
  136. * 用户点击右上角分享
  137. */
  138. onShareAppMessage: function () {
  139. },
  140. setRemainNumSplits: function() {
  141. this.setData({
  142. remainNumSplits: (this.data.remainNum || 0).toString().split("")
  143. })
  144. },
  145. closeDlg: function() {
  146. this.setData({
  147. showHitPrizeDlg: false,
  148. showNoHitPrizeDlg: false
  149. })
  150. }
  151. })