// pages/myAppointment/myAppointment.js import { appointmentList, cancelAppointment } from '../../api/appointment' const app = getApp() Page({ /** * 页面的初始数据 */ data: { navItemActive: '0', appointmentList: [], currentPage: 1, hasNext: false, globalDataUserName: '', appointmentId: '' }, /** * 生命周期函数--监听页面显示 */ onShow() { this.setData({ navItemActive: '0', globalDataUserName: wx.getStorageSync('userName') }) this.getAppointmentList() }, /** * 获取预约列表 * 状态 空代表查询全部 1 待服务,2,3 已取消 4: 已完成 5.超时 */ getAppointmentList() { var status = '' if (this.data.navItemActive == '0' ) { status = '' } else if (this.data.navItemActive == '1') { status = 1 } else if (this.data.navItemActive == '2') { status = 4 } var data = { status: status, currentPage: this.data.currentPage } wx.showLoading({ title: '加载中...', mask: true }) appointmentList(data).then(res => { wx.hideLoading() const response = res.data.vos || [] response.map(item => { item.appointmentTimeStr = item.appointmentTime.split(' ')[0] }) this.setData({ hasNext: res.data.hasNext, appointmentList: response }) }).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() } } }) }, handleScanCode () { wx.navigateTo({ url: '/pages/myFile/myFile', }) }, /** * 切换nav * 状态 空代表查询全部 ,1:申请(待服务) 2.取消(不做参数) 3.完成 */ handleChangeNav(e, navFlag = true) { var navItemActive = navFlag ? e.currentTarget.dataset.index : e this.setData({ navItemActive: navItemActive, currentPage: 1 }) this.getAppointmentList() } })