piano.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // pages/piano/piano.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. beginDate: null,
  11. endDate: null,
  12. list: [
  13. ],
  14. loading: '上拉加载',
  15. flag: 0,
  16. pageNum: 0,
  17. hasNextPage: true,
  18. },
  19. getPiano: function () {
  20. wx.navigateTo({
  21. url: '/pages/makePiano/makePiano',
  22. })
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onReady: function () {
  33. },
  34. /**
  35. * 生命周期函数--监听页面显示
  36. */
  37. onShow: function () {
  38. let now = new Date();
  39. // 显示近7天的预约记录
  40. let bd = util.formatTime(now).substring(0, 10).replace(/\//g, '-')
  41. let edd = new Date(now.setDate(now.getDate() + 7));
  42. let ed = util.formatTime(edd).substring(0, 10).replace(/\//g, '-')
  43. const date = new Date()
  44. this.setData({ beginDate: date.getFullYear()+"-01"+"-01", endDate: ed, list: [] });
  45. this.queryList();
  46. },
  47. /**
  48. * 生命周期函数--监听页面隐藏
  49. */
  50. onHide: function () {
  51. },
  52. /**
  53. * 生命周期函数--监听页面卸载
  54. */
  55. onUnload: function () {
  56. },
  57. /**
  58. * 页面相关事件处理函数--监听用户下拉动作
  59. */
  60. onPullDownRefresh: function () {
  61. },
  62. /**
  63. * 页面上拉触底事件的处理函数
  64. */
  65. onReachBottom: function () {
  66. if (this.data.hasNextPage) {
  67. let pn = this.data.pageNum
  68. this.setData({ loading: '加载中', 'pageNum': ++pn })
  69. this.queryList()
  70. }
  71. },
  72. /**
  73. * 用户点击右上角分享
  74. */
  75. onShareAppMessage: function () {
  76. },
  77. getDates: function (e) {
  78. this.setData({
  79. list: [],
  80. pageNum: 0,
  81. beginDate: e.detail[0],
  82. endDate: e.detail[1],
  83. loading: '加载中'
  84. })
  85. this.queryList()
  86. },
  87. queryList: function () {
  88. const urls = urlDef.urls;
  89. let stu = wx.getStorageSync('student');
  90. if (stu) {
  91. let params = { 'q.beginDate': this.data.beginDate, 'q.endDate': this.data.endDate, 'q.studentId': stu.studentId, 'q.orgId': stu.orgId }
  92. params.pageNum = this.data.pageNum
  93. util.apiPost(urls.query_appointment_list, params).then(rs => {
  94. let list = rs.list
  95. list.map(o => {
  96. o.visitDate = o.visitDate.substring(0, 10)
  97. o.cancelFlag = this.canCancel(o) // 是否可以取消
  98. })
  99. this.setData({
  100. 'hasNextPage': rs.hasNextPage,
  101. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  102. 'list': this.data.list.concat(list)
  103. })
  104. })
  105. }
  106. },
  107. canCancel(item) { // 判断是否能取消, 未到预约时间前都能取消,至少提前1个小时
  108. let t = item.visitDate + ' ' + item.beginTime + ':00';
  109. let vdt = new Date(t.replace(/-/g,'/'));
  110. let tdt = new Date().getTime();
  111. if (vdt < tdt) {
  112. return false;
  113. }
  114. // const dayTime = 86400000;
  115. const dayTime = 3600000;
  116. return (vdt - tdt) >= dayTime
  117. },
  118. doCancel: function (e) {
  119. let id = e.currentTarget.dataset.id
  120. let that = this
  121. wx.showModal({
  122. title: '确认信息',
  123. content: '确定要取消本次预约?',
  124. showCancel: true,
  125. cancelText: "否",
  126. confirmText: "是",
  127. success: function (res) {
  128. if (res.cancel) {
  129. } else {
  130. wx.showLoading({
  131. title: '正在取消',
  132. mask: true
  133. })
  134. that.doRealCancel(id)
  135. }
  136. }
  137. })
  138. },
  139. doRealCancel: function (id) {
  140. const urls = urlDef.urls;
  141. util.apiPost(urls.cancel_appointment + '?id=' + id).then(rs => {
  142. if (rs.message) {
  143. wx.showToast({ title: rs.message, icon: 'none' })
  144. return
  145. }
  146. wx.showToast({ title: '取消成功', icon: 'success' })
  147. this.setData({
  148. list: [],
  149. pageNum: 0,
  150. loading: '加载中'
  151. })
  152. this.queryList()
  153. })
  154. }
  155. })