index.js 5.6 KB

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