makePiano.js 10 KB

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