Files
qingcheng-xiaochengxu/pages/course/createCourseOrder/createCourseOrder.js
2025-07-20 18:22:59 +08:00

122 lines
2.0 KiB
JavaScript

import { baseUrl, globalImgUrl } from "../../../request";
// pages/course/createCourseOrder/createCourseOrder.js
Page({
/**
* 页面的初始数据
*/
data: {
courseId: 0, // 课程id
courseObj: '', // 课程对象
globalImgUrl, // 全局图片
},
// 创建订单方法
createOrder() {
const { courseId } = this.data;
let orderId ;
wx.request({
url: baseUrl + '/courseOrder/add',
method: 'POST',
data: {
courseId: courseId
},
header: {
Authorization :wx.getStorageSync('token'),
},
success : res => {
console.log(res);
this.setData({
orderId: res.data.data
})
wx.navigateTo({
url: `/pages/course/orderDetail/orderDetail?id=${this.data.orderId}`,
})
}
})
},
// 获取课程详情
getCourseDetail() {
const cid = this.data.courseId;
wx.request({
url: baseUrl + '/course/detail/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,
})
}
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log('课程id--->',options.id);
this.setData({
courseId: options.id,
})
this.getCourseDetail()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})