index.js 7.2 KB

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