53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
// pages/IndexNewCourseDetails/IndexNewCourseDetails.js
|
|
const api = require('../../utils/api');
|
|
const store = require('../../utils/store');
|
|
|
|
const app = getApp();
|
|
|
|
Page({
|
|
data: {
|
|
html: ' ',
|
|
courseCode: '',
|
|
courseTitle: '',
|
|
priceYuan: '',
|
|
buyText: '',
|
|
contactText: '',
|
|
},
|
|
|
|
onLoad(options) {
|
|
const id = options.id;
|
|
if (!id) return;
|
|
|
|
api
|
|
.getHomeCourses()
|
|
.then((list) => {
|
|
const item = (list || []).filter((c) => String(c.id) === String(id))[0];
|
|
if (!item) return;
|
|
this.setData({
|
|
html: item.content || ' ',
|
|
courseCode: item.courseCode || '',
|
|
courseTitle: item.courseTitle || '',
|
|
});
|
|
})
|
|
.catch((err) => console.error('[IndexNewCourseDetails] 加载失败', err));
|
|
},
|
|
|
|
onShow() {
|
|
app.ready().then(() => this.applyConfig());
|
|
},
|
|
|
|
/** 按钮文案取自后台配置,后台改完小程序下拉刷新即可生效。 */
|
|
applyConfig() {
|
|
this.setData({
|
|
buyText: store.cfg('course.button.buy'),
|
|
contactText: store.cfg('course.button.contact'),
|
|
});
|
|
},
|
|
|
|
/** 购买统一走商业化页面。 */
|
|
toBuy() {
|
|
if (!this.data.courseCode) return;
|
|
wx.navigateTo({ url: '/pages/buy/buy?code=' + this.data.courseCode });
|
|
},
|
|
});
|