const app = getApp(); Page({ /** * 页面的初始数据 */ data: { frameStyle: { useTop: true, name: '课程统计', leftArrow: true, useBar: false }, user: {}, list: [], total: 0, skip: 0, limit: 10, page: 0, // dialog弹框 dialog: { title: '筛选条件', show: false, type: '1' }, form: {}, // 课程信息 lessonList: [], // 学生 studentList: [] }, // 跳转菜单 back(e) { wx.navigateBack({ delta: 1 }) }, // 清空列表 clearPage() { const that = this; that.setData({ list: [], skip: 0, limit: 10, page: 0 }) }, // 筛选条件 toSearch() { const that = this; that.clearPage(); that.setData({ dialog: { title: '筛选条件', show: true, type: '1' } }) }, // 选择课程 lessonChange(e) { const that = this; let data = that.data.lessonList[e.detail.value]; console.log(data); if (data) that.setData({ 'form.lesson_id': data.id, 'form.lesson_title': data.title }) }, // 选择学员 stuChange(e) { const that = this; let data = that.data.studentList[e.detail.value]; if (data) that.setData({ 'form.student_id': data.student_id, 'form.student_id_name': data.student_id_name }) }, // 时间确定选择 datetimeChange: function (e) { const that = this; that.setData({ [`form.${e.detail.name}`]: e.detail.datetime }); }, // 提交查询 onSubmit(e) { const that = this; // let form = that.data.form; // const params = e.detail.value; // params.time_start = form.time_start; // params.time_end = form.time_end; that.search() }, // 关闭弹框 toClose: function () { const that = this; that.clearPage(); that.setData({ form: {} }) that.setData({ dialog: { title: '筛选条件', show: false, type: '1' } }) that.search() }, // 重置查询 onReset(e) { const that = this; that.clearPage() that.setData({ form: {} }) that.search(); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: async function () { const that = this; // 监听用户登录 await that.watchLogin(); }, watchLogin() { const that = this; wx.getStorage({ key: 'user', success: async res => { that.setData({ user: res.data }) await that.searchOther() await that.search() }, fail: async res => { wx.redirectTo({ url: '/pages/index/index' }) } }) }, async search() { const that = this; console.log(that.data.form); }, async searchOther() { const that = this; let user = that.data.user; let res; // 查詢課程信息 res = await app.$get(`/lesson`, { school_id: user.info.id }); if (res.errcode == '0') { that.setData({ lessonList: res.data }) } // 查询学校学生 res = await app.$get(`/rss`, { school_id: user.info.id }) if (res.errcode == '0') { that.setData({ studentList: res.data }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { const that = this; that.clearPage(); }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })