piano.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. changeType:function(e){
  25. console.log(e)
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. },
  32. /**
  33. * 生命周期函数--监听页面初次渲染完成
  34. */
  35. onReady: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow: function () {
  41. let now = new Date();
  42. // 显示近7天的预约记录
  43. let bd = util.formatTime(now).substring(0, 10).replace(/\//g, '-')
  44. let edd = new Date(now.setDate(now.getDate() + 7));
  45. let ed = util.formatTime(edd).substring(0, 10).replace(/\//g, '-')
  46. this.setData({ beginDate: bd, endDate: ed, list: [] });
  47. this.queryList();
  48. },
  49. /**
  50. * 生命周期函数--监听页面隐藏
  51. */
  52. onHide: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面卸载
  56. */
  57. onUnload: function () {
  58. },
  59. /**
  60. * 页面相关事件处理函数--监听用户下拉动作
  61. */
  62. onPullDownRefresh: function () {
  63. },
  64. /**
  65. * 页面上拉触底事件的处理函数
  66. */
  67. onReachBottom: function () {
  68. if (this.data.hasNextPage) {
  69. let pn = this.data.pageNum
  70. this.setData({ loading: '加载中', 'pageNum': ++pn })
  71. this.queryList()
  72. }
  73. },
  74. /**
  75. * 用户点击右上角分享
  76. */
  77. onShareAppMessage: function () {
  78. },
  79. getDates: function (e) {
  80. this.setData({
  81. list: [],
  82. pageNum: 0,
  83. beginDate: e.detail[0],
  84. endDate: e.detail[1],
  85. loading: '加载中'
  86. })
  87. this.queryList()
  88. },
  89. queryList: function () {
  90. const urls = urlDef.urls;
  91. let stu = wx.getStorageSync('student');
  92. if (stu) {
  93. let params = { 'q.beginDate': this.data.beginDate, 'q.endDate': this.data.endDate, 'q.studentId': stu.studentId }
  94. params.pageNum = this.data.pageNum
  95. util.apiPost(urls.query_appointment_list, params).then(rs => {
  96. let list = rs.list
  97. list.map(o => {
  98. o.visitDate = o.visitDate.substring(0, 10)
  99. o.cancelFlag = this.canCancel(o) // 是否可以取消
  100. })
  101. this.setData({
  102. 'hasNextPage': rs.hasNextPage,
  103. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  104. 'list': this.data.list.concat(list)
  105. })
  106. })
  107. }
  108. },
  109. canCancel(item) { // 判断是否能取消, 未到预约时间前都能取消,至少提前1个小时
  110. let t = item.visitDate + ' ' + item.beginTime + ':00';
  111. let vdt = new Date(t.replace(/-/g,'/'));
  112. let tdt = new Date().getTime();
  113. if (vdt < tdt) {
  114. return false;
  115. }
  116. // const dayTime = 86400000;
  117. const dayTime = 3600000;
  118. return item.attend == 0 && (vdt - tdt) >= dayTime
  119. },
  120. doCancelQueue: function(e) {
  121. let id = e.currentTarget.dataset.id
  122. let that = this
  123. wx.showModal({
  124. title: '确认信息',
  125. content: '确定要取消本次排队?',
  126. showCancel: true,
  127. cancelText: "否",
  128. confirmText: "是",
  129. success: function (res) {
  130. if (res.cancel) {
  131. } else {
  132. wx.showLoading({
  133. title: '正在取消',
  134. mask: true
  135. })
  136. const urls = urlDef.urls;
  137. util.apiPost(urls.delete_queue, {'ids[]': [id]}).then(rs => {
  138. if (rs.message) {
  139. wx.showToast({ title: rs.message, icon: 'none' })
  140. return
  141. }
  142. wx.showToast({ title: '取消成功', icon: 'success' })
  143. that.setData({
  144. list: [],
  145. pageNum: 0,
  146. loading: '加载中'
  147. })
  148. that.queryList()
  149. })
  150. }
  151. }
  152. })
  153. },
  154. doCancel: function (e) {
  155. let id = e.currentTarget.dataset.id
  156. let that = this
  157. wx.showModal({
  158. title: '确认信息',
  159. content: '确定要取消本次预约?',
  160. showCancel: true,
  161. cancelText: "否",
  162. confirmText: "是",
  163. success: function (res) {
  164. if (res.cancel) {
  165. } else {
  166. wx.showLoading({
  167. title: '正在取消',
  168. mask: true
  169. })
  170. that.doRealCancel(id)
  171. }
  172. }
  173. })
  174. },
  175. doRealCancel: function (id) {
  176. const urls = urlDef.urls;
  177. util.apiPost(urls.cancel_appointment + '?id=' + id).then(rs => {
  178. if (rs.message) {
  179. wx.showToast({ title: rs.message, icon: 'none' })
  180. return
  181. }
  182. wx.showToast({ title: '取消成功', icon: 'success' })
  183. this.setData({
  184. list: [],
  185. pageNum: 0,
  186. loading: '加载中'
  187. })
  188. this.queryList()
  189. })
  190. }
  191. })