index.js 5.9 KB

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