1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import {
- getCategoryWorks,
- searchWorks
- } 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) {
- // 没有二级分类
- if (options.id) {
- this.setData({
- childType: options.id
- })
- this.resetData()
- } else if (options.list) {
- let categoryList = JSON.parse(decodeURIComponent(options.list))
- this.setData({
- categoryList
- })
- this.resetData()
- }
- wx.setNavigationBarTitle({
- title: options.title || '搜索'
- })
- this.setData({
- type: options.type,
- })
- },
- // 获取分类的内容
- loadMore() {
- if (this.data.type == 'search') {
- return
- }
- 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
- })
- this.resetData()
- },
- setSearch({
- detail
- }) {
- this.setData({
- text: detail.value
- })
- },
- async search() {
- if (!this.data.text) {
- return
- }
- let res = await searchWorks({
- title: this.data.text,
- grade: 'PRIMARY_FIRST_GRADE'
- })
- let list = res.map(item => {
- return {
- readAmount: item.readAmount,
- ...item.userRead
- }
- })
- this.setData({
- list
- })
- },
- goRead({
- currentTarget
- }) {
- wx.navigateTo({
- url: `/pages/reading/index?videoId=${currentTarget.dataset.id}`
- })
- },
- })
|