import httpRequestApi from '../../../utils/APIClient'; import { formatDate } from '../../../utils/util'; Page({ data: { fullScreenBtn: false, playBtn: false, gesture: true, videoUrl: '', title: '', poster: '', works: [], total: '', title: '', id: '', iconImg: '', collectFlag: false, }, onLoad: function (option) { console.log(option); wx.setNavigationBarTitle({ title: option.title //页面标题为路由参数 }) this.setData({ title: option.title, id: option.id }) this.uid = wx.getStorageSync('uid');; httpRequestApi.getClassDetail(this.uid, option.id).success(res => { console.log(res); this.setData({ title: res.data.data.title, videoUrl: res.data.data.playUrl, iconImg: res.data.data.iconImg }) this.getReadInfo(1, 10); this.checkLike(); }) }, // 检查是否收藏 checkLike: function () { httpRequestApi.classIsLike(this.uid, { targetCode: this.data.id }).success(res => { this.setData({ collectFlag: res.data.data }) }) }, goToReading: function () { let id = this.data.id; let title = this.data.title; wx.navigateTo({ url: `../../main/reading/reading?id=${id}&title=${this.data.title}&img=${this.data.img}&video=${this.data.videoUrl}` }) }, goToWorks: function (e) { this.videoCtx = wx.createVideoContext('myVideo', this); this.videoCtx.stop(); console.log(e); let readId = e.target.dataset.uid; let title = this.data.title; wx.navigateTo({ url: `../../social/works/works?id=${readId}&tilte=${title}` }) }, collect: function (e) { // let uid = wx.getStorageSync('uid'); let data = { targetCode: this.data.id, title: this.data.title, iconImg: this.data.iconImg } httpRequestApi.collectClass(this.uid, data).success(res => { this.setData({ collectFlag: !this.data.collectFlag }) }) }, getReadInfo: function (pageNo, pageSize) { // const uid = wx.getStorageSync('uid'); const data = { lessonId: 1, pageNo: pageNo, pageSize: pageSize }; httpRequestApi.getClassRead(this.uid, data).success(res => { const readInfo = res.data.data.list; const readTemp = []; readInfo.forEach(item => { const temp = {}; temp.nickName = item.user.wechatName; temp.time = formatDate(item.userRead.gmtCreated, 3); temp.avatar = item.user.avatar; temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0; temp.uid = item.userRead.uid; temp.id = item.userRead.id; readTemp.push(temp); }); this.setData({ total: res.data.data.totalSize, works: readTemp }) }); }, // 下拉加载 scrollUpdate: function (e) { console.log(e) } })