index.js 3.8 KB

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