index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. jumpChildClassify() {
  62. wx.navigateTo({
  63. url: `/pages/childClassify/index?type=class&id=123`,
  64. })
  65. },
  66. jumpSearch() {
  67. wx.navigateTo({
  68. url: '/pages/childClassify/index?type=search',
  69. })
  70. },
  71. /**
  72. * 监听页面滚动事件
  73. */
  74. onPageScroll(e) {
  75. if (e.scrollTop >= 103 && !this.data.isFixed) {
  76. this.setData({
  77. isFixed: true
  78. })
  79. } else if (e.scrollTop < 103 && this.data.isFixed) {
  80. this.setData({
  81. isFixed: false
  82. })
  83. }
  84. },
  85. onReachBottom() {
  86. this.loadMore()
  87. },
  88. selectType({
  89. target
  90. }) {
  91. if (target.dataset.type) {
  92. this.setData({
  93. currentType: target.dataset.type
  94. })
  95. this.resetData()
  96. }
  97. },
  98. })