// pages/my-apply/my-apply.js import { cancelEnrollmentApi } from '../../service/hwRequirement'; import { getEnrollmentsImpl } from '../../service/impl/hwEnrollment.impl' Page({ /** * 页面的初始数据 */ data: { status: 1, // list: [], show: false, pageNo: 1, isLast: false }, /** * 跳转详情页 */ toDetail(e: any) { const id = e.currentTarget.dataset.id; wx.navigateTo({ url: `/pages/detail/detail?id=${id}&&status=1`, }) }, /** * 获取报名列表 * @pageNo 页码 * @pageSize 每页条数 */ getList(pageNumber?: number) { let pageNo = pageNumber || this.data.pageNo getEnrollmentsImpl({ pageNo, pageSize: 10 }).then(res => { if (res.errCode === 0) { if (pageNo === 1 && res.data.enrollmentsList && res.data.enrollmentsList.length === 0) { this.setData({ show: true }) } else { pageNo++; this.setData({ [`list[${pageNo - 2}]`]: res.data.enrollmentsList, isLast: res.data.isLast, pageNo }) } } }) }, /** * 取消订单 * @param {id} 订单id */ cancelEnrollment(e: any) { const { id } = e.currentTarget.dataset; cancelEnrollmentApi({ enroll_id: id }).then(() => { wx.showToast({ icon: 'none', title: '取消成功', success: () => { setTimeout(() => { this.getList(1) }, 1200) } }) }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function () { // 获取报名列表 this.setData({ list: [], pageNo: 1, }, () => { this.getList() }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.setData({ list: [], pageNo: 1, }, () => { this.getList() }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { const isLast = this.data.isLast; if (isLast) { // wx.showToast({ // icon: 'none', // title: '已经是最后一页了', // }) } else { this.getList() } } })