index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.storeBindings = createStoreBindings(this, {
  35. store,
  36. fields: {
  37. userInfo: 'userInfo'
  38. },
  39. })
  40. this.storeBindings.updateStoreBindings()
  41. this.loadMore()
  42. }
  43. },
  44. onUnload() {
  45. this.storeBindings.destroyStoreBindings()
  46. },
  47. loadMore() {
  48. if (this.data.currentType == '1') {
  49. this.getData(getHotrecommendList, {
  50. grade: this.data.userInfo.grade
  51. })
  52. } else if (this.data.currentType == '2') {
  53. this.getData(getHotrecommendList, {
  54. grade: 'PRESCHOOL'
  55. })
  56. }
  57. },
  58. /**
  59. * 监听页面滚动事件
  60. */
  61. onPageScroll(e) {
  62. if (e.scrollTop >= 103 && !this.data.isFixed) {
  63. this.setData({
  64. isFixed: true
  65. })
  66. } else if (e.scrollTop < 103 && this.data.isFixed) {
  67. this.setData({
  68. isFixed: false
  69. })
  70. }
  71. },
  72. onReachBottom() {
  73. this.loadMore()
  74. },
  75. selectType({
  76. target
  77. }) {
  78. if (target.dataset.type) {
  79. this.setData({
  80. currentType: target.dataset.type
  81. })
  82. this.resetData()
  83. }
  84. },
  85. })