makePiano.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. // pages/makePiano/makePiano.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. animationBox: {},
  11. animationBg: {},
  12. weekList: [],
  13. curIndex: 0,
  14. array: [
  15. '全部时间',
  16. '08:00 ~ 10:00',
  17. '10:00 ~ 12:00',
  18. '12:00 ~ 14:00',
  19. '14:00 ~ 16:00',
  20. '16:00 ~ 18:00',
  21. '18:00 ~ 20:00',
  22. '20:00 ~ 22:00',
  23. ],
  24. objectArray: [
  25. {
  26. id: 0,
  27. name: '全部时间'
  28. },
  29. {
  30. id: 1,
  31. name: '08:00 ~ 10:00'
  32. },
  33. {
  34. id: 2,
  35. name: '10:00 ~ 12:00'
  36. },
  37. {
  38. id: 3,
  39. name: '12:00 ~ 14:00'
  40. },
  41. {
  42. id: 4,
  43. name: '14:00 ~ 16:00'
  44. },
  45. {
  46. id: 5,
  47. name: '16:00 ~ 18:00'
  48. },
  49. {
  50. id: 6,
  51. name: '18:00 ~ 20:00'
  52. },
  53. {
  54. id: 7,
  55. name: '20:00 ~ 22:00'
  56. }
  57. ],
  58. index: 0,
  59. schoolList: [
  60. ],
  61. loading: '上拉加载',
  62. flag: 0,
  63. curStu: null,
  64. pageNum: 0,
  65. hasNextPage: true,
  66. schoolIndex: 0
  67. },
  68. getWeek: function (e) {
  69. this.setData({
  70. curIndex: e.currentTarget.dataset.index,
  71. pageNum: 0,
  72. schoolList: [],
  73. })
  74. this.queryList();
  75. },
  76. bindPickerChange: function (e) {
  77. this.setData({
  78. index: e.detail.value
  79. })
  80. },
  81. localtionMethod: function () {
  82. var that = this
  83. wx.getLocation({
  84. type: 'wgs84',
  85. success(res) {
  86. // console.log(res)
  87. wx.setStorageSync('latlng', res)
  88. that.queryList()
  89. },
  90. fail(res) {
  91. wx.hideLoading({
  92. success: (res) => {
  93. wx.showModal({
  94. title: '提示',
  95. content: "定位失败,请检查手机'位置服务'或GPS功能已开启并授权小程序位置信息",
  96. })
  97. },
  98. })
  99. }
  100. })
  101. },
  102. showSelect: function () {
  103. var animation = wx.createAnimation({
  104. timingFunction: 'linear',
  105. })
  106. this.animation = animation
  107. var num = 0
  108. var opacity = 0
  109. if (this.data.yFlag == false) {
  110. num = 165
  111. opacity = 0.4
  112. this.setData({
  113. yFlag: true
  114. })
  115. } else {
  116. num = -360
  117. opacity = 0
  118. this.setData({
  119. yFlag: false
  120. })
  121. }
  122. animation.translateY(num).step()
  123. this.setData({
  124. animationBox: animation.export()
  125. })
  126. var animation2 = wx.createAnimation({
  127. timingFunction: 'linear',
  128. })
  129. this.animation2 = animation2
  130. animation2.opacity(opacity).step()
  131. this.setData({
  132. animationBg: animation2.export()
  133. })
  134. },
  135. /**
  136. * 生命周期函数--监听页面加载
  137. */
  138. onLoad: function (options) {
  139. var list = []
  140. for (var i = 0; i < 7; i++) {
  141. var date = util.fun_date(i)
  142. var week = util.fun_week(date)
  143. var json = {
  144. date: date.substring(5, date.length),
  145. ds: date, // 日期 y-m-d
  146. ws: new Date(date).getDay(), // 星期
  147. week: week
  148. }
  149. list.push(json)
  150. }
  151. this.setData({
  152. weekList: list
  153. })
  154. this.localtionMethod()
  155. },
  156. /**
  157. * 生命周期函数--监听页面初次渲染完成
  158. */
  159. onReady: function () {
  160. },
  161. /**
  162. * 生命周期函数--监听页面显示
  163. */
  164. onShow: function () {
  165. },
  166. /**
  167. * 生命周期函数--监听页面隐藏
  168. */
  169. onHide: function () {
  170. },
  171. /**
  172. * 生命周期函数--监听页面卸载
  173. */
  174. onUnload: function () {
  175. },
  176. /**
  177. * 页面相关事件处理函数--监听用户下拉动作
  178. */
  179. onPullDownRefresh: function () {
  180. },
  181. /**
  182. * 页面上拉触底事件的处理函数
  183. */
  184. onReachBottom: function () {
  185. if (this.data.hasNextPage) {
  186. let pn = this.data.pageNum
  187. this.setData({ loading: '加载中', 'pageNum': ++pn })
  188. this.queryList()
  189. }
  190. },
  191. /**
  192. * 用户点击右上角分享
  193. */
  194. onShareAppMessage: function () {
  195. },
  196. queryList: function () {
  197. const urls = urlDef.urls;
  198. let stu = wx.getStorageSync('student');
  199. if (stu) {
  200. this.setData({ curStu: stu })
  201. let latlng = wx.getStorageSync('latlng')
  202. let latitude = latlng.latitude //30.55473
  203. let longitude = latlng.longitude
  204. let countyCode = '420101'
  205. let params = { 'q.coordinate': longitude + ',' + latitude, 'q.studentId': stu.studentId };
  206. // 'q.regionId': countyCode.substring(0, 4) + '00'
  207. params['q.regionId'] = countyCode.substring(0, 4) + '00'
  208. params.pageNum = this.data.pageNum
  209. util.apiPost(urls.get_near_school, params).then(rs => {
  210. let list = rs.list;
  211. list.map(s => {
  212. s.dist = this.showDist(s.distance)
  213. })
  214. this.setData({
  215. 'hasNextPage': rs.hasNextPage,
  216. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  217. 'schoolList': this.data.schoolList.concat(list)
  218. })
  219. // 默认查询第一个学校的课程
  220. if (list && list.length > 0) {
  221. this.queryClassesList(list[0].id)
  222. }
  223. })
  224. }
  225. },
  226. showDist(d) {
  227. if (d <= 0) {
  228. return '无法定位';
  229. }
  230. if (d > 1000) {
  231. return (d / 1000).toFixed(2) + 'km';
  232. }
  233. return d + 'm';
  234. },
  235. selectSchool: function (e) {
  236. let index = e.currentTarget.dataset.index;
  237. let id = e.currentTarget.dataset.id;
  238. this.setData({ 'schoolIndex': index })
  239. this.queryClassesList(id)
  240. },
  241. collectSchool: function (e) {
  242. let id = e.currentTarget.dataset.id;
  243. const urls = urlDef.urls;
  244. util.apiPost(urls.collect_school + '?q.orgId=' + id + '&q.studentId=' + this.data.curStu.studentId).then((rs) => {
  245. this.setData({
  246. pageNum: 0,
  247. schoolList: []
  248. })
  249. this.queryList()
  250. });
  251. },
  252. queryClassesList: function (sid) {
  253. const urls = urlDef.urls;
  254. let sl = this.data.schoolList;
  255. let s = sl.filter(o => o.id == sid)[0];
  256. let w = this.data.weekList[this.data.curIndex];
  257. let date = w.ds
  258. let week = w.ws
  259. let params = { 'q.orgId': sid, 'q.studentId': this.data.curStu.studentId, 'q.date': date, 'q.week': week }
  260. // params['q.timeScope'] = ''; 时段
  261. util.apiPost(urls.query_school_attence, params).then(rs => {
  262. s.items = rs
  263. this.setData({ schoolList: sl })
  264. })
  265. },
  266. doAppointment: function (e) {
  267. let id = e.currentTarget.dataset.id;
  268. const urls = urlDef.urls;
  269. let w = this.data.weekList[this.data.curIndex];
  270. util.apiPost(urls.do_appointment + '?q.studentId=' + this.data.curStu.studentId + '&q.planId=' + id + '&q.orgId=' + this.data.curStu.orgId + '&q.visitDate=' + w.ds).then(rs => {
  271. if (rs.success > 0) {
  272. wx.showToast({
  273. title: '预约成功'
  274. })
  275. this.queryClassesList(this.data.curStu.orgId)
  276. } else {
  277. wx.showToast({
  278. title: rs.msg,
  279. icon: 'none',
  280. })
  281. }
  282. });
  283. }
  284. })