96 lines
2.1 KiB
JavaScript
96 lines
2.1 KiB
JavaScript
import { baseUrl } from "../../../request";
|
|
import { decodeBase64 } from "../../../utils/decodebase64";
|
|
|
|
// pages/course/courseDetail/courseDetail.js
|
|
Page({
|
|
data: {
|
|
chapterList: [null, null, null,null, null, null], // 章节目录
|
|
activeTab: 'intro', // 默认选中“课程简介”
|
|
activeIndex: null, // 默认没有任何标题被选中
|
|
cid: 0, // 课程ID
|
|
courseObj: '', // 课程对象
|
|
richText: '', // 课程概述富文本
|
|
},
|
|
|
|
// 获取课程详情
|
|
getCourseDetail() {
|
|
const cid = this.data.cid;
|
|
wx.request({
|
|
url: baseUrl + '/course/query/id',
|
|
method: 'POST',
|
|
data: {
|
|
id: cid
|
|
},
|
|
header: {
|
|
Authorization :wx.getStorageSync('token'),
|
|
},
|
|
success : res => {
|
|
console.log(res);
|
|
if (res.data.code === 1) {
|
|
this.setData({
|
|
courseObj: res.data.data,
|
|
chapterList: res.data.data.courseChapters,
|
|
richText: decodeBase64(res.data.data.detail)
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
/** 切换选项卡 */
|
|
selectTab(e) {
|
|
const tab = e.currentTarget.dataset.tab;
|
|
this.setData({ activeTab: tab });
|
|
},
|
|
|
|
/** 选择课程标题 */
|
|
selectCourse(e) {
|
|
const index = e.currentTarget.dataset.index;
|
|
this.setData({
|
|
activeIndex: index // 设置选中的课程标题索引
|
|
});
|
|
},
|
|
|
|
// 跳转课程订单创建页面
|
|
gotoCourseOrder(e) {
|
|
const courseId = e.currentTarget.dataset.id;
|
|
wx.navigateTo({
|
|
url: `/pages/course/createCourseOrder/createCourseOrder?id=${courseId}`,
|
|
})
|
|
},
|
|
|
|
// 跳转申请推广页面
|
|
gotoApplyPromotion(e) {
|
|
const courseId = e.currentTarget.dataset.id;
|
|
wx.navigateTo({
|
|
url: `/pages/course/applyPromotion/applyPromotion?id=${courseId}`,
|
|
})
|
|
},
|
|
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
console.log(options);
|
|
this.setData({
|
|
cid: options.id,
|
|
})
|
|
this.getCourseDetail()
|
|
},
|
|
|
|
onReady() {},
|
|
|
|
onShow() {},
|
|
|
|
onHide() {},
|
|
|
|
onUnload() {},
|
|
|
|
onPullDownRefresh() {},
|
|
|
|
onReachBottom() {},
|
|
|
|
onShareAppMessage() {}
|
|
});
|