import { getCategoryWorks } from '~/api/works' import reachBottom from '~/mixins/reachBottom' Page({ behaviors: [reachBottom], data: { // class为二级,search为搜索 type: 'class', categoryList: [], childType: '', currentIndex: 0, scrollTop: 0, text: '', }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let title = '分类' console.log(options); // 没有二级分类 if (options.id) { this.setData({ childType: options.id }) title = options.title this.resetData() } else if (options.list) { let categoryList = JSON.parse(decodeURIComponent(options.list)) this.setData({ categoryList }) title = this.data.categoryList[this.data.currentIndex].title this.resetData() } wx.setNavigationBarTitle({ title }) this.setData({ type: options.type, }) }, // 获取分类的内容 loadMore() { let columnId = this.data.childType ? this.data.childType : this.data.categoryList[this.data.currentIndex].id this.getData(getCategoryWorks, { columnId }) }, setClass({ currentTarget }) { this.setData({ scrollTop: 0, currentIndex: currentTarget.dataset.index }) wx.setNavigationBarTitle({ title: this.data.categoryList[this.data.currentIndex].title }) this.resetData() }, setSearch({ detail }) { this.setData({ text: detail.value }) }, search() { console.log("搜索"); }, goRead({ currentTarget }) { console.log( currentTarget.dataset ); wx.navigateTo({ url: `/pages/reading/index?videoId=${currentTarget.dataset.id}` }) }, bindscrolltolower() { this.loadMore() }, })