index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. async getLocUserInfo() {
  56. this.storeBindings = createStoreBindings(this, {
  57. store,
  58. fields: {
  59. userInfo: 'userInfo'
  60. },
  61. })
  62. this.storeBindings.updateStoreBindings()
  63. },
  64. })