myAppointment.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 已取消 4: 已完成 5.超时
  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 = 4
  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. const response = res.data.vos || []
  49. response.map(item => {
  50. item.appointmentTimeStr = item.appointmentTime.split(' ')[0]
  51. })
  52. this.setData({
  53. hasNext: res.data.hasNext,
  54. appointmentList: response
  55. })
  56. }).catch(e => {
  57. wx.hideLoading()
  58. wx.showModal({
  59. content: e,
  60. confirmColor: '#333',
  61. showCancel: false
  62. })
  63. })
  64. },
  65. /**
  66. * 生命周期函数--监听到底
  67. */
  68. onReachBottom() {
  69. if (this.data.hasNext) {
  70. var _currentPag = this.data.currentPag + 1
  71. that.setData({
  72. currentPag: _currentPag
  73. })
  74. this.getAppointmentList()
  75. }
  76. },
  77. handleCancelAppoint (e) {
  78. var that = this
  79. wx.showLoading({
  80. title: '加载中...',
  81. mask: true
  82. })
  83. cancelAppointment({
  84. appointmentId: this.data.appointmentId
  85. }).then(res => {
  86. wx.hideLoading()
  87. wx.showToast({
  88. title: '取消成功',
  89. icon: 'success',
  90. success () {
  91. that.handleChangeNav(that.data.navItemActive, false)
  92. }
  93. })
  94. }).catch(e => {
  95. wx.hideLoading()
  96. wx.showModal({
  97. content: e,
  98. confirmColor: '#333',
  99. showCancel: false
  100. })
  101. })
  102. },
  103. /**
  104. * 取消预约
  105. */
  106. handleCancel(e) {
  107. var that = this
  108. this.setData({
  109. appointmentId: e.currentTarget.dataset.id
  110. })
  111. wx.showModal({
  112. content: '确定要取消预约吗?',
  113. confirmColor: '#333',
  114. cancelColor: '#666',
  115. success (res) {
  116. if (res.confirm) {
  117. that.handleCancelAppoint()
  118. }
  119. }
  120. })
  121. },
  122. handleScanCode () {
  123. wx.navigateTo({
  124. url: '/pages/myFile/myFile',
  125. })
  126. },
  127. /**
  128. * 切换nav
  129. * 状态 空代表查询全部 ,1:申请(待服务) 2.取消(不做参数) 3.完成
  130. */
  131. handleChangeNav(e, navFlag = true) {
  132. var navItemActive = navFlag ? e.currentTarget.dataset.index : e
  133. this.setData({
  134. navItemActive: navItemActive,
  135. currentPage: 1
  136. })
  137. this.getAppointmentList()
  138. }
  139. })