var APIClient = require('../../../utils/APIClient.js'); const util = require('../../../utils/util.js'); Page({ data: { userInfo: wx.getStorageSync('userInfo'), swiperList: [], currentIndex: 0, currentId: '', id: '', showId: '', title: '' }, onLoad(options) { if(options.scene) { // let id = util.convertObject(decodeURIComponent(options.scene)).id; this.setData({ userInfo: wx.getStorageSync('userInfo'), // id: id id: options.id }) }else { this.setData({ userInfo: wx.getStorageSync('userInfo'), id: options.id }) } if(options.title) { wx.setNavigationBarTitle({ title: options.title }) } if (options.showId) { this.getClassScheduleWeeklyQR(this.data.id, this.data.userInfo.id, options.showId); } else { this.getClassSchedule(this.data.id, this.data.userInfo.id); } }, onShareAppMessage: function() { // 用户点击右上角分享 let title = this.data.title let id = this.data.id let index = this.data.currentIndex let showId = this.data.swiperList[index].categoryId return { title: title, // 分享标题 desc: title, // 分享描述 path: `pages/index/index?id=${id}&showId=${showId}` // 分享路径 } }, switchContent(e) { this.setData({ currentIndex: e.detail.current }) wx.setNavigationBarTitle({ title: this.data.swiperList[e.detail.current].mainTitle }) }, // 获取课程列表 getClassSchedule(itemId, userId) { APIClient.getClassScheduleWeekly(itemId, userId).success(function (res) { console.log('轮播图', res); if (res.data.success) { this.setData({ swiperList: res.data.data.items, currentId: res.data.data.currentId }) this.getCurrentIndex(this.data.currentId, this.data.swiperList) } }.bind(this)) }, // 获取课程列表qr getClassScheduleWeeklyQR(itemId, userId, showId) { APIClient.getClassScheduleWeeklyQR(itemId, userId, showId).success(function (res) { if (res.data.success) { this.setData({ swiperList: res.data.data.items, currentId: res.data.data.currentId }) this.getCurrentIndex(this.data.currentId, this.data.swiperList) } }.bind(this)) }, toScheduleSubjectInner(e) { let id = e.currentTarget.dataset.id wx.navigateTo({ url: `/pages/schedule/scheduleSubjectInner/scheduleSubjectInner?id=${id}` }) }, getCurrentIndex(id, arr) { let len = arr.length; for (let i = 0; i < len; i++) { if (arr[i].categoryId === id) { this.setData({ currentIndex: i }) return; } } } })