// pages/makePiano/makePiano.js const app = getApp() const util = require("../../utils/util") const urlDef = require("../../utils/urls") Page({ /** * 页面的初始数据 */ data: { animationBox: {}, animationBg: {}, weekList: [], curIndex: 0, array: [ '全部时间', '08:00 ~ 10:00', '10:00 ~ 12:00', '12:00 ~ 14:00', '14:00 ~ 16:00', '16:00 ~ 18:00', '18:00 ~ 20:00', '20:00 ~ 22:00', ], index: 0, schoolList: [ ], loading: '上拉加载', flag: 0, curStu: null, pageNum: 0, hasNextPage: true, schoolIndex: 0, timeScope: '0,0', yFlag: false }, getWeek: function (e) { this.setData({ curIndex: e.currentTarget.dataset.index, pageNum: 0, schoolList: [], }) this.queryList(); }, bindPickerChange: function (e) { this.setData({ index: e.detail.value }) }, selectTime: function () { let timeScope = '0,0' if (this.data.index > 0) { timeScope = this.data.array[this.data.index].replace(/\s*/g, '').replace('~', ',').replace(/:00/g,'') } this.setData({ timeScope: timeScope }) this.showSelect() this.setData({ pageNum: 0, schoolList: [] }) this.queryList() }, resetTime:function(){ let timeScope = '0,0' this.setData({ timeScope , index: 0}) this.showSelect() this.queryList() }, localtionMethod: function () { var that = this wx.getLocation({ type: 'wgs84', success(res) { // console.log(res) wx.setStorageSync('latlng', res) that.queryList() }, fail(res) { wx.hideLoading({ success: (res) => { wx.showModal({ title: '提示', content: "定位失败,请检查手机'位置服务'或GPS功能已开启并授权小程序位置信息", }) }, }) } }) }, showSelect: function () { var animation = wx.createAnimation({ timingFunction: 'linear', }) this.animation = animation var num = 0 var opacity = 0 if (this.data.yFlag == false) { num = 165 opacity = 0.4 this.setData({ yFlag: true }) } else { num = -360 opacity = 0 this.setData({ yFlag: false }) } animation.translateY(num).step() this.setData({ animationBox: animation.export() }) var animation2 = wx.createAnimation({ timingFunction: 'linear', }) this.animation2 = animation2 animation2.opacity(opacity).step() this.setData({ animationBg: animation2.export() }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var list = [] for (var i = 0; i < 7; i++) { var date = util.fun_date(i) var week = util.fun_week(date) var json = { date: date.substring(5, date.length), ds: date, // 日期 y-m-d ws: new Date(date).getDay(), // 星期 week: week } list.push(json) } this.setData({ weekList: list }) this.localtionMethod() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { if (this.data.hasNextPage) { let pn = this.data.pageNum this.setData({ loading: '加载中', 'pageNum': ++pn }) this.queryList() } }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, queryList: function () { const urls = urlDef.urls; let stu = wx.getStorageSync('student'); if (stu) { this.setData({ curStu: stu }) let latlng = wx.getStorageSync('latlng') let latitude = latlng.latitude //30.55473 let longitude = latlng.longitude let countyCode = '420101' let params = { 'q.coordinate': longitude + ',' + latitude, 'q.studentId': stu.studentId }; // 'q.regionId': countyCode.substring(0, 4) + '00' params['q.regionId'] = countyCode.substring(0, 4) + '00' params.pageNum = this.data.pageNum util.apiPost(urls.get_near_school, params).then(rs => { let list = rs.list; list.map(s => { s.dist = this.showDist(s.distance) }) this.setData({ 'hasNextPage': rs.hasNextPage, 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据', 'schoolList': this.data.schoolList.concat(list) }) // 默认查询第一个学校的课程 if (list && list.length > 0) { this.queryClassesList(list[0].id) } }) } }, showDist(d) { if (d <= 0) { return '无法定位'; } if (d > 1000) { return (d / 1000).toFixed(2) + 'km'; } return d + 'm'; }, selectSchool: function (e) { let index = e.currentTarget.dataset.index; let id = e.currentTarget.dataset.id; this.setData({ 'schoolIndex': index }) this.queryClassesList(id) }, collectSchool: function (e) { let id = e.currentTarget.dataset.id; const urls = urlDef.urls; util.apiPost(urls.collect_school + '?q.orgId=' + id + '&q.studentId=' + this.data.curStu.studentId).then((rs) => { this.setData({ pageNum: 0, schoolList: [] }) this.queryList() }); }, queryClassesList: function (sid) { const urls = urlDef.urls; let sl = this.data.schoolList; let s = sl.filter(o => o.id == sid)[0]; let w = this.data.weekList[this.data.curIndex]; let date = w.ds let week = w.ws let params = { 'q.orgId': sid, 'q.studentId': this.data.curStu.studentId, 'q.date': date, 'q.week': week, 'q.timeScope': this.data.timeScope } // params['q.timeScope'] = ''; 时段 util.apiPost(urls.query_school_attence, params).then(rs => { s.items = rs this.setData({ schoolList: sl }) }) }, doAppointment: function (e) { wx.showLoading({ title: '处理中', mask: true }) let id = e.currentTarget.dataset.id; const urls = urlDef.urls; let w = this.data.weekList[this.data.curIndex]; 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 => { if (rs.success > 0) { wx.showToast({ title: '预约成功' }) this.queryClassesList(this.data.curStu.orgId) } else { wx.showToast({ title: rs.msg, icon: 'none', }) } }); } })