index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. const app = getApp()
  2. import {
  3. getActivities
  4. } from '~/api/global'
  5. import {
  6. storeBindingsBehavior
  7. } from 'mobx-miniprogram-bindings'
  8. import {
  9. store
  10. } from '~/store/index'
  11. Component({
  12. behaviors: [storeBindingsBehavior],
  13. storeBindings: {
  14. store,
  15. fields: {
  16. userInfo: 'userInfo'
  17. },
  18. },
  19. properties: {
  20. classify: {
  21. type: Number,
  22. value: 1
  23. }
  24. },
  25. /**
  26. * 组件的初始数据
  27. */
  28. data: {
  29. //1:图片,2:邀新榜,3:热播榜,4:挑战pk榜,5,朗读赛,6,领取勋章,7年包红包8,次数红包
  30. type: '4',
  31. activityList: [],
  32. isIos: app.globalData.isIOS,
  33. dsqList: []
  34. },
  35. lifetimes: {
  36. attached() {
  37. this.getActivities()
  38. },
  39. detached() {
  40. this.data.dsqList.forEach(item => {
  41. clearInterval(item)
  42. })
  43. }
  44. },
  45. /**
  46. * 组件的方法列表
  47. */
  48. methods: {
  49. async getActivities() {
  50. this.data.dsqList.forEach(item => {
  51. clearInterval(item)
  52. })
  53. let activityList = await getActivities({
  54. classify: this.properties.classify,
  55. grade: this.data.userInfo.grade
  56. })
  57. this.setData({
  58. activityList,
  59. })
  60. activityList.forEach((item, index) => {
  61. if (item.bannerType == 4 && item.voucherType) {
  62. this.activityTimeOut(item.endTime, index)
  63. }
  64. })
  65. },
  66. jumpUserInfo({
  67. currentTarget
  68. }) {
  69. if (!currentTarget.dataset.uid) {
  70. return
  71. }
  72. wx.navigateTo({
  73. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  74. })
  75. },
  76. activityTimeOut(oTime, index) {
  77. let inputTime = new Date(oTime)
  78. let dsq = setInterval(() => {
  79. var nowTime = new Date();
  80. //把剩余时间毫秒数转化为秒
  81. var times = (inputTime - nowTime) / 1000;
  82. if (times <= 0) {
  83. this.setData({
  84. [`activityList[${index}].hour`]: '00',
  85. [`activityList[${index}].minute`]: '00',
  86. [`activityList[${index}].second`]: '00',
  87. [`activityList[${index}].finish`]: true,
  88. })
  89. return clearInterval(dsq)
  90. }
  91. //计算小时数 转化为整数
  92. var h = parseInt(times / 60 / 60);
  93. //如果小时数小于 10,要变成 0 + 数字的形式 赋值给盒子
  94. let hour = h < 10 ? "0" + h : h;
  95. //计算分钟数 转化为整数
  96. var m = parseInt(times / 60 % 60);
  97. //如果分钟数小于 10,要变成 0 + 数字的形式 赋值给盒子
  98. let minute = m < 10 ? "0" + m : m;
  99. //计算描述 转化为整数
  100. var s = parseInt(times % 60);
  101. //如果秒钟数小于 10,要变成 0 + 数字的形式 赋值给盒子
  102. let second = s < 10 ? "0" + s : s;
  103. this.setData({
  104. [`activityList[${index}].hour`]: hour,
  105. [`activityList[${index}].minute`]: minute,
  106. [`activityList[${index}].second`]: second,
  107. [`activityList[${index}].finish`]: false,
  108. })
  109. times = --times;
  110. }, 1000);
  111. this.setData({
  112. dsqList: [...this.data.dsqList, dsq]
  113. })
  114. },
  115. activityEvent({
  116. currentTarget
  117. }) {
  118. //1:图片,2:邀新榜,3:热播榜,4:挑战pk榜,5,朗读赛,6,领取勋章
  119. let {
  120. type,
  121. id,
  122. title,
  123. explain
  124. } = currentTarget.dataset.info
  125. if (type == 1) {
  126. wx.navigateTo({
  127. url: `/pages/rankIntro/index?title=${title}&img=${explain}`,
  128. })
  129. }
  130. if (type == 5) {
  131. wx.navigateTo({
  132. url: `/pages/match/index?activityId=${id}`,
  133. })
  134. }
  135. if ([2, 3, 4].includes(type)) {
  136. wx.navigateTo({
  137. url: `/pages/ranking/index?id=${id}&type=${type}`,
  138. })
  139. }
  140. },
  141. drawVoucher({
  142. currentTarget
  143. }) {
  144. let info = currentTarget.dataset.info
  145. if (info.finish) {
  146. return
  147. }
  148. this.selectComponent('#voucher').open({
  149. type: info.type,
  150. id: info.id,
  151. voucherType: info.voucherType,
  152. preferential: info.price
  153. })
  154. }
  155. }
  156. })