index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. console.log(count);
  48. this.setData({
  49. count
  50. })
  51. },
  52. async getLocUserInfo() {
  53. this.storeBindings = createStoreBindings(this, {
  54. store,
  55. fields: {
  56. userInfo: 'userInfo'
  57. },
  58. })
  59. this.storeBindings.updateStoreBindings()
  60. },
  61. jump({
  62. currentTarget
  63. }) {
  64. let type = currentTarget.dataset.type
  65. wx.navigateTo({
  66. url: `/pages/userWorks/index?type=${type}`,
  67. })
  68. },
  69. onReachBottom() {
  70. this.loadMore()
  71. },
  72. onUnload() {
  73. this.storeBindings.destroyStoreBindings()
  74. },
  75. })