myAppointment.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // pages/myAppointment/myAppointment.js
  2. import { appointmentList, cancelAppointment } from '../../api/appointment'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. navItemActive: '0',
  10. appointmentList: [],
  11. currentPage: 1,
  12. hasNext: false,
  13. globalDataUserName: app.globalData.userInfo.userName,
  14. appointmentId: ''
  15. },
  16. /**
  17. * 生命周期函数--监听页面显示
  18. */
  19. onShow() {
  20. this.setData({
  21. navItemActive: '0'
  22. })
  23. this.getAppointmentList()
  24. },
  25. /**
  26. * 获取预约列表
  27. * 状态 空代表查询全部 ,1:申请(待服务) 2.取消(不做参数) 3.完成
  28. */
  29. getAppointmentList() {
  30. var status = ''
  31. if (this.data.navItemActive == '0' ) {
  32. status = ''
  33. } else if (this.data.navItemActive == '1') {
  34. status = 1
  35. } else if (this.data.navItemActive == '2') {
  36. status = 3
  37. }
  38. var data = {
  39. status: status,
  40. currentPage: this.data.currentPage
  41. }
  42. wx.showLoading({
  43. title: '加载中...',
  44. mask: true
  45. })
  46. appointmentList(data).then(res => {
  47. wx.hideLoading()
  48. this.setData({
  49. hasNext: res.data.hasNext,
  50. appointmentList: res.data.vos
  51. })
  52. }).catch(e => {
  53. wx.hideLoading()
  54. wx.showModal({
  55. content: e,
  56. confirmColor: '#333',
  57. showCancel: false
  58. })
  59. })
  60. },
  61. /**
  62. * 生命周期函数--监听到底
  63. */
  64. onReachBottom() {
  65. if (this.data.hasNext) {
  66. var _currentPag = this.data.currentPag + 1
  67. that.setData({
  68. currentPag: _currentPag
  69. })
  70. this.getAppointmentList()
  71. }
  72. },
  73. handleCancelAppoint (e) {
  74. var that = this
  75. wx.showLoading({
  76. title: '加载中...',
  77. mask: true
  78. })
  79. cancelAppointment({
  80. appointmentId: this.data.appointmentId
  81. }).then(res => {
  82. wx.hideLoading()
  83. wx.showToast({
  84. title: '取消成功',
  85. icon: 'success',
  86. success () {
  87. that.handleChangeNav(that.data.navItemActive, false)
  88. }
  89. })
  90. }).catch(e => {
  91. wx.hideLoading()
  92. wx.showModal({
  93. content: e,
  94. confirmColor: '#333',
  95. showCancel: false
  96. })
  97. })
  98. },
  99. /**
  100. * 取消预约
  101. */
  102. handleCancel(e) {
  103. var that = this
  104. this.setData({
  105. appointmentId: e.currentTarget.dataset.id
  106. })
  107. wx.showModal({
  108. content: '确定要取消预约吗?',
  109. confirmColor: '#333',
  110. cancelColor: '#666',
  111. success (res) {
  112. if (res.confirm) {
  113. that.handleCancelAppoint()
  114. }
  115. }
  116. })
  117. },
  118. /**
  119. * 切换nav
  120. * 状态 空代表查询全部 ,1:申请(待服务) 2.取消(不做参数) 3.完成
  121. */
  122. handleChangeNav(e, navFlag = true) {
  123. var navItemActive = navFlag ? e.currentTarget.dataset.index : e
  124. this.setData({
  125. navItemActive: navItemActive,
  126. currentPage: 1
  127. })
  128. this.getAppointmentList()
  129. }
  130. })