|
@@ -1,88 +1,92 @@
|
|
|
const app = getApp()
|
|
|
import {
|
|
|
- getHotrecommendList
|
|
|
+ getHotrecommendList
|
|
|
} from "~/api/works"
|
|
|
import reachBottom from '~/mixins/reachBottom'
|
|
|
import {
|
|
|
- createStoreBindings
|
|
|
+ createStoreBindings
|
|
|
} from 'mobx-miniprogram-bindings'
|
|
|
import {
|
|
|
- store
|
|
|
+ store
|
|
|
} from '~/store/index'
|
|
|
Page({
|
|
|
- behaviors: [reachBottom],
|
|
|
- /**
|
|
|
- * 页面的初始数据
|
|
|
- */
|
|
|
- data: {
|
|
|
- navBarHeight: app.globalData.navBarHeight,
|
|
|
- background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
|
|
|
- currentType: '1',
|
|
|
- // 控制一级分类是否固定
|
|
|
- isFixed: false
|
|
|
- },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
- onShow() {
|
|
|
- if (typeof this.getTabBar === 'function') {
|
|
|
- this.getTabBar().setData({
|
|
|
- selected: 1
|
|
|
- })
|
|
|
- }
|
|
|
- getApp().callBack = (res) => {
|
|
|
- this.storeBindings = createStoreBindings(this, {
|
|
|
- store,
|
|
|
- fields: {
|
|
|
- userInfo: 'userInfo'
|
|
|
- },
|
|
|
- })
|
|
|
- this.storeBindings.updateStoreBindings()
|
|
|
- this.loadMore()
|
|
|
- }
|
|
|
- },
|
|
|
- onUnload() {
|
|
|
- this.storeBindings.destroyStoreBindings()
|
|
|
- },
|
|
|
- loadMore() {
|
|
|
- if (this.data.currentType == '1') {
|
|
|
- this.getData(getHotrecommendList, {
|
|
|
- grade: this.data.userInfo.grade
|
|
|
- })
|
|
|
- } else if (this.data.currentType == '2') {
|
|
|
- this.getData(getHotrecommendList, {
|
|
|
- grade: 'PRESCHOOL'
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- },
|
|
|
- /**
|
|
|
- * 监听页面滚动事件
|
|
|
- */
|
|
|
- onPageScroll(e) {
|
|
|
- if (e.scrollTop >= 103 && !this.data.isFixed) {
|
|
|
- this.setData({
|
|
|
- isFixed: true
|
|
|
- })
|
|
|
- } else if (e.scrollTop < 103 && this.data.isFixed) {
|
|
|
- this.setData({
|
|
|
+ behaviors: [reachBottom],
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ navBarHeight: app.globalData.navBarHeight,
|
|
|
+ background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
|
|
|
+ currentType: '1',
|
|
|
+ // 控制一级分类是否固定
|
|
|
isFixed: false
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ onShow() {
|
|
|
+ if (typeof this.getTabBar === 'function') {
|
|
|
+ this.getTabBar().setData({
|
|
|
+ selected: 1
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.storeBindings = createStoreBindings(this, {
|
|
|
+ store,
|
|
|
+ fields: {
|
|
|
+ userInfo: 'userInfo'
|
|
|
+ },
|
|
|
+ })
|
|
|
+ this.storeBindings.updateStoreBindings()
|
|
|
+ if (wx.getStorageSync('uid')) {
|
|
|
+ this.loadMore()
|
|
|
+ } else {
|
|
|
+ getApp().callBack = (res) => {
|
|
|
+ this.loadMore()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ this.storeBindings.destroyStoreBindings()
|
|
|
+ },
|
|
|
+ loadMore() {
|
|
|
+ if (this.data.currentType == '1') {
|
|
|
+ this.getData(getHotrecommendList, {
|
|
|
+ grade: this.data.userInfo.grade
|
|
|
+ })
|
|
|
+ } else if (this.data.currentType == '2') {
|
|
|
+ this.getData(getHotrecommendList, {
|
|
|
+ grade: 'PRESCHOOL'
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 监听页面滚动事件
|
|
|
+ */
|
|
|
+ onPageScroll(e) {
|
|
|
+ if (e.scrollTop >= 103 && !this.data.isFixed) {
|
|
|
+ this.setData({
|
|
|
+ isFixed: true
|
|
|
+ })
|
|
|
+ } else if (e.scrollTop < 103 && this.data.isFixed) {
|
|
|
+ this.setData({
|
|
|
+ isFixed: false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
- onReachBottom() {
|
|
|
- this.loadMore()
|
|
|
- },
|
|
|
- selectType({
|
|
|
- target
|
|
|
- }) {
|
|
|
- if (target.dataset.type) {
|
|
|
- this.setData({
|
|
|
- currentType: target.dataset.type
|
|
|
- })
|
|
|
- this.resetData()
|
|
|
- }
|
|
|
- },
|
|
|
+ onReachBottom() {
|
|
|
+ this.loadMore()
|
|
|
+ },
|
|
|
+ selectType({
|
|
|
+ target
|
|
|
+ }) {
|
|
|
+ if (target.dataset.type) {
|
|
|
+ this.setData({
|
|
|
+ currentType: target.dataset.type
|
|
|
+ })
|
|
|
+ this.resetData()
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
})
|