piano.js 5.4 KB

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