index.js 2.3 KB

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