makePiano.js 11 KB

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