piano.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. type: ''
  19. },
  20. getPiano: function () {
  21. wx.navigateTo({
  22. url: '/pages/makePiano/makePiano',
  23. })
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. },
  30. /**
  31. * 生命周期函数--监听页面初次渲染完成
  32. */
  33. onReady: function () {
  34. },
  35. /**
  36. * 生命周期函数--监听页面显示
  37. */
  38. onShow: function () {
  39. let now = new Date();
  40. // 显示近7天的预约记录
  41. let bd = util.formatTime(now).substring(0, 10).replace(/\//g, '-')
  42. let edd = new Date(now.setDate(now.getDate() + 7));
  43. let ed = util.formatTime(edd).substring(0, 10).replace(/\//g, '-')
  44. this.setData({ beginDate: bd, 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.dateArr[0],
  82. endDate: e.detail.dateArr[1],
  83. type: e.detail.typeIndex == 0 ? '' : e.detail.typeIndex,
  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.type': this.data.type }
  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. doCancelQueue: 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. const urls = urlDef.urls;
  136. util.apiPost(urls.delete_queue, {'ids[]': [id]}).then(rs => {
  137. if (rs.message) {
  138. wx.showToast({ title: rs.message, icon: 'none' })
  139. return
  140. }
  141. wx.showToast({ title: '取消成功', icon: 'success' })
  142. that.setData({
  143. list: [],
  144. pageNum: 0,
  145. loading: '加载中'
  146. })
  147. that.queryList()
  148. })
  149. }
  150. }
  151. })
  152. },
  153. doCancel: function (e) {
  154. let id = e.currentTarget.dataset.id
  155. let that = this
  156. wx.showModal({
  157. title: '确认信息',
  158. content: '确定要取消本次预约?',
  159. showCancel: true,
  160. cancelText: "否",
  161. confirmText: "是",
  162. success: function (res) {
  163. if (res.cancel) {
  164. } else {
  165. wx.showLoading({
  166. title: '正在取消',
  167. mask: true
  168. })
  169. that.doRealCancel(id)
  170. }
  171. }
  172. })
  173. },
  174. doRealCancel: function (id) {
  175. const urls = urlDef.urls;
  176. util.apiPost(urls.cancel_appointment + '?id=' + id).then(rs => {
  177. if (rs.message) {
  178. wx.showToast({ title: rs.message, icon: 'none' })
  179. return
  180. }
  181. wx.showToast({ title: '取消成功', icon: 'success' })
  182. this.setData({
  183. list: [],
  184. pageNum: 0,
  185. loading: '加载中'
  186. })
  187. this.queryList()
  188. })
  189. }
  190. })