Files
qingcheng-xiaochengxu/pages/course/courseDetail/courseDetail.js

96 lines
2.1 KiB
JavaScript
Raw Normal View History

2025-06-30 13:12:06 +08:00
import { baseUrl } from "../../../request";
import { decodeBase64 } from "../../../utils/decodebase64";
2025-06-25 15:44:12 +08:00
// pages/course/courseDetail/courseDetail.js
Page({
data: {
2025-06-30 13:12:06 +08:00
chapterList: [null, null, null,null, null, null], // 章节目录
2025-06-25 15:44:12 +08:00
activeTab: 'intro', // 默认选中“课程简介”
activeIndex: null, // 默认没有任何标题被选中
2025-06-30 13:12:06 +08:00
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)
})
}
}
})
2025-06-25 15:44:12 +08:00
},
/** 切换选项卡 */
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}`,
})
},
/**
* 生命周期函数--监听页面加载
*/
2025-06-30 13:12:06 +08:00
onLoad(options) {
console.log(options);
this.setData({
cid: options.id,
})
this.getCourseDetail()
},
2025-06-25 15:44:12 +08:00
onReady() {},
onShow() {},
onHide() {},
onUnload() {},
onPullDownRefresh() {},
onReachBottom() {},
onShareAppMessage() {}
});