index.js 1.9 KB

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