123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522 |
- // pages/makePiano/makePiano.js
- const app = getApp()
- const util = require("../../utils/util")
- const urlDef = require("../../utils/urls")
- const key = 'FCLBZ-ZQ2Y3-DC23W-3EXRK-LUKX6-W7F6Z'; // 使用在腾讯位置服务申请的key
- const referer = '艾克斯朗学生端'; // 调用插件的app的名称
- const hotCitys = '武汉'; // 用户自定义的的热门城市
- const citySelector = requirePlugin('citySelector');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- refreshFlag: 1,
- homeName: '',
- 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: -1,
- schoolList: [],
- loading: '加载中...',
- flag: 0,
- curStu: null,
- pageNum: 0,
- hasNextPage: true,
- schoolIndex: 0,
- timeScope: '0,0',
- yFlag: false,
- endDate: '2099-12-31',
- punishType: 0,
- maxLength: 2,
- },
- getTimeDate: function (e) {
- if (e.currentTarget.dataset.value == this.data.index) {
- this.setData({
- index: -1,
- })
- } else {
- this.setData({
- index: e.currentTarget.dataset.value,
- })
- }
- },
- 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: -1,
- schoolList: []
- })
- this.showSelect()
- this.queryList()
- },
- localtionMethod: function () {
- const that = this
- wx.getLocation({
- type: 'wgs84',
- success(res) {
- that.locationAfter()
- },
- fail(res) {
- wx.hideLoading({
- success: (res) => {
- wx.showModal({
- title: '提示',
- content: "定位失败,请检查手机'位置服务'或GPS功能已开启并授权小程序位置信息",
- success(res) {
- if (res.confirm) {
- wx.openSetting({
- success(res) {
- console.log(res.authSetting)
- // res.authSetting = {
- // "scope.userInfo": true,
- // "scope.userLocation": true
- // }
- }
- })
- } else {
- wx.navigateBack({
- delta: 1,
- })
- }
- }
- })
- },
- })
- }
- })
- },
- showSelect: function () {
- var animation = wx.createAnimation({
- timingFunction: 'linear',
- })
- this.animation = animation
- var num = 0
- var opacity = 0
- if (this.data.yFlag == false) {
- num = -300
- opacity = 0.4
- this.setData({
- yFlag: true
- })
- } else {
- num = 165
- opacity = 0
- this.setData({
- yFlag: false
- })
- }
- animation.translateX(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,
- homeName: wx.getStorageSync('wxLocalName'),
- maxLength:parseInt(options.maxLength)
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.localtionMethod()
- },
- locationAfter: function () {
- const selectedCity = citySelector.getCity();
- if (selectedCity) {
- this.setData({
- homeName: selectedCity.fullname,
- schoolList: []
- })
- wx.setStorageSync('latlng', selectedCity.location)
- wx.setStorageSync('adCode', selectedCity.id)
- wx.setStorageSync('wxLocalName', selectedCity.fullname)
- } else {
- if (wx.getStorageSync('latlng')) {
- this.setData({
- homeName: wx.getStorageSync('wxLocalName')
- })
- } else {
- this.selectCity()
- }
- }
- if (this.data.refreshFlag == 1) {
- this.setData({
- schoolList: [],
- refreshFlag: 0
- })
- this.queryList()
- }
- },
- selectCity: function () {
- wx.navigateTo({
- url: `plugin://citySelector/index?key=${key}&referer=${referer}&hotCitys=${hotCitys}`,
- })
- this.setData({
- refreshFlag: 1
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- 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 countyCode = wx.getStorageSync('adCode')
- 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)
- })
- const schoolNum = "(" + list.length + ")"
- this.setData({
- 'hasNextPage': rs.hasNextPage,
- 'loading': rs.hasNextPage ? '上拉加载' : '没有更多数据',
- 'schoolList': this.data.schoolList.concat(list),
- schoolNum
- })
- // 默认查询第一个学校的课程
- 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)
- let moreFlag = 'schoolList[' + index + '].moreFlag'
- if (this.data.schoolList[index].moreFlag) {
- this.setData({
- [moreFlag]: false
- })
- } else {
- this.setData({
- [moreFlag]: true
- })
- }
- },
- 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;
- for (var i in sl) {
- let s = sl.filter(o => o.id == this.data.schoolList[i].id)[0];
- let w = this.data.weekList[this.data.curIndex];
- let date = w.ds
- let week = w.ws + 1;
- let params = {
- 'q.orgId': this.data.schoolList[i].id,
- 'q.studentId': this.data.curStu.studentId,
- 'q.date': date,
- 'q.week': week,
- 'q.timeScope': this.data.timeScope
- }
- // params['q.timeScope'] = ''; 时段
- if (i == 0) {
- util.apiPost(urls.query_school_attence, params).then(rs => {
- s.moreFlag = true
- s.items = rs
- if(rs[0].endDate){
- this.setData({
- endDate: rs[0].endDate,
- })
- }
- if(rs[0].punishType){
- this.setData({
- punishType: rs[0].punishType
- })
- }
- this.setData({
- schoolList: sl,
- })
- })
- } else {
- util.apiPost(urls.query_school_attence, params).then(rs => {
- for (var j in rs) {
- if (rs[j].studentVisitNum > 0 || rs[j].studentWaitNum > 0) {
- s.moreFlag = true
- break
- } else {
- s.moreFlag = false
- }
- }
- if (s.collect == 1) {
- s.moreFlag = true
- }
- s.items = rs
- this.setData({
- schoolList: sl
- })
- })
- }
- }
- },
- doAppointment: function (e) {
- if (this.data.punishType == 1) {
- if (this.data.maxLength >= 1) {
- wx.hideLoading({
- success: (res) => {},
- })
- wx.showModal({
- title: '提示',
- content: '预约上限已满',
- showCancel: false, //是否显示取消按钮
- cancelText: "否", //默认是“取消”
- cancelColor: '#999999', //取消文字的颜色
- confirmText: "确定", //默认是“确定”
- // confirmColor: 'skyblue', //确定文字的颜色
- })
- return
- }
- } else if (this.data.punishType == 2) {
- let date = new Date()
- const year = date.getFullYear()
- const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
- const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
- const curDate = year + '/' + month + "/" + day
- let endDate = this.data.endDate.replace(/-/g, '/')
- if (curDate <= endDate) {
- let newEndDate = year + '年' + this.data.endDate.substring(5, 7) + '月' + this.data.endDate.substring(8, 10) + '日'
- wx.showModal({
- title: '提示',
- content: newEndDate + '前不可预约课程',
- showCancel: false, //是否显示取消按钮
- cancelText: "否", //默认是“取消”
- cancelColor: '#999999', //取消文字的颜色
- confirmText: "确定", //默认是“确定”
- // confirmColor: 'skyblue', //确定文字的颜色
- })
- return
- }
- }
- wx.showLoading({
- title: '处理中',
- mask: true
- })
- let id = e.currentTarget.dataset.id;
- const index = e.currentTarget.dataset.index
- const cIndex = e.currentTarget.dataset.cindex
- if (this.data.schoolList[index].items[cIndex].hasVisitNum >= this.data.schoolList[index].items[cIndex].maxNum) {
- wx.hideLoading({
- success: (res) => {
- wx.showToast({
- title: '预约上限已满',
- icon: 'none'
- })
- },
- })
- return
- }
- const urls = urlDef.urls;
- let w = this.data.weekList[this.data.curIndex];
- let sid = this.data.schoolList[index].id
- util.apiPost(urls.do_appointment + '?q.studentId=' + this.data.curStu.studentId + '&q.planId=' + id + '&q.orgId=' + sid + '&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',
- duration: 3000
- })
- // this.queryList()
- }
- });
- },
- toQueueUp(e) {
- let id = e.currentTarget.dataset.id;
- let index = e.currentTarget.dataset.index
- let w = this.data.weekList[this.data.curIndex];
- let sid = this.data.schoolList[index].id
- wx.navigateTo({
- url: '/pages/queue/queue?planId=' + id + '&orgId=' + sid + '&visitDate=' + w.ds
- })
- }
- })
|