piano.js 5.6 KB

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