makePiano.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. // pages/makePiano/makePiano.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. const key = 'FCLBZ-ZQ2Y3-DC23W-3EXRK-LUKX6-W7F6Z'; // 使用在腾讯位置服务申请的key
  6. const referer = '艾克斯朗学生端'; // 调用插件的app的名称
  7. const hotCitys = '武汉'; // 用户自定义的的热门城市
  8. const citySelector = requirePlugin('citySelector');
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. refreshFlag: 1,
  15. homeName: '',
  16. animationBox: {},
  17. animationBg: {},
  18. weekList: [],
  19. curIndex: 0,
  20. array: [
  21. // '全部时间',
  22. '08:00 ~ 10:00',
  23. '10:00 ~ 12:00',
  24. '12:00 ~ 14:00',
  25. '14:00 ~ 16:00',
  26. '16:00 ~ 18:00',
  27. '18:00 ~ 20:00',
  28. '20:00 ~ 22:00',
  29. ],
  30. index: -1,
  31. schoolList: [],
  32. loading: '加载中...',
  33. flag: 0,
  34. curStu: null,
  35. pageNum: 0,
  36. hasNextPage: true,
  37. schoolIndex: 0,
  38. timeScope: '0,0',
  39. yFlag: false,
  40. endDate: '2099-12-31',
  41. punishType: 0,
  42. maxLength: 2,
  43. },
  44. getTimeDate: function (e) {
  45. if (e.currentTarget.dataset.value == this.data.index) {
  46. this.setData({
  47. index: -1,
  48. })
  49. } else {
  50. this.setData({
  51. index: e.currentTarget.dataset.value,
  52. })
  53. }
  54. },
  55. getWeek: function (e) {
  56. this.setData({
  57. curIndex: e.currentTarget.dataset.index,
  58. pageNum: 0,
  59. schoolList: [],
  60. })
  61. this.queryList();
  62. },
  63. bindPickerChange: function (e) {
  64. this.setData({
  65. index: e.detail.value
  66. })
  67. },
  68. selectTime: function () {
  69. let timeScope = '0,0'
  70. if (this.data.index >= 0) {
  71. timeScope = this.data.array[this.data.index].replace(/\s*/g, '').replace('~', ',').replace(/:00/g, '')
  72. }
  73. this.setData({
  74. timeScope: timeScope
  75. })
  76. this.showSelect()
  77. this.setData({
  78. pageNum: 0,
  79. schoolList: []
  80. })
  81. this.queryList()
  82. },
  83. resetTime: function () {
  84. let timeScope = '0,0'
  85. this.setData({
  86. timeScope,
  87. index: -1,
  88. schoolList: []
  89. })
  90. this.showSelect()
  91. this.queryList()
  92. },
  93. localtionMethod: function () {
  94. const that = this
  95. wx.getLocation({
  96. type: 'wgs84',
  97. success(res) {
  98. that.locationAfter()
  99. },
  100. fail(res) {
  101. wx.hideLoading({
  102. success: (res) => {
  103. wx.showModal({
  104. title: '提示',
  105. content: "定位失败,请检查手机'位置服务'或GPS功能已开启并授权小程序位置信息",
  106. success(res) {
  107. if (res.confirm) {
  108. wx.openSetting({
  109. success(res) {
  110. console.log(res.authSetting)
  111. // res.authSetting = {
  112. // "scope.userInfo": true,
  113. // "scope.userLocation": true
  114. // }
  115. }
  116. })
  117. } else {
  118. wx.navigateBack({
  119. delta: 1,
  120. })
  121. }
  122. }
  123. })
  124. },
  125. })
  126. }
  127. })
  128. },
  129. showSelect: function () {
  130. var animation = wx.createAnimation({
  131. timingFunction: 'linear',
  132. })
  133. this.animation = animation
  134. var num = 0
  135. var opacity = 0
  136. if (this.data.yFlag == false) {
  137. num = -300
  138. opacity = 0.4
  139. this.setData({
  140. yFlag: true
  141. })
  142. } else {
  143. num = 165
  144. opacity = 0
  145. this.setData({
  146. yFlag: false
  147. })
  148. }
  149. animation.translateX(num).step()
  150. this.setData({
  151. animationBox: animation.export()
  152. })
  153. var animation2 = wx.createAnimation({
  154. timingFunction: 'linear',
  155. })
  156. this.animation2 = animation2
  157. animation2.opacity(opacity).step()
  158. this.setData({
  159. animationBg: animation2.export()
  160. })
  161. },
  162. /**
  163. * 生命周期函数--监听页面加载
  164. */
  165. onLoad: function (options) {
  166. var list = []
  167. for (var i = 0; i < 7; i++) {
  168. var date = util.fun_date(i)
  169. var week = util.fun_week(date)
  170. var json = {
  171. date: date.substring(5, date.length),
  172. ds: date, // 日期 y-m-d
  173. ws: new Date(date).getDay(), // 星期
  174. week: week
  175. }
  176. list.push(json)
  177. }
  178. this.setData({
  179. weekList: list,
  180. homeName: wx.getStorageSync('wxLocalName'),
  181. maxLength:parseInt(options.maxLength)
  182. })
  183. },
  184. /**
  185. * 生命周期函数--监听页面初次渲染完成
  186. */
  187. onReady: function () {
  188. },
  189. /**
  190. * 生命周期函数--监听页面显示
  191. */
  192. onShow: function () {
  193. this.localtionMethod()
  194. },
  195. locationAfter: function () {
  196. const selectedCity = citySelector.getCity();
  197. if (selectedCity) {
  198. this.setData({
  199. homeName: selectedCity.fullname,
  200. schoolList: []
  201. })
  202. wx.setStorageSync('latlng', selectedCity.location)
  203. wx.setStorageSync('adCode', selectedCity.id)
  204. wx.setStorageSync('wxLocalName', selectedCity.fullname)
  205. } else {
  206. if (wx.getStorageSync('latlng')) {
  207. this.setData({
  208. homeName: wx.getStorageSync('wxLocalName')
  209. })
  210. } else {
  211. this.selectCity()
  212. }
  213. }
  214. if (this.data.refreshFlag == 1) {
  215. this.setData({
  216. schoolList: [],
  217. refreshFlag: 0
  218. })
  219. this.queryList()
  220. }
  221. },
  222. selectCity: function () {
  223. wx.navigateTo({
  224. url: `plugin://citySelector/index?key=${key}&referer=${referer}&hotCitys=${hotCitys}`,
  225. })
  226. this.setData({
  227. refreshFlag: 1
  228. })
  229. },
  230. /**
  231. * 生命周期函数--监听页面隐藏
  232. */
  233. onHide: function () {
  234. },
  235. /**
  236. * 生命周期函数--监听页面卸载
  237. */
  238. onUnload: function () {
  239. },
  240. /**
  241. * 页面相关事件处理函数--监听用户下拉动作
  242. */
  243. onPullDownRefresh: function () {
  244. },
  245. /**
  246. * 页面上拉触底事件的处理函数
  247. */
  248. onReachBottom: function () {
  249. if (this.data.hasNextPage) {
  250. let pn = this.data.pageNum
  251. this.setData({
  252. loading: '加载中',
  253. 'pageNum': ++pn
  254. })
  255. this.queryList()
  256. }
  257. },
  258. /**
  259. * 用户点击右上角分享
  260. */
  261. onShareAppMessage: function () {
  262. },
  263. queryList: function () {
  264. const urls = urlDef.urls;
  265. let stu = wx.getStorageSync('student');
  266. if (stu) {
  267. this.setData({
  268. curStu: stu,
  269. })
  270. let latlng = wx.getStorageSync('latlng')
  271. let latitude = latlng.latitude //30.55473
  272. let longitude = latlng.longitude
  273. // let countyCode = '420101'
  274. let countyCode = wx.getStorageSync('adCode')
  275. let params = {
  276. 'q.coordinate': longitude + ',' + latitude,
  277. 'q.studentId': stu.studentId
  278. };
  279. // 'q.regionId': countyCode.substring(0, 4) + '00'
  280. params['q.regionId'] = countyCode.substring(0, 4) + '00'
  281. params.pageNum = this.data.pageNum
  282. util.apiPost(urls.get_near_school, params).then(rs => {
  283. let list = rs.list;
  284. list.map(s => {
  285. s.dist = this.showDist(s.distance)
  286. })
  287. const schoolNum = "(" + list.length + ")"
  288. this.setData({
  289. 'hasNextPage': rs.hasNextPage,
  290. 'loading': rs.hasNextPage ? '上拉加载' : '没有更多数据',
  291. 'schoolList': this.data.schoolList.concat(list),
  292. schoolNum
  293. })
  294. // 默认查询第一个学校的课程
  295. if (list && list.length > 0) {
  296. this.queryClassesList(list[0].id)
  297. }
  298. })
  299. }
  300. },
  301. showDist(d) {
  302. if (d <= 0) {
  303. return '无法定位';
  304. }
  305. if (d > 1000) {
  306. return (d / 1000).toFixed(2) + 'km';
  307. }
  308. return d + 'm';
  309. },
  310. selectSchool: function (e) {
  311. let index = e.currentTarget.dataset.index;
  312. // let id = e.currentTarget.dataset.id;
  313. // this.setData({
  314. // 'schoolIndex': index
  315. // })
  316. // this.queryClassesList(id)
  317. let moreFlag = 'schoolList[' + index + '].moreFlag'
  318. if (this.data.schoolList[index].moreFlag) {
  319. this.setData({
  320. [moreFlag]: false
  321. })
  322. } else {
  323. this.setData({
  324. [moreFlag]: true
  325. })
  326. }
  327. },
  328. collectSchool: function (e) {
  329. let id = e.currentTarget.dataset.id;
  330. const urls = urlDef.urls;
  331. util.apiPost(urls.collect_school + '?q.orgId=' + id + '&q.studentId=' + this.data.curStu.studentId).then((rs) => {
  332. this.setData({
  333. pageNum: 0,
  334. schoolList: []
  335. })
  336. this.queryList()
  337. });
  338. },
  339. queryClassesList: function (sid) {
  340. const urls = urlDef.urls;
  341. let sl = this.data.schoolList;
  342. for (var i in sl) {
  343. let s = sl.filter(o => o.id == this.data.schoolList[i].id)[0];
  344. let w = this.data.weekList[this.data.curIndex];
  345. let date = w.ds
  346. let week = w.ws + 1;
  347. let params = {
  348. 'q.orgId': this.data.schoolList[i].id,
  349. 'q.studentId': this.data.curStu.studentId,
  350. 'q.date': date,
  351. 'q.week': week,
  352. 'q.timeScope': this.data.timeScope
  353. }
  354. // params['q.timeScope'] = ''; 时段
  355. if (i == 0) {
  356. util.apiPost(urls.query_school_attence, params).then(rs => {
  357. s.moreFlag = true
  358. s.items = rs
  359. if(rs[0].endDate){
  360. this.setData({
  361. endDate: rs[0].endDate,
  362. })
  363. }
  364. if(rs[0].punishType){
  365. this.setData({
  366. punishType: rs[0].punishType
  367. })
  368. }
  369. this.setData({
  370. schoolList: sl,
  371. })
  372. })
  373. } else {
  374. util.apiPost(urls.query_school_attence, params).then(rs => {
  375. for (var j in rs) {
  376. if (rs[j].studentVisitNum > 0 || rs[j].studentWaitNum > 0) {
  377. s.moreFlag = true
  378. break
  379. } else {
  380. s.moreFlag = false
  381. }
  382. }
  383. if (s.collect == 1) {
  384. s.moreFlag = true
  385. }
  386. s.items = rs
  387. this.setData({
  388. schoolList: sl
  389. })
  390. })
  391. }
  392. }
  393. },
  394. doAppointment: function (e) {
  395. if (this.data.punishType == 1) {
  396. if (this.data.maxLength >= 1) {
  397. wx.hideLoading({
  398. success: (res) => {},
  399. })
  400. wx.showModal({
  401. title: '提示',
  402. content: '预约上限已满',
  403. showCancel: false, //是否显示取消按钮
  404. cancelText: "否", //默认是“取消”
  405. cancelColor: '#999999', //取消文字的颜色
  406. confirmText: "确定", //默认是“确定”
  407. // confirmColor: 'skyblue', //确定文字的颜色
  408. })
  409. return
  410. }
  411. } else if (this.data.punishType == 2) {
  412. let date = new Date()
  413. const year = date.getFullYear()
  414. const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
  415. const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
  416. const curDate = year + '/' + month + "/" + day
  417. let endDate = this.data.endDate.replace(/-/g, '/')
  418. if (curDate <= endDate) {
  419. let newEndDate = year + '年' + this.data.endDate.substring(5, 7) + '月' + this.data.endDate.substring(8, 10) + '日'
  420. wx.showModal({
  421. title: '提示',
  422. content: newEndDate + '前不可预约课程',
  423. showCancel: false, //是否显示取消按钮
  424. cancelText: "否", //默认是“取消”
  425. cancelColor: '#999999', //取消文字的颜色
  426. confirmText: "确定", //默认是“确定”
  427. // confirmColor: 'skyblue', //确定文字的颜色
  428. })
  429. return
  430. }
  431. }
  432. wx.showLoading({
  433. title: '处理中',
  434. mask: true
  435. })
  436. let id = e.currentTarget.dataset.id;
  437. const index = e.currentTarget.dataset.index
  438. const cIndex = e.currentTarget.dataset.cindex
  439. if (this.data.schoolList[index].items[cIndex].hasVisitNum >= this.data.schoolList[index].items[cIndex].maxNum) {
  440. wx.hideLoading({
  441. success: (res) => {
  442. wx.showToast({
  443. title: '预约上限已满',
  444. icon: 'none'
  445. })
  446. },
  447. })
  448. return
  449. }
  450. const urls = urlDef.urls;
  451. let w = this.data.weekList[this.data.curIndex];
  452. let sid = this.data.schoolList[index].id
  453. util.apiPost(urls.do_appointment + '?q.studentId=' + this.data.curStu.studentId + '&q.planId=' + id + '&q.orgId=' + sid + '&q.visitDate=' + w.ds).then(rs => {
  454. if (rs.success > 0) {
  455. wx.showToast({
  456. title: '预约成功'
  457. })
  458. this.queryClassesList(this.data.curStu.orgId)
  459. } else {
  460. wx.showToast({
  461. title: rs.msg,
  462. icon: 'none',
  463. duration: 3000
  464. })
  465. // this.queryList()
  466. }
  467. });
  468. },
  469. toQueueUp(e) {
  470. let id = e.currentTarget.dataset.id;
  471. let index = e.currentTarget.dataset.index
  472. let w = this.data.weekList[this.data.curIndex];
  473. let sid = this.data.schoolList[index].id
  474. wx.navigateTo({
  475. url: '/pages/queue/queue?planId=' + id + '&orgId=' + sid + '&visitDate=' + w.ds
  476. })
  477. }
  478. })