index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. // console.log(activityList);
  43. // 下面这个处理限时活动的,第一版先不上
  44. // activityList.forEach((item, index) => {
  45. // if (item.bannerType == 4 && item.voucherType) {
  46. // // this.activityTimeOut(1677109150000, index)
  47. // this.activityTimeOut(item.endTime, index)
  48. // }
  49. // })
  50. },
  51. jumpUserInfo({
  52. currentTarget
  53. }) {
  54. if (!currentTarget.dataset.uid) {
  55. return
  56. }
  57. wx.navigateTo({
  58. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  59. })
  60. },
  61. activityTimeOut(oTime, index) {
  62. let inputTime = new Date(oTime)
  63. let dsq = setInterval(() => {
  64. console.log('1');
  65. var nowTime = new Date();
  66. //把剩余时间毫秒数转化为秒
  67. var times = (inputTime - nowTime) / 1000;
  68. if (times <= 0) {
  69. this.setData({
  70. [`activityList[${index}].hour`]: '00',
  71. [`activityList[${index}].minute`]: '00',
  72. [`activityList[${index}].second`]: '00',
  73. })
  74. return clearInterval(dsq)
  75. }
  76. //计算小时数 转化为整数
  77. var h = parseInt(times / 60 / 60 % 24);
  78. //如果小时数小于 10,要变成 0 + 数字的形式 赋值给盒子
  79. let hour = h < 10 ? "0" + h : h;
  80. //计算分钟数 转化为整数
  81. var m = parseInt(times / 60 % 60);
  82. //如果分钟数小于 10,要变成 0 + 数字的形式 赋值给盒子
  83. let minute = m < 10 ? "0" + m : m;
  84. //计算描述 转化为整数
  85. var s = parseInt(times % 60);
  86. //如果秒钟数小于 10,要变成 0 + 数字的形式 赋值给盒子
  87. let second = s < 10 ? "0" + s : s;
  88. this.setData({
  89. [`activityList[${index}].hour`]: hour,
  90. [`activityList[${index}].minute`]: minute,
  91. [`activityList[${index}].second`]: second,
  92. })
  93. times = --times;
  94. }, 1000);
  95. this.setData({
  96. dsqList: [...this.data.dsqList, dsq]
  97. })
  98. },
  99. activityEvent({
  100. currentTarget
  101. }) {
  102. //1:图片,2:邀新榜,3:热播榜,4:挑战pk榜,5,朗读赛,6,领取勋章
  103. let {
  104. type,
  105. id,
  106. title,
  107. explain
  108. } = currentTarget.dataset.info
  109. if (type == 1) {
  110. wx.navigateTo({
  111. url: `/pages/rankIntro/index?title=${title}&img=${explain}`,
  112. })
  113. }
  114. if (type == 5) {
  115. wx.navigateTo({
  116. url: `/pages/match/index`,
  117. })
  118. }
  119. if ([2, 3, 4].includes(type)) {
  120. wx.navigateTo({
  121. url: `/pages/ranking/index?id=${id}&type=${type}`,
  122. })
  123. }
  124. },
  125. drawVoucher({
  126. currentTarget
  127. }) {
  128. let info = currentTarget.dataset.info
  129. this.selectComponent('#voucher').open({
  130. type: info.type,
  131. id: info.id,
  132. voucherType: info.voucherType,
  133. preferential: info.price
  134. })
  135. }
  136. }
  137. })