index.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. console.log(activityList);
  78. this.setData({
  79. activityList,
  80. })
  81. activityList.forEach((item, index) => {
  82. if (item.bannerType == 4 && item.voucherType) {
  83. this.activityTimeOut(item.endTime, index)
  84. }
  85. })
  86. },
  87. jumpUserInfo({
  88. currentTarget
  89. }) {
  90. if (!currentTarget.dataset.uid) {
  91. return
  92. }
  93. wx.navigateTo({
  94. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  95. })
  96. },
  97. activityTimeOut(oTime, index) {
  98. let inputTime = new Date(oTime)
  99. let dsq = setInterval(() => {
  100. var nowTime = new Date();
  101. //把剩余时间毫秒数转化为秒
  102. var times = (inputTime - nowTime) / 1000;
  103. if (times <= 0) {
  104. this.setData({
  105. [`activityList[${index}].hour`]: '00',
  106. [`activityList[${index}].minute`]: '00',
  107. [`activityList[${index}].second`]: '00',
  108. [`activityList[${index}].finish`]: true,
  109. })
  110. return clearInterval(dsq)
  111. }
  112. //计算小时数 转化为整数
  113. var h = parseInt(times / 60 / 60);
  114. //如果小时数小于 10,要变成 0 + 数字的形式 赋值给盒子
  115. let hour = h < 10 ? "0" + h : h;
  116. //计算分钟数 转化为整数
  117. var m = parseInt(times / 60 % 60);
  118. //如果分钟数小于 10,要变成 0 + 数字的形式 赋值给盒子
  119. let minute = m < 10 ? "0" + m : m;
  120. //计算描述 转化为整数
  121. var s = parseInt(times % 60);
  122. //如果秒钟数小于 10,要变成 0 + 数字的形式 赋值给盒子
  123. let second = s < 10 ? "0" + s : s;
  124. this.setData({
  125. [`activityList[${index}].hour`]: hour,
  126. [`activityList[${index}].minute`]: minute,
  127. [`activityList[${index}].second`]: second,
  128. [`activityList[${index}].finish`]: false,
  129. })
  130. times = --times;
  131. }, 1000);
  132. this.setData({
  133. dsqList: [...this.data.dsqList, dsq]
  134. })
  135. },
  136. activityEvent({
  137. currentTarget
  138. }) {
  139. //1:图片,2:邀新榜,3:热播榜,4:挑战pk榜,5,朗读赛,6,领取勋章,9:邀新,10订购vip会员,11分销
  140. let {
  141. type,
  142. id,
  143. title,
  144. explain
  145. } = currentTarget.dataset.info
  146. if (type == 1) {
  147. wx.navigateTo({
  148. url: `/pages/rankIntro/index?title=${title}&img=${explain}`,
  149. })
  150. }
  151. if (type == 5) {
  152. wx.navigateTo({
  153. url: `/pages/match/index?activityId=${id}`,
  154. })
  155. }
  156. if ([2, 3, 4].includes(type)) {
  157. wx.navigateTo({
  158. url: `/pages/ranking/index?id=${id}&type=${type}`,
  159. })
  160. }
  161. if (type == 9) {
  162. wx.navigateTo({
  163. url: "/pages/invite/index",
  164. })
  165. }
  166. if (type == 10) {
  167. this.selectComponent('#buyVip').open()
  168. }
  169. if (type == 11) {
  170. let url = ''
  171. if (!this.data.userInfo.saleUserId) {
  172. url = '/salesperson/pages/sale/index'
  173. } else {
  174. url = '/salesperson/pages/saleOffice/index'
  175. }
  176. wx.navigateTo({
  177. url
  178. })
  179. }
  180. },
  181. drawVoucher({
  182. currentTarget
  183. }) {
  184. let info = currentTarget.dataset.info
  185. if (info.finish) {
  186. return
  187. }
  188. this.selectComponent('#voucher').open({
  189. type: info.type,
  190. id: info.id,
  191. voucherType: info.voucherType,
  192. preferential: info.price
  193. })
  194. }
  195. }
  196. })