myAppointment.js 3.1 KB

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