piano.js 5.4 KB

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