index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
  19. currentType: '1'
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onShow() {
  25. if (typeof this.getTabBar === 'function') {
  26. this.getTabBar().setData({
  27. selected: 1
  28. })
  29. }
  30. getApp().callBack = (res) => {
  31. this.storeBindings = createStoreBindings(this, {
  32. store,
  33. fields: {
  34. userInfo: 'userInfo'
  35. },
  36. })
  37. this.storeBindings.updateStoreBindings()
  38. this.loadMore()
  39. }
  40. },
  41. onUnload() {
  42. this.storeBindings.destroyStoreBindings()
  43. },
  44. loadMore() {
  45. console.log(this.data.currentType, 'zzz');
  46. if (this.data.currentType == '1') {
  47. this.getData(getHotrecommendList, {
  48. grade: this.data.userInfo.grade
  49. })
  50. } else if (this.data.currentType == '2') {
  51. this.getData(getHotrecommendList, {
  52. grade: 'PRESCHOOL'
  53. })
  54. }
  55. },
  56. onReachBottom() {
  57. console.log('触底');
  58. this.loadMore()
  59. },
  60. selectType({
  61. target
  62. }) {
  63. if (target.dataset.type) {
  64. this.setData({
  65. currentType: target.dataset.type
  66. })
  67. this.resetData()
  68. }
  69. },
  70. })