makePiano.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. toQueue:function(){
  144. wx.navigateTo({
  145. url: '/pages/queue/queue',
  146. })
  147. },
  148. /**
  149. * 生命周期函数--监听页面初次渲染完成
  150. */
  151. onReady: function () {
  152. },
  153. /**
  154. * 生命周期函数--监听页面显示
  155. */
  156. onShow: function () {
  157. },
  158. /**
  159. * 生命周期函数--监听页面隐藏
  160. */
  161. onHide: function () {
  162. },
  163. /**
  164. * 生命周期函数--监听页面卸载
  165. */
  166. onUnload: function () {
  167. },
  168. /**
  169. * 页面相关事件处理函数--监听用户下拉动作
  170. */
  171. onPullDownRefresh: function () {
  172. },
  173. /**
  174. * 页面上拉触底事件的处理函数
  175. */
  176. onReachBottom: function () {
  177. if (this.data.hasNextPage) {
  178. let pn = this.data.pageNum
  179. this.setData({ loading: '加载中', 'pageNum': ++pn })
  180. this.queryList()
  181. }
  182. },
  183. /**
  184. * 用户点击右上角分享
  185. */
  186. onShareAppMessage: function () {
  187. },
  188. queryList: function () {
  189. const urls = urlDef.urls;
  190. let stu = wx.getStorageSync('student');
  191. if (stu) {
  192. this.setData({ curStu: stu })
  193. let latlng = wx.getStorageSync('latlng')
  194. let latitude = latlng.latitude //30.55473
  195. let longitude = latlng.longitude
  196. let countyCode = '420101'
  197. let params = { 'q.coordinate': longitude + ',' + latitude, 'q.studentId': stu.studentId };
  198. // 'q.regionId': countyCode.substring(0, 4) + '00'
  199. params['q.regionId'] = countyCode.substring(0, 4) + '00'
  200. params.pageNum = this.data.pageNum
  201. util.apiPost(urls.get_near_school, params).then(rs => {
  202. let list = rs.list;
  203. list.map(s => {
  204. s.dist = this.showDist(s.distance)
  205. })
  206. this.setData({
  207. 'hasNextPage': rs.hasNextPage,
  208. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  209. 'schoolList': this.data.schoolList.concat(list)
  210. })
  211. // 默认查询第一个学校的课程
  212. if (list && list.length > 0) {
  213. this.queryClassesList(list[0].id)
  214. }
  215. })
  216. }
  217. },
  218. showDist(d) {
  219. if (d <= 0) {
  220. return '无法定位';
  221. }
  222. if (d > 1000) {
  223. return (d / 1000).toFixed(2) + 'km';
  224. }
  225. return d + 'm';
  226. },
  227. selectSchool: function (e) {
  228. let index = e.currentTarget.dataset.index;
  229. let id = e.currentTarget.dataset.id;
  230. this.setData({ 'schoolIndex': index })
  231. this.queryClassesList(id)
  232. },
  233. collectSchool: function (e) {
  234. let id = e.currentTarget.dataset.id;
  235. const urls = urlDef.urls;
  236. util.apiPost(urls.collect_school + '?q.orgId=' + id + '&q.studentId=' + this.data.curStu.studentId).then((rs) => {
  237. this.setData({
  238. pageNum: 0,
  239. schoolList: []
  240. })
  241. this.queryList()
  242. });
  243. },
  244. queryClassesList: function (sid) {
  245. const urls = urlDef.urls;
  246. let sl = this.data.schoolList;
  247. let s = sl.filter(o => o.id == this.data.schoolList[this.data.schoolIndex].id)[0];
  248. let w = this.data.weekList[this.data.curIndex];
  249. let date = w.ds
  250. let week = w.ws + 1;
  251. let params = { 'q.orgId': this.data.schoolList[this.data.schoolIndex].id, 'q.studentId': this.data.curStu.studentId, 'q.date': date, 'q.week': week, 'q.timeScope': this.data.timeScope }
  252. // params['q.timeScope'] = ''; 时段
  253. util.apiPost(urls.query_school_attence, params).then(rs => {
  254. s.items = rs
  255. this.setData({ schoolList: sl })
  256. })
  257. },
  258. doAppointment: function (e) {
  259. wx.showLoading({
  260. title: '处理中',
  261. mask: true
  262. })
  263. let id = e.currentTarget.dataset.id;
  264. const index = e.currentTarget.dataset.index
  265. const cIndex = e.currentTarget.dataset.cindex
  266. if(this.data.schoolList[index].items[cIndex].hasVisitNum >= this.data.schoolList[index].items[cIndex].maxNum){
  267. wx.hideLoading({
  268. success: (res) => {
  269. wx.showToast({
  270. title: '预约上限已满',
  271. icon: 'none'
  272. })
  273. },
  274. })
  275. return
  276. }
  277. const urls = urlDef.urls;
  278. let w = this.data.weekList[this.data.curIndex];
  279. let sid = this.data.schoolList[this.data.schoolIndex].id
  280. util.apiPost(urls.do_appointment + '?q.studentId=' + this.data.curStu.studentId + '&q.planId=' + id + '&q.orgId=' + sid + '&q.visitDate=' + w.ds).then(rs => {
  281. if (rs.success > 0) {
  282. wx.showToast({
  283. title: '预约成功'
  284. })
  285. this.queryClassesList(this.data.curStu.orgId)
  286. } else {
  287. wx.showToast({
  288. title: rs.msg,
  289. icon: 'none',
  290. })
  291. }
  292. });
  293. }
  294. })