// pages/myAppointment/myAppointment.js import { appointmentList, cancelAppointment } from '../../api/appointment' const app = getApp() Page({ /** * 页面的初始数据 */ data: { navItemActive: '0', appointmentList: [], currentPage: 1, hasNext: false, globalDataUserName: app.globalData.userInfo.userName, appointmentId: '' }, /** * 生命周期函数--监听页面显示 */ onShow() { this.setData({ navItemActive: '0' }) this.getAppointmentList() }, /** * 获取预约列表 * 状态 空代表查询全部 ,1:申请(待服务) 2.取消(不做参数) 3.完成 */ getAppointmentList() { var status = '' if (this.data.navItemActive == '0' ) { status = '' } else if (this.data.navItemActive == '1') { status = 1 } else if (this.data.navItemActive == '2') { status = 3 } var data = { status: status, currentPage: this.data.currentPage } wx.showLoading({ title: '加载中...', mask: true }) appointmentList(data).then(res => { wx.hideLoading() this.setData({ hasNext: res.data.hasNext, appointmentList: res.data.vos }) }).catch(e => { wx.hideLoading() wx.showModal({ content: e, confirmColor: '#333', showCancel: false }) }) }, /** * 生命周期函数--监听到底 */ onReachBottom() { if (this.data.hasNext) { var _currentPag = this.data.currentPag + 1 that.setData({ currentPag: _currentPag }) this.getAppointmentList() } }, handleCancelAppoint (e) { var that = this wx.showLoading({ title: '加载中...', mask: true }) cancelAppointment({ appointmentId: this.data.appointmentId }).then(res => { wx.hideLoading() wx.showToast({ title: '取消成功', icon: 'success', success () { that.handleChangeNav(that.data.navItemActive, false) } }) }).catch(e => { wx.hideLoading() wx.showModal({ content: e, confirmColor: '#333', showCancel: false }) }) }, /** * 取消预约 */ handleCancel(e) { var that = this this.setData({ appointmentId: e.currentTarget.dataset.id }) wx.showModal({ content: '确定要取消预约吗?', confirmColor: '#333', cancelColor: '#666', success (res) { if (res.confirm) { that.handleCancelAppoint() } } }) }, /** * 切换nav * 状态 空代表查询全部 ,1:申请(待服务) 2.取消(不做参数) 3.完成 */ handleChangeNav(e, navFlag = true) { var navItemActive = navFlag ? e.currentTarget.dataset.index : e this.setData({ navItemActive: navItemActive, currentPage: 1 }) this.getAppointmentList() } })