index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {
  2. createStoreBindings
  3. } from 'mobx-miniprogram-bindings'
  4. import {
  5. getCategoryList,
  6. getAuthorityList,
  7. } from "~/api/works"
  8. import share from '~/mixins/share'
  9. import reachBottom from '~/mixins/reachBottom'
  10. import {
  11. store
  12. } from '~/store/index'
  13. Page({
  14. behaviors: [reachBottom, share],
  15. data: {
  16. categoryList: [],
  17. isFixed: false
  18. },
  19. onShow() {
  20. if (typeof this.getTabBar === 'function') {
  21. this.getTabBar().setData({
  22. selected: 1
  23. })
  24. }
  25. this.getLocUserInfo()
  26. if (Object.keys(this.data.userInfo).length > 0) {
  27. this.requestAgain()
  28. } else {
  29. getApp().callBack = (res) => {
  30. this.getLocUserInfo()
  31. this.requestAgain()
  32. }
  33. }
  34. },
  35. requestAgain() {
  36. this.resetData()
  37. this.getCategoryList()
  38. },
  39. async loadMore() {
  40. if (!this.data.userInfo.grade) {
  41. return
  42. }
  43. let list = await getAuthorityList({
  44. grade: this.data.userInfo.grade
  45. })
  46. this.setData({
  47. list
  48. })
  49. },
  50. async getCategoryList() {
  51. let grade = this.data.userInfo.grade
  52. let categoryList = await getCategoryList({
  53. grade
  54. })
  55. this.setData({
  56. categoryList
  57. })
  58. },
  59. jumpChildClassify({
  60. currentTarget
  61. }) {
  62. let firstInfo = currentTarget.dataset.item
  63. let params = firstInfo.childList.length > 0 ? `list=${encodeURIComponent(JSON.stringify(firstInfo.childList))}` : `id=${firstInfo.id}`
  64. wx.navigateTo({
  65. url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&${params}`,
  66. })
  67. },
  68. onUnload() {
  69. this.storeBindings.destroyStoreBindings()
  70. },
  71. async getLocUserInfo() {
  72. this.storeBindings = createStoreBindings(this, {
  73. store,
  74. fields: {
  75. userInfo: 'userInfo'
  76. },
  77. })
  78. this.storeBindings.updateStoreBindings()
  79. },
  80. onUnload() {
  81. this.storeBindings.destroyStoreBindings()
  82. },
  83. /**
  84. * 监听页面滚动事件
  85. */
  86. onPageScroll(e) {
  87. if (e.scrollTop >= 6 && !this.data.isFixed) {
  88. this.setData({
  89. isFixed: true
  90. })
  91. } else if (e.scrollTop < 6 && this.data.isFixed) {
  92. this.setData({
  93. isFixed: false
  94. })
  95. }
  96. },
  97. })