index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import share from '~/mixins/share'
  2. import {
  3. getHotrecommendList,
  4. getWorksNum
  5. } from "~/api/works"
  6. import event from '~/mixins/event'
  7. import reachBottom from '~/mixins/reachBottom'
  8. import {
  9. createStoreBindings
  10. } from 'mobx-miniprogram-bindings'
  11. import {
  12. store
  13. } from '~/store/index'
  14. Page({
  15. behaviors: [reachBottom, share, event],
  16. data: {
  17. isFixed: false,
  18. count:{}
  19. },
  20. onShow() {
  21. if (typeof this.getTabBar === 'function') {
  22. this.getTabBar().setData({
  23. selected: 1
  24. })
  25. }
  26. this.getLocUserInfo()
  27. if (Object.keys(this.data.userInfo).length > 0) {
  28. this.requestAgain()
  29. } else {
  30. getApp().callBack = (res) => {
  31. this.getLocUserInfo()
  32. this.requestAgain()
  33. }
  34. }
  35. },
  36. loadMore() {
  37. if (!this.data.userInfo.grade) {
  38. return
  39. }
  40. this.localGetData(getHotrecommendList, {
  41. grade: this.data.userInfo.grade
  42. })
  43. },
  44. async requestAgain() {
  45. this.resetData()
  46. let count = await getWorksNum()
  47. this.setData({
  48. count
  49. })
  50. },
  51. async getLocUserInfo() {
  52. this.storeBindings = createStoreBindings(this, {
  53. store,
  54. fields: {
  55. userInfo: 'userInfo'
  56. },
  57. })
  58. this.storeBindings.updateStoreBindings()
  59. },
  60. jump({
  61. currentTarget
  62. }) {
  63. let type = currentTarget.dataset.type
  64. wx.navigateTo({
  65. url: `/pages/userWorks/index?type=${type}`,
  66. })
  67. },
  68. onReachBottom() {
  69. this.loadMore()
  70. },
  71. onUnload() {
  72. this.storeBindings.destroyStoreBindings()
  73. },
  74. })