const app = getApp(); Page({ /** * 页面的初始数据 */ data: { frameStyle: { useTop: true, name: '临时上课学员', leftArrow: true, useBar: false }, iconUrl: app.globalData.icon, lesson_id: '', // 查询 search: {}, list: [], total: 0, skip: 0, limit: 10, page: 0, }, // 跳转菜单 back(e) { wx.navigateBack({ delta: 1 }) }, // 查询 toInput(e) { const that = this; let value = e.detail.value; if (value) that.setData({ 'search.name': value }) else that.setData({ search: {} }) that.clearPage(); that.search(); }, // 清空列表 clearPage() { const that = this; that.setData({ list: [], skip: 0, limit: 10, page: 0 }) }, // 添加 toAdd() { const that = this; let lesson_id = that.data.lesson_id; that.clearPage(); wx.navigateTo({ url: `/pagesSchool/coaAdmin/course/tpStudentadd?lesson_id=${lesson_id}`, }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { const that = this; that.setData({ lesson_id: options.lesson_id || '' }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: async function () { const that = this; // 监听用户是否登录 await that.watchLogin(); }, watchLogin: async function () { const that = this; wx.getStorage({ key: 'user', success: async res => { await that.search(); }, fail: async res => { wx.redirectTo({ url: '/pages/index/index' }) } }) }, async search() { const that = this; let lesson_id = that.data.lesson_id; let info = { skip: that.data.skip, limit: that.data.limit, lesson_id: lesson_id }; let res = await app.$get(`/tempLessonApply`, { ...info, ...that.data.search }); if (res.errcode == '0') { let list = [...that.data.list, ...res.data]; that.setData({ list }); that.setData({ total: res.total }); } else { wx.showToast({ title: res.errmsg, icon: 'none' }) } }, // 分页 toPage: function () { const that = this; let list = that.data.list; let limit = that.data.limit; if (that.data.total > list.length) { wx.showLoading({ title: '加载中', mask: true }) let page = that.data.page + 1; that.setData({ page: page }) let skip = page * limit; that.setData({ skip: skip }) that.watchLogin(); wx.hideLoading() } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { const that = this; that.clearPage(); }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })