makePiano.js 6.9 KB

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