index.js 3.6 KB

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