123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- // 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()
- })
- },
- })
|