index.js 1.9 KB

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