index.js 7.0 KB

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