// pages/course_detail/course_detail.js import dayjs from 'dayjs' import { Toast } from 'tdesign-miniprogram'; import { getVRCourseDetail, freeBuy } from '../../utils/request'; import { getCourseStatus, } from '../../utils/courseTime'; Page({ /** * 页面的初始数据 */ data: { time: 96 * 60 * 1000, detail: { compereId: null, createTime: "", creatorId: null, creatorName: "", display: null, duration: null, fee: null, id: null, isDap: null, isFee: null, isTop: null, organization: "", rtf: "", sceneCode: "", sort: null, thumb: "", thumbShare: "", title: "", titleSub: "", updateTime: "", openRoomTime: '', endRoomTime: '' }, imageOnTop: false, courseStaus: { status: 0, time: 0, showTime: '' } }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { if (options.id) { // debugger this.getVRCourseDetailData(options.id); } }, async getVRCourseDetailData(id) { const data = await getVRCourseDetail(id) console.log('data', data.data) this.setData({ detail: data.data }, () => { const res = getCourseStatus(this.data.detail.openRoomTime, this.data.detail.endRoomTime) // const res = getCourseStatus(dayjs('2024-09-02 10:00:00'), dayjs('2024-09-04 10:00:00')) console.log('getCourseStatus', res) this.setData({ courseStaus: res }) }) }, onFreeBuying() { this.setData({ imageOnTop: true }) }, closeDialog() { this.setData({ imageOnTop: false }) }, confirmDialog() { this.setData({ imageOnTop: false }, async () => { const userInfo = wx.getStorageSync('userInfo') console.log('userInfo', userInfo) const res = await freeBuy({ amount: this.data.detail.fee, businessId: this.data.detail.id, openId: userInfo.openId, phone: userInfo.phone, type: "lesson" }) if (res.code === 0) { Toast({ context: this, selector: '#t-toast', message: '购买成功!', theme: 'success', direction: 'column', }); } else { console.log('res', res) Toast({ context: this, selector: '#t-toast', message: res.msg, theme: 'warning', direction: 'column', }); } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, openHost() { wx.navigateToMiniProgram({ appId: 'wxd55ee54235e90359', path: 'pages/paid-room/paid-room', extraData: { roomId: 'test-01586', role: "leader", userId: '066893f525e56f09ce8b4420dff7e0681', nickname: "四维展主持人", avatar: "https://4dkk.4dage.com/take-look/images/other/6d5298a02bd849119b7e5357cbd6edff.jpeg" }, envVersion: 'develop', success(res) { // 打开成功 } }) }, })