index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. const app = getApp()
  2. import {
  3. getHotrecommendList
  4. } from "~/api/works"
  5. import reachBottom from '~/mixins/reachBottom'
  6. import {
  7. createStoreBindings
  8. } from 'mobx-miniprogram-bindings'
  9. import {
  10. store
  11. } from '~/store/index'
  12. Page({
  13. behaviors: [reachBottom],
  14. /**
  15. * 页面的初始数据
  16. */
  17. data: {
  18. navBarHeight: app.globalData.navBarHeight,
  19. background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
  20. currentType: '1',
  21. // 控制一级分类是否固定
  22. isFixed: false
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onShow() {
  28. if (typeof this.getTabBar === 'function') {
  29. this.getTabBar().setData({
  30. selected: 1
  31. })
  32. }
  33. getApp().callBack = (res) => {
  34. this.getLocUserInfo()
  35. this.loadMore()
  36. }
  37. },
  38. onUnload() {
  39. this.storeBindings.destroyStoreBindings()
  40. },
  41. getLocUserInfo() {
  42. this.storeBindings = createStoreBindings(this, {
  43. store,
  44. fields: {
  45. userInfo: 'userInfo'
  46. },
  47. })
  48. this.storeBindings.updateStoreBindings()
  49. },
  50. loadMore() {
  51. if (this.data.currentType == '1') {
  52. this.getData(getHotrecommendList, {
  53. grade: this.data.userInfo.grade
  54. })
  55. } else if (this.data.currentType == '2') {
  56. this.getData(getHotrecommendList, {
  57. grade: 'PRESCHOOL'
  58. })
  59. }
  60. },
  61. /**
  62. * 监听页面滚动事件
  63. */
  64. onPageScroll(e) {
  65. if (e.scrollTop >= 103 && !this.data.isFixed) {
  66. this.setData({
  67. isFixed: true
  68. })
  69. } else if (e.scrollTop < 103 && this.data.isFixed) {
  70. this.setData({
  71. isFixed: false
  72. })
  73. }
  74. },
  75. onReachBottom() {
  76. this.loadMore()
  77. },
  78. selectType({
  79. target
  80. }) {
  81. if (target.dataset.type) {
  82. this.setData({
  83. currentType: target.dataset.type
  84. })
  85. this.resetData()
  86. }
  87. },
  88. })