123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- // 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) {
- // 打开成功
- }
- })
- },
- openCouse() {
- const {
- roomId,
- isCompere
- } = this.data.detail
- const userInfo = wx.getStorageSync('userInfo')
- const role = isCompere === 1 ? 'leader' : "customer"
- wx.showToast({
- title: `role-${role}`,
- })
- wx.navigateToMiniProgram({
- appId: 'wxd55ee54235e90359',
- path: 'pages/paid-room/paid-room',
- extraData: {
- roomId: roomId,
- role:role,
- userId: userInfo.id,
- nickname: userInfo.nickName,
- avatar: userInfo.avatarUrl,
- courseId: this.data.detail.id
- },
- envVersion: getApp().globalData.envVersion,
- success(res) {
- // 打开成功
- }
- })
- },
- })
|