// pages/problem_list/problem_list.js import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber, formatDate,throttle} from '../../utils/util.js' import { ProblemList} from '../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData } = getApp() const { baseImgUrl, thumbnail } = globalData const app = getApp() Page({ /** * 页面的初始数据 */ data: { baseImgUrl, thumbnail, pageNo: 1, pageSize: 5, maxCreateTime: formatDateTime(new Date()), isAll: false, isLoaded: false, navIndex:0, subject:'语文', nodata: [ { text: '暂无语文数据' }, { text: '暂无数学数据' }, { text: '暂无英语数据' } ], navList: [ { text: '语文' }, { text: '数学' }, { text: '英语' }, ], }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData(options) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { const obj = { navigateTo, redirectTo, navigateBack, viewImage } for (const i in obj) { this[i] = obj[i] } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getData() }, /** * 生命周期函数--监听页面隐藏 */ 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 (app.sharePageDefaultCtl) { return app.sharePageDefaultCtl() } }, /** * 选择切换项 */ selectNavIndexCtl:throttle(function (e) { const { index,subject } = e.currentTarget.dataset const {navIndex}=this.data if (navIndex == index) return this.setData({ navIndex: index, subject,list:[],pageNo:1}) this.getData() },500), /** * 返回上一页 */ backBook: function () { wx.navigateBack({ delta: 1, }) }, /** * 获取数据 */ getData: function (cb) { const continuousFn = { fn: this.getData, param: { ...arguments } } const { vipId, pageNo, pageSize, list, subject, maxCreateTime } = this.data ProblemList({ data: { vipId, pageNo, pageSize, subject, maxCreateTime }, continuousFn }).then(res => { const listTemp = res.data.list; let arr = [] if (pageNo == 1) { arr = [...listTemp] } else { arr = [...list, ...listTemp] } this.setData({ list: arr, pageNo: listTemp.length == pageSize ? pageNo + 1 : pageNo, isAll: listTemp.length < pageSize, isLoaded: true }) if (isFn(cb)) cb() }).catch(res => { this.setData({ isLoaded: true }) if (isFn(cb)) cb() }) }, })