index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. this.setData({
  41. rankList: res
  42. })
  43. },
  44. async getActivityList() {
  45. let res = await getActivities({
  46. classify: 3,
  47. grade: this.data.userInfo.grade
  48. })
  49. console.log(res, 'bbbb');
  50. this.setData({
  51. activityList: res
  52. })
  53. },
  54. activityEvent({
  55. currentTarget
  56. }) {
  57. let {
  58. type,
  59. } = currentTarget.dataset.info
  60. wx.navigateTo({
  61. url: `/pages/ranking/index?type=${type}`,
  62. })
  63. },
  64. jumpUserInfo({
  65. currentTarget
  66. }) {
  67. if (!currentTarget.dataset.uid) {
  68. return
  69. }
  70. wx.navigateTo({
  71. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  72. })
  73. },
  74. async getLocUserInfo() {
  75. this.storeBindings = createStoreBindings(this, {
  76. store,
  77. fields: {
  78. userInfo: 'userInfo'
  79. },
  80. })
  81. this.storeBindings.updateStoreBindings()
  82. },
  83. })