piano.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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. nickName: '***',
  11. height: 400,
  12. firstLoad: wx.getStorageSync('firstLoad'),
  13. listHeight: 0,
  14. btnTop: 0,
  15. toTop: 0,
  16. animationBtn: {},
  17. animationChange: {},
  18. childTitle: '预约练琴',
  19. beginDate: null,
  20. endDate: null,
  21. list: [],
  22. loading: '加载中...',
  23. flag: 0,
  24. pageNum: 0,
  25. hasNextPage: true,
  26. type: '',
  27. ruleShow: false,
  28. bgShow: false,
  29. curStuId: '',
  30. orgIndex: 0,
  31. beginDate: '2020-01-01',
  32. endDate: '2021-02-02',
  33. initDate: '2020-01-01',
  34. lastDate: '',
  35. yFlag: false,
  36. animationBox: {},
  37. animationBg: {},
  38. typeArr: ['全部', '已预约', '排队中'],
  39. typeIndex: 0,
  40. str: {},
  41. selectHeight: 1000,
  42. },
  43. getCurStu: function (e) {
  44. let curStuId = e.currentTarget.dataset.id
  45. this.setData({
  46. curStuId
  47. })
  48. },
  49. ruleShow: function () {
  50. if (this.data.ruleShow) {
  51. this.setData({
  52. ruleShow: false,
  53. })
  54. } else {
  55. this.setData({
  56. ruleShow: true,
  57. })
  58. }
  59. },
  60. getPiano: function () {
  61. wx.navigateTo({
  62. url: '/pages/makePiano/makePiano',
  63. })
  64. },
  65. autoLogin: function () {
  66. var openId = wx.getStorageSync('openId')
  67. util.doPost(
  68. 'autoLogin', {
  69. openId,
  70. }
  71. ).then(rs => {
  72. if (rs.success > 0) {
  73. wx.setStorageSync('sso-token', rs.data.token);
  74. this.loadIndexData()
  75. // this.queryList();
  76. } else {
  77. wx.showToast({
  78. title: rs.errMsg,
  79. icon: 'none',
  80. duration: 3000
  81. })
  82. }
  83. })
  84. },
  85. /**
  86. * 生命周期函数--监听页面加载
  87. */
  88. onLoad: function (options) {
  89. var query = wx.createSelectorQuery();
  90. query.select('#change-view').boundingClientRect()
  91. query.exec(res => {
  92. this.setData({
  93. selectHeight: res[0].height,
  94. })
  95. })
  96. // 显示近7天的预约记录
  97. let now = new Date();
  98. let bd = util.formatTime(now).substring(0, 10).replace(/\//g, '-')
  99. let edd = new Date(now.setDate(now.getDate() + 7));
  100. let ed = util.formatTime(edd).substring(0, 10).replace(/\//g, '-')
  101. this.setData({
  102. beginDate: bd,
  103. endDate: ed,
  104. list: []
  105. });
  106. // end
  107. this.initDate()
  108. },
  109. initDate: function () {
  110. var date = new Date()
  111. const year = date.getFullYear()
  112. const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
  113. const day = date.getDate() + 1 < 10 ? '0' + date.getDate() : date.getDate()
  114. let now = new Date();
  115. let edd = new Date(now.setDate(now.getDate() + 7));
  116. let ed = util.formatTime(edd).substring(0, 10).replace(/\//g, '-')
  117. this.setData({
  118. endDate: year + '-' + month + '-' + day,
  119. lastDate: year + '-' + month + '-' + day,
  120. initChangeDate: ed
  121. })
  122. const token = wx.getStorageSync('sso-token')
  123. if (!token) {
  124. this.autoLogin()
  125. } else {
  126. this.loadIndexData()
  127. }
  128. if (this.data.firstLoad) {
  129. this.showChange()
  130. this.setData({
  131. bgShow: true
  132. })
  133. }
  134. },
  135. /**
  136. * 生命周期函数--监听页面初次渲染完成
  137. */
  138. onReady: function () {},
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow: function () {
  143. this.setData({
  144. firstLoad: wx.getStorageSync('firstLoad')
  145. })
  146. if (!this.data.firstLoad) {
  147. this.setData({
  148. list: []
  149. })
  150. this.queryList()
  151. }
  152. },
  153. /**
  154. * 生命周期函数--监听页面隐藏
  155. */
  156. onHide: function () {
  157. },
  158. /**
  159. * 生命周期函数--监听页面卸载
  160. */
  161. onUnload: function () {
  162. wx.setStorageSync('firstLoad', true)
  163. },
  164. /**
  165. * 页面相关事件处理函数--监听用户下拉动作
  166. */
  167. onPullDownRefresh: function () {
  168. },
  169. // onPageScroll:function(e){
  170. // const that = this
  171. // that.hideBtn()
  172. // that.setData({
  173. // scrollTop:e.scrollTop,
  174. // scrollIng:true
  175. // })
  176. // let timer= setTimeout(()=>{
  177. // if(that.data.scrollTop===e.scrollTop){
  178. // that.setData({
  179. // scrollTop:e.scrollTop,
  180. // scrollIng:false
  181. // })
  182. // console.log('滚动结束')
  183. // that.showBtn()
  184. // clearTimeout(timer)
  185. // }
  186. // },1000)
  187. // },
  188. getChange: function () {
  189. if (!this.data.bgShow) {
  190. this.setData({
  191. yFlag: true
  192. })
  193. this.showSelect()
  194. this.showChange()
  195. } else {
  196. this.hideChange()
  197. }
  198. this.setData({
  199. bgShow: !this.data.bgShow
  200. })
  201. },
  202. showChange: function () {
  203. var animationChange = wx.createAnimation({
  204. timingFunction: 'linear',
  205. duration: 600
  206. })
  207. this.animationChange = animationChange
  208. let right = this.data.height
  209. animationChange.translateY(right).step()
  210. this.setData({
  211. animationChange: animationChange.export(),
  212. })
  213. },
  214. hideChange: function () {
  215. var animationChange = wx.createAnimation({
  216. timingFunction: 'linear',
  217. duration: 800
  218. })
  219. this.animationChange = animationChange
  220. let right = -this.data.height
  221. animationChange.translateY(right).step()
  222. this.setData({
  223. animationChange: animationChange.export(),
  224. })
  225. },
  226. changeStuBtn: function () {
  227. this.setData({
  228. bgShow: false
  229. })
  230. this.hideChange()
  231. },
  232. hideBtn: function () { //淡化切换学生按钮
  233. var animationBtn = wx.createAnimation({
  234. timingFunction: 'linear',
  235. duration: 10000
  236. })
  237. this.animationBtn = animationBtn
  238. let opacity = 0.3
  239. animationBtn.opacity(opacity).step()
  240. this.setData({
  241. animationBtn: animationBtn.export()
  242. })
  243. },
  244. showBtn: function () { //正常显示学生切换按钮
  245. var animationBtn = wx.createAnimation({
  246. timingFunction: 'linear',
  247. duration: 800
  248. })
  249. this.animationBtn = animationBtn
  250. let opacity = 1
  251. animationBtn.opacity(opacity).step()
  252. this.setData({
  253. animationBtn: animationBtn.export()
  254. })
  255. },
  256. /**
  257. * 页面上拉触底事件的处理函数
  258. */
  259. onReachBottom: function () {
  260. if (this.data.hasNextPage) {
  261. let pn = this.data.pageNum
  262. this.setData({
  263. loading: '加载中',
  264. 'pageNum': ++pn
  265. })
  266. this.queryList()
  267. }
  268. },
  269. /**
  270. * 用户点击右上角分享
  271. */
  272. onShareAppMessage: function () {
  273. },
  274. getDates: function (e) {
  275. this.setData({
  276. list: [],
  277. pageNum: 0,
  278. beginDate: e[0],
  279. endDate: e[1],
  280. type: this.data.typeIndex == 0 ? '' : this.data.typeIndex,
  281. loading: '加载中'
  282. })
  283. this.queryList()
  284. },
  285. queryList: function () {
  286. const urls = urlDef.urls;
  287. let stu = wx.getStorageSync('student');
  288. if (stu) {
  289. let params = {
  290. 'q.beginDate': this.data.beginDate,
  291. 'q.endDate': this.data.endDate,
  292. 'q.studentId': stu.studentId,
  293. 'q.type': this.data.type
  294. }
  295. params.pageNum = this.data.pageNum
  296. util.apiPost(urls.query_appointment_list, params).then(rs => {
  297. let list = rs.list
  298. list.map(o => {
  299. o.visitDate = o.visitDate.substring(0, 10)
  300. o.cancelFlag = this.canCancel(o) // 是否可以取消
  301. })
  302. this.setData({
  303. 'hasNextPage': rs.hasNextPage,
  304. 'loading': rs.hasNextPage ? '上拉加载' : '没有更多数据',
  305. 'list': this.data.list.concat(list)
  306. })
  307. if (this.data.firstLoad) {
  308. this.getCount()
  309. }
  310. })
  311. }
  312. },
  313. getCount: function () {
  314. const urls = urlDef.urls;
  315. let stu = wx.getStorageSync('student');
  316. util.apiPost(urls.query_appointment_count, {
  317. 'q.studentId': stu.studentId
  318. }).then(rs => {
  319. if (rs[0] <= 0) {
  320. this.setData({
  321. ruleShow: true
  322. })
  323. }
  324. })
  325. },
  326. loadIndexData: function () {
  327. this.setData({
  328. 'stuShowList': [],
  329. 'teaShowList': [],
  330. })
  331. const urls = urlDef.urls;
  332. //获取登录用户数据, 并加载首页数据
  333. util.apiPost(urls.get_cur_user, {}).then(rs => {
  334. // console.log(JSON.stringify(rs));
  335. let userItems = rs.attr.others
  336. let orgItems = []
  337. let student = {}
  338. userItems.forEach(u => {
  339. let exists = false;
  340. orgItems.some(o => {
  341. if (o.orgId === u.orgId) {
  342. exists = true;
  343. return true;
  344. }
  345. })
  346. if (!exists) {
  347. orgItems.push({
  348. orgId: u.orgId,
  349. orgName: u.orgName
  350. })
  351. }
  352. if (u.studentId === rs.attr.personId) { // 当前用户
  353. const headImg = u.imageUrl ? urls.oss_file + 'image/' + u.imageUrl : '/images/head.png';
  354. student = {
  355. studentId: u.studentId,
  356. orgId: u.orgId,
  357. orgName: u.orgName,
  358. name: u.studentName,
  359. sex: u.sex,
  360. headImg: headImg
  361. }
  362. this.setData({
  363. 'curStu': student,
  364. })
  365. // 放入 strong中
  366. wx.setStorageSync('student', student);
  367. }
  368. })
  369. for (var i in userItems) {
  370. userItems[i].headName = userItems[i].studentName.substring(userItems[i].studentName.length - 1, userItems[i].studentName.length)
  371. userItems[i].nickName = userItems[i].studentName.substring(0, 1) + "*" + userItems[i].studentName.substring(userItems[i].studentName.length - 1, userItems[i].studentName.length)
  372. }
  373. for (var j in orgItems) {
  374. if (this.data.curStu.orgId == orgItems[j].orgId) {
  375. const tempName = this.data.curStu.name.substring(0, 1) + "*" + this.data.curStu.name.substring( this.data.curStu.name.length - 1, this.data.curStu.name.length)
  376. this.setData({
  377. orgIndex: j,
  378. curStuId: this.data.curStu.studentId,
  379. nickName: tempName
  380. })
  381. break
  382. }
  383. }
  384. this.setData({
  385. 'userItems': userItems,
  386. 'orgItems': orgItems
  387. })
  388. this.queryList()
  389. });
  390. },
  391. //切换校区
  392. bindPickerChangeSchool: function (e) {
  393. let i = e.detail.value;
  394. if (i == this.data.orgIndex) {
  395. console.log('无须切换...');
  396. return;
  397. }
  398. // 取该校区 第1位学生 作为默认登录用户
  399. let targetId = this.data.orgItems[i].orgId;
  400. this.data.userItems.some(u => {
  401. if (u.orgId === targetId) {
  402. this.doChangeUser(u.studentId);
  403. this.setData({
  404. orgIndex: i,
  405. sid: u.studentId,
  406. list: [],
  407. loading: '加载中...',
  408. firstLoad: true
  409. });
  410. return true;
  411. }
  412. });
  413. },
  414. //切换身份
  415. changeStu: function (e) {
  416. let sid = e.currentTarget.dataset.id;
  417. this.doChangeUser(sid);
  418. },
  419. doChangeUser: function (sid) {
  420. if (this.data.curStu.studentId == sid) {
  421. console.log('无须切换')
  422. return;
  423. }
  424. wx.showLoading({
  425. title: '正在切换用户',
  426. mask: true
  427. })
  428. const urls = urlDef.urls;
  429. util.apiPost(urls.change_user, {
  430. targetId: sid
  431. }).then(rs => {
  432. wx.hideLoading();
  433. if (rs === 1) {
  434. console.log('切换成功');
  435. this.setData({
  436. curStuId: sid,
  437. list: [],
  438. loading: '加载中...',
  439. firstLoad: true
  440. })
  441. this.loadIndexData();
  442. } else {
  443. wx.showToast({
  444. title: '切换失败,请稍后重试',
  445. icon: 'none'
  446. })
  447. }
  448. });
  449. },
  450. canCancel(item) { // 判断是否能取消, 未到预约时间前都能取消,至少提前1个小时
  451. let t = item.visitDate + ' ' + item.beginTime + ':00';
  452. let vdt = new Date(t.replace(/-/g, '/'));
  453. let tdt = new Date().getTime();
  454. if (vdt < tdt) {
  455. return false;
  456. }
  457. // const dayTime = 86400000;
  458. const dayTime = 3600000;
  459. return item.attend == 0 && (vdt - tdt) >= dayTime
  460. },
  461. doCancelQueue: function (e) {
  462. let id = e.currentTarget.dataset.id
  463. let that = this
  464. wx.showModal({
  465. title: '确认信息',
  466. content: '确定要取消本次排队?',
  467. showCancel: true,
  468. cancelText: "否",
  469. confirmText: "是",
  470. success: function (res) {
  471. if (res.cancel) {} else {
  472. wx.showLoading({
  473. title: '正在取消',
  474. mask: true
  475. })
  476. const urls = urlDef.urls;
  477. util.apiPost(urls.delete_queue, {
  478. 'ids[]': [id]
  479. }).then(rs => {
  480. if (rs.message) {
  481. wx.showToast({
  482. title: rs.message,
  483. icon: 'none'
  484. })
  485. return
  486. }
  487. wx.showToast({
  488. title: '取消成功',
  489. icon: 'success'
  490. })
  491. that.setData({
  492. list: [],
  493. pageNum: 0,
  494. loading: '加载中'
  495. })
  496. that.queryList()
  497. })
  498. }
  499. }
  500. })
  501. },
  502. doCancel: function (e) {
  503. let id = e.currentTarget.dataset.id
  504. let that = this
  505. wx.showModal({
  506. title: '确认信息',
  507. content: '确定要取消本次预约?',
  508. showCancel: true,
  509. cancelText: "否",
  510. confirmText: "是",
  511. success: function (res) {
  512. if (res.cancel) {} else {
  513. wx.showLoading({
  514. title: '正在取消',
  515. mask: true
  516. })
  517. that.doRealCancel(id)
  518. }
  519. }
  520. })
  521. },
  522. doRealCancel: function (id) {
  523. const urls = urlDef.urls;
  524. util.apiPost(urls.cancel_appointment + '?id=' + id).then(rs => {
  525. if (rs.message) {
  526. wx.showToast({
  527. title: rs.message,
  528. icon: 'none'
  529. })
  530. return
  531. }
  532. wx.showToast({
  533. title: '取消成功',
  534. icon: 'success'
  535. })
  536. this.setData({
  537. list: [],
  538. pageNum: 0,
  539. loading: '加载中'
  540. })
  541. this.queryList()
  542. })
  543. },
  544. bindBeginDateChange: function (e) {
  545. if (e.detail.value > this.data.endDate) {
  546. this.setData({
  547. beginDate: this.data.endDate
  548. })
  549. } else {
  550. this.setData({
  551. beginDate: e.detail.value
  552. })
  553. }
  554. },
  555. bindEndDateChange: function (e) {
  556. if (e.detail.value > this.data.initChangeDate) {
  557. this.setData({
  558. endDate: this.data.initChangeDate
  559. })
  560. } else {
  561. this.setData({
  562. endDate: e.detail.value
  563. })
  564. }
  565. },
  566. resetDate: function () {
  567. this.setData({
  568. beginDate: this.data.initDate,
  569. endDate: this.data.initChangeDate,
  570. typeIndex: 0
  571. })
  572. const date = new Date()
  573. const dateArr = [date.getFullYear() + "-01" + "-01", this.data.initChangeDate];
  574. const typeIndex = this.data.typeIndex
  575. this.getDates(dateArr)
  576. // this.triggerEvent("getDates", {dateArr,typeIndex});
  577. this.showSelect()
  578. },
  579. submitDate: function () {
  580. const dateArr = [this.data.beginDate, this.data.endDate];
  581. // const typeIndex = this.data.typeIndex
  582. // this.triggerEvent("getDates", {dateArr,typeIndex});
  583. this.getDates(dateArr)
  584. this.showSelect()
  585. },
  586. showSelect: function () {
  587. var animation = wx.createAnimation({
  588. timingFunction: 'linear',
  589. duration: 600
  590. })
  591. this.animation = animation
  592. var num = 0
  593. var opacity = 0
  594. if (this.data.yFlag == false) {
  595. num = Math.abs(this.data.toTop) / 2 + this.data.selectHeight - 20
  596. opacity = 0.4
  597. this.setData({
  598. yFlag: true,
  599. bgShow: false
  600. })
  601. this.hideChange()
  602. } else {
  603. num = this.data.toTop
  604. opacity = 0
  605. this.setData({
  606. yFlag: false,
  607. })
  608. }
  609. animation.translateY(num).step()
  610. this.setData({
  611. animationBox: animation.export()
  612. })
  613. var animation2 = wx.createAnimation({
  614. timingFunction: 'linear',
  615. duration: 200
  616. })
  617. this.animation2 = animation2
  618. animation2.opacity(opacity).step()
  619. this.setData({
  620. animationBg: animation2.export()
  621. })
  622. },
  623. bindPickerChange: function (e) {
  624. const typeIndex = e.detail.value
  625. this.setData({
  626. typeIndex
  627. })
  628. // this.triggerEvent("changeType",str)
  629. },
  630. })
  631. // 历史课程
  632. // end