// pages/bookClasses/index.js const app = getApp(); let weekday = [ '星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六' ]; let veneuType = ''; let venueId = ''; let isFrist = true; let clickDate = ''; Page({ /** * 页面的初始数据 */ data: { currentIndex: 1, calendar: [], venueLessons: [], isShowNewplot: false, isGoHome: false, }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { isFrist = false; veneuType = options.type; venueId = options.venueId; app.$api.venueLessonShow({ type: options.type, venueId: options.venueId }).then(res => { let list = []; let subList = []; let currentDate = new Date(new Date().setHours(8, 0, 0, 0)); let currentDateValue = '' for (let i = 0; i < res.lessons.length; i++) { if (i % 7 == 0 && i != 0) { list.push(subList); subList = []; } let obj = {} let date = new Date(res.lessons[i].dateList); obj.date = (date.getMonth() + 1) + '.' + date.getDate() obj.week = weekday[date.getDay()]; obj.value = res.lessons[i].dateList; obj.flg = res.lessons[i].flg; if (currentDate.getTime() == date.getTime()) { obj.isSelected = true; currentDateValue = obj.value; clickDate = obj.value; } subList.push(obj); } list.push(subList); subList = []; this.setData({ calendar: list, isShowNewplot: true, }) this.getData(currentDateValue); }, err => { this.setData({ isShowNewplot: true, }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { let pages = getCurrentPages(); this.setData({ isGoHome: pages.length == 1 }) }, /** * 生命周期函数--监听页面显示 */ onShow: function() { // if (isFrist) { // // clickDate = new // this.getData(clickDate); // } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { isFrist = true; }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { return { title: '预约课程' } }, // 向左划 leftClick() { if (this.data.currentIndex == 0) { return; } this.data.currentIndex--; this.setData({ currentIndex: this.data.currentIndex }) }, // 向右滑 rightClick() { if (this.data.currentIndex == this.data.calendar.length - 1) { return; } this.data.currentIndex++; this.setData({ currentIndex: this.data.currentIndex }) }, // 点击日历 clickItem(e) { let idx = e.currentTarget.dataset.idx; let index = e.currentTarget.dataset.index; for (let i = 0; i < this.data.calendar.length; i++) { for (let j = 0; j < this.data.calendar[i].length; j++) { if (index == i && idx == j) { this.data.calendar[i][j].isSelected = true; } else { this.data.calendar[i][j].isSelected = false; } } } this.setData({ calendar: this.data.calendar }) clickDate = this.data.calendar[index][idx].value; this.getData(this.data.calendar[index][idx].value); }, // 跳转详情 clickCell(e) { let id = e.currentTarget.dataset.id; wx.navigateTo({ url: `/pages/bookClassesDetail/index?id=${id}`, success: function(res) {}, fail: function(res) {}, complete: function(res) {}, }) }, getData(date) { wx.showLoading({ title: '加载中...', mask: true, }) app.$api.venueLessonDate({ date: date, type: veneuType, venueId: venueId }).then(res => { this.setData({ venueLessons: res.venueLessons }) }, err => { }) } })