index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const app = getApp()
  2. import {
  3. getHotrecommendList
  4. } from "~/api/works"
  5. import {
  6. getBannerList
  7. } from '~/api/global'
  8. import reachBottom from '~/mixins/reachBottom'
  9. import {
  10. createStoreBindings
  11. } from 'mobx-miniprogram-bindings'
  12. import {
  13. store
  14. } from '~/store/index'
  15. Page({
  16. behaviors: [reachBottom],
  17. /**
  18. * 页面的初始数据
  19. */
  20. data: {
  21. navBarHeight: app.globalData.navBarHeight,
  22. background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
  23. currentType: '1',
  24. // 控制一级分类是否固定
  25. isFixed: false
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onShow() {
  31. if (typeof this.getTabBar === 'function') {
  32. this.getTabBar().setData({
  33. selected: 1
  34. })
  35. }
  36. getApp().callBack = (res) => {
  37. this.getLocUserInfo()
  38. this.loadMore()
  39. }
  40. },
  41. onUnload() {
  42. this.storeBindings.destroyStoreBindings()
  43. },
  44. async getLocUserInfo() {
  45. this.storeBindings = createStoreBindings(this, {
  46. store,
  47. fields: {
  48. userInfo: 'userInfo'
  49. },
  50. })
  51. this.storeBindings.updateStoreBindings()
  52. /* let res = await getBannerList(1)
  53. console.log(res); */
  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. jumpChildClassify() {
  67. wx.navigateTo({
  68. url: `/pages/childClassify/index?type=class&id=123`,
  69. })
  70. },
  71. jumpSearch() {
  72. wx.navigateTo({
  73. url: '/pages/childClassify/index?type=search',
  74. })
  75. },
  76. /**
  77. * 监听页面滚动事件
  78. */
  79. onPageScroll(e) {
  80. if (e.scrollTop >= 103 && !this.data.isFixed) {
  81. this.setData({
  82. isFixed: true
  83. })
  84. } else if (e.scrollTop < 103 && this.data.isFixed) {
  85. this.setData({
  86. isFixed: false
  87. })
  88. }
  89. },
  90. onReachBottom() {
  91. this.loadMore()
  92. },
  93. selectType({
  94. target
  95. }) {
  96. if (target.dataset.type) {
  97. this.setData({
  98. currentType: target.dataset.type
  99. })
  100. this.resetData()
  101. }
  102. },
  103. })