123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- // parents/pages/growth/growth.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
- import { BookSort, SortSearch} from '../../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData, hasLibraryService, hasVipService } = getApp()
- const { baseImgUrl } = globalData
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- baseImgUrl,
- isLoaded: 1,
- pageNo: 1,
- pageSize: 10,
- isAll: 0,
- list: [],
- themeIdx:0,
- isClass:true,
- navIndex:0,
- themeList: [
- // {
- // "code": "child1",
- // "name": "历史文化"
- // },
- // {
- // "code": "child2",
- // "name": "人文艺术"
- // },
- // {
- // "code": "child3",
- // "name": "学科素养"
- // },
- // {
- // "code": "child4",
- // "name": "想象幻想"
- // },
- // {
- // "code": "child4",
- // "name": "想象幻想"
- // },
- // {
- // "code": "child4",
- // "name": "想象幻想"
- // }
- ],
- nodataArray: {
- text: '暂无数据',
- // image: '../../../assets/nodata_2.png'
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- options.userId = getGlobalVal('userId')
- // options.vipId = getGlobalVal('vipId', `vipId_${options.userId}`) || ''
- options.vipId ='ea4e93ee-8b22-41bd-bb09-ec36e88eab78'
- options.libId = getGlobalVal('library').id || ''
- this.setData({ options })
- // this.getData(res => {
- // this.setData({ isLoaded: 1 })
- // })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- const obj = { navigateTo, redirectTo, navigateBack, viewImage }
- for (const i in obj) {
- this[i] = obj[i]
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.getBookSort()
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.setData({ pageNo: 1 })
- this.getData(res => {
- wx.stopPullDownRefresh()
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- const { isAll } = this.data
- if (isAll) {
- return
- }
- this.getData()
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- if (isFn(sharePage)) return sharePage()
- },
- /**
- * 获取主题年龄段
- */
- getBookSort: function (cb) {
- const continuousFn = { fn: this.getBookSort, param: { ...arguments } }
- wx.showLoading({
- title: '加载中',
- })
- BookSort({ data: {}, continuousFn }).then(res => {
- wx.hideLoading()
- const { themeList, gradeList} = res.data
- themeList.unshift({ code: '', name:'全部'})
- gradeList.unshift('全部')
- this.setData({ themeList, gradeList})
- cb && cb()
- }).catch(res => {
- this.setData({ isLoaded: true })
- cb && cb()
- })
- },
- /**
- * 选择主题
- */
- selectTheme:function(e){
- const { code, theme, type } = e.currentTarget.dataset;
- this.setData({ code, isClass: false, isTheme: type, grade: type == 0 ? theme : "",theme,isLoaded:false})
- wx.setNavigationBarTitle({
- title: `${theme}`,
- })
- this.getData()
- },
- /**
- * 选择二级主题
- */
- selectOne: function (e) {
- const { code, index} = e.currentTarget.dataset;
- this.setData({ code, themeIdx: index, list: [], isLoaded: false, pageNo:1 })
- this.getData()
- },
- /**
- * 选择班级
- */
- selectTwo: function (e) {
- const { theme, index } = e.currentTarget.dataset;
- this.setData({ grade: theme == '全部' ? '' : theme, themeIdx: index, list: [], isLoaded: false, pageNo: 1 })
- this.getData()
- },
- /**
- * 获取数据
- */
- getData: function (cb) {
- const continuousFn = { fn: this.getData, param: { ...arguments } }
- const { pageNo, pageSize, options, list, code, grade } = this.data
- const { libId} = options
- SortSearch({ data: { pageNo, pageSize, libId, code, grade }, continuousFn }).then(res => {
- const newList = res.data.list
- const listTemp = (res => {
- for (let i in res) {
- if (res[i].summary.length > 30) {
- res[i].summary = res[i].summary.slice(0, 30) + '...'
- } else {
- res[i].summary = res[i].summary
- }
- }
- return res
- })(newList)
- let arr = []
- if (pageNo == 1) {
- arr = [...listTemp]
- } else {
- arr = [...list, ...listTemp]
- }
- this.setData({ list: arr, isAll: newList.length < pageSize, pageNo: newList.length == pageSize ? pageNo + 1 : pageNo, isLoaded: true })
- cb && cb()
- }).catch(res => {
- this.setData({ isLoaded: true })
- cb && cb()
- })
- }
- })
|