index.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {
  2. getActivities,
  3. } from '~/api/global'
  4. import {
  5. createStoreBindings
  6. } from 'mobx-miniprogram-bindings'
  7. import {
  8. store
  9. } from '~/store/index'
  10. Page({
  11. data: {
  12. rankList: [],
  13. activityList: []
  14. },
  15. onLoad(options) {
  16. this.getLocUserInfo()
  17. if (Object.keys(this.data.userInfo).length > 0) {
  18. this.getRankList()
  19. this.getActivityList()
  20. } else {
  21. getApp().callBack = (res) => {
  22. this.getLocUserInfo()
  23. this.getRankList()
  24. this.getActivityList()
  25. }
  26. }
  27. },
  28. onShow() {
  29. if (typeof this.getTabBar === 'function') {
  30. this.getTabBar().setData({
  31. selected: 0
  32. })
  33. }
  34. },
  35. async getRankList() {
  36. let res = await getActivities({
  37. classify: 2,
  38. grade: this.data.userInfo.grade
  39. })
  40. let list = res.filter(item => {
  41. return item.type != 2
  42. })
  43. this.setData({
  44. rankList: list
  45. })
  46. },
  47. async getActivityList() {
  48. let res = await getActivities({
  49. classify: 3,
  50. grade: this.data.userInfo.grade
  51. })
  52. this.setData({
  53. activityList: res
  54. })
  55. },
  56. activityEvent({
  57. currentTarget
  58. }) {
  59. let {
  60. type,
  61. } = currentTarget.dataset.info
  62. wx.navigateTo({
  63. url: `/pages/ranking/index?type=${type}`,
  64. })
  65. },
  66. jumpUserInfo({
  67. currentTarget
  68. }) {
  69. if (!currentTarget.dataset.uid) {
  70. return
  71. }
  72. wx.navigateTo({
  73. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  74. })
  75. },
  76. async getLocUserInfo() {
  77. this.storeBindings = createStoreBindings(this, {
  78. store,
  79. fields: {
  80. userInfo: 'userInfo'
  81. },
  82. })
  83. this.storeBindings.updateStoreBindings()
  84. },
  85. })