index.js 2.1 KB

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