piano.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. this.setData({ beginDate: bd, endDate: ed, list: [] });
  44. this.queryList();
  45. },
  46. /**
  47. * 生命周期函数--监听页面隐藏
  48. */
  49. onHide: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面卸载
  53. */
  54. onUnload: function () {
  55. },
  56. /**
  57. * 页面相关事件处理函数--监听用户下拉动作
  58. */
  59. onPullDownRefresh: function () {
  60. },
  61. /**
  62. * 页面上拉触底事件的处理函数
  63. */
  64. onReachBottom: function () {
  65. if (this.data.hasNextPage) {
  66. let pn = this.data.pageNum
  67. this.setData({ loading: '加载中', 'pageNum': ++pn })
  68. this.queryList()
  69. }
  70. },
  71. /**
  72. * 用户点击右上角分享
  73. */
  74. onShareAppMessage: function () {
  75. },
  76. getDates: function (e) {
  77. this.setData({
  78. list: [],
  79. pageNum: 0,
  80. beginDate: e.detail[0],
  81. endDate: e.detail[1],
  82. loading: '加载中'
  83. })
  84. this.queryList()
  85. },
  86. queryList: function () {
  87. const urls = urlDef.urls;
  88. let stu = wx.getStorageSync('student');
  89. if (stu) {
  90. let params = { 'q.beginDate': this.data.beginDate, 'q.endDate': this.data.endDate, 'q.studentId': stu.studentId, 'q.orgId': stu.orgId }
  91. params.pageNum = this.data.pageNum
  92. util.apiPost(urls.query_appointment_list, params).then(rs => {
  93. let list = rs.list
  94. list.map(o => {
  95. o.visitDate = o.visitDate.substring(0, 10)
  96. o.cancelFlag = this.canCancel(o) // 是否可以取消
  97. })
  98. this.setData({
  99. 'hasNextPage': rs.hasNextPage,
  100. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  101. 'list': this.data.list.concat(list)
  102. })
  103. })
  104. }
  105. },
  106. canCancel(item) { // 判断是否能取消, 未到预约时间前都能取消,至少提前1个小时
  107. let t = item.visitDate + ' ' + item.beginTime + ':00';
  108. let vdt = new Date(t.replace(/-/g,'/'));
  109. let tdt = new Date().getTime();
  110. if (vdt < tdt) {
  111. return false;
  112. }
  113. // const dayTime = 86400000;
  114. const dayTime = 3600000;
  115. return item.attend == 0 && (vdt - tdt) >= dayTime
  116. },
  117. doCancel: function (e) {
  118. let id = e.currentTarget.dataset.id
  119. let that = this
  120. wx.showModal({
  121. title: '确认信息',
  122. content: '确定要取消本次预约?',
  123. showCancel: true,
  124. cancelText: "否",
  125. confirmText: "是",
  126. success: function (res) {
  127. if (res.cancel) {
  128. } else {
  129. wx.showLoading({
  130. title: '正在取消',
  131. mask: true
  132. })
  133. that.doRealCancel(id)
  134. }
  135. }
  136. })
  137. },
  138. doRealCancel: function (id) {
  139. const urls = urlDef.urls;
  140. util.apiPost(urls.cancel_appointment + '?id=' + id).then(rs => {
  141. if (rs.message) {
  142. wx.showToast({ title: rs.message, icon: 'none' })
  143. return
  144. }
  145. wx.showToast({ title: '取消成功', icon: 'success' })
  146. this.setData({
  147. list: [],
  148. pageNum: 0,
  149. loading: '加载中'
  150. })
  151. this.queryList()
  152. })
  153. }
  154. })