piano.js 4.0 KB

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