makePiano.js 6.7 KB

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