index.js 3.8 KB

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