// pages/leave/leave.js const app = getApp(); const { axios } = app.globalData; Page({ /** * 页面的初始数据 */ data: { notice: "", datalist: [] }, // 请求管理数据 totalPage: 1, currentPage: 1, AdddataRequest () { if (this.currentPage > this.totalResult) return false; let that = this; axios({ url: "/order/student_leave/", method: 'get', success (res) { let { data, totalPage } = res.data, datalist = that.data.datalist; that.totalPage = totalPage; data.forEach(item => { let { student_text: name, id } = item; datalist.push({ id, name, tel: [item.school_text, item.grade_text, item.class_text].join(" "), createdata: item.create_time_f, enddata: item.leave_date, data: item.order_text }) }) that.setData({ datalist }) that.currentPage++; wx.stopPullDownRefresh(); } }) }, // 删除 Del (e) { let { index } = e.currentTarget.dataset, that = this, { datalist } = this.data; axios({ url: `/order/student_leave/${datalist[index].id}/`, method: 'delete', success (res) { datalist.splice(index, 1) that.setData({ datalist }) } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.lxd.Ctr({ // nav title: "请假管理", //标题 back: false, tabber: true, active: 1,//活动值 }); }, // 新增 Add () { if (!this.state) { this.login(); return false; } wx.navigateTo({ url: '/pages/leaveadd/leaveadd', }) }, login () { wx.showModal({ title: '提示', content: '请先登录!', success (res) { if (res.confirm) { wx.navigateTo({ url: '/pages/sgin/sgin', }) } } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { let { token, user } = app.globalData; this.state = token(); if (!this.state) { this.login(); return false; } this.totalResult = 1; this.currentPage = 1; this.setData({ datalist: [], notice: `请假截止时间:${user.lead_hour}` }) this.AdddataRequest() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { if (!this.state) { this.login(); return false; } this.totalResult = 1; this.currentPage = 1; this.setData({ datalist: [] }) this.AdddataRequest() }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { if (!this.state) { this.login(); return false; } this.AdddataRequest() }, })