course_detail.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // pages/course_detail/course_detail.js
  2. import dayjs from 'dayjs'
  3. import {
  4. Toast
  5. } from 'tdesign-miniprogram';
  6. import {
  7. getVRCourseDetail,
  8. freeBuy
  9. } from '../../utils/request';
  10. import {
  11. getCourseStatus,
  12. } from '../../utils/courseTime';
  13. Page({
  14. /**
  15. * 页面的初始数据
  16. */
  17. data: {
  18. time: 96 * 60 * 1000,
  19. detail: {
  20. compereId: null,
  21. createTime: "",
  22. creatorId: null,
  23. creatorName: "",
  24. display: null,
  25. duration: null,
  26. fee: null,
  27. id: null,
  28. isDap: null,
  29. isFee: null,
  30. isTop: null,
  31. organization: "",
  32. rtf: "",
  33. sceneCode: "",
  34. sort: null,
  35. thumb: "",
  36. thumbShare: "",
  37. title: "",
  38. titleSub: "",
  39. updateTime: "",
  40. openRoomTime: '',
  41. endRoomTime: ''
  42. },
  43. imageOnTop: false,
  44. courseStaus: {
  45. status: 0,
  46. time: 0,
  47. showTime: ''
  48. }
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad(options) {
  54. if (options.id) {
  55. // debugger
  56. this.getVRCourseDetailData(options.id);
  57. }
  58. },
  59. async getVRCourseDetailData(id) {
  60. const data = await getVRCourseDetail(id)
  61. console.log('data', data.data)
  62. this.setData({
  63. detail: data.data
  64. }, () => {
  65. const res = getCourseStatus(this.data.detail.openRoomTime, this.data.detail.endRoomTime)
  66. // const res = getCourseStatus(dayjs('2024-09-02 10:00:00'), dayjs('2024-09-04 10:00:00'))
  67. console.log('getCourseStatus', res)
  68. this.setData({
  69. courseStaus: res
  70. })
  71. })
  72. },
  73. onFreeBuying() {
  74. this.setData({
  75. imageOnTop: true
  76. })
  77. },
  78. closeDialog() {
  79. this.setData({
  80. imageOnTop: false
  81. })
  82. },
  83. confirmDialog() {
  84. this.setData({
  85. imageOnTop: false
  86. }, async () => {
  87. const userInfo = wx.getStorageSync('userInfo')
  88. console.log('userInfo', userInfo)
  89. const res = await freeBuy({
  90. amount: this.data.detail.fee,
  91. businessId: this.data.detail.id,
  92. openId: userInfo.openId,
  93. phone: userInfo.phone,
  94. type: "lesson"
  95. })
  96. if (res.code === 0) {
  97. Toast({
  98. context: this,
  99. selector: '#t-toast',
  100. message: '购买成功!',
  101. theme: 'success',
  102. direction: 'column',
  103. });
  104. } else {
  105. console.log('res', res)
  106. Toast({
  107. context: this,
  108. selector: '#t-toast',
  109. message: res.msg,
  110. theme: 'warning',
  111. direction: 'column',
  112. });
  113. }
  114. })
  115. },
  116. /**
  117. * 生命周期函数--监听页面初次渲染完成
  118. */
  119. onReady() {
  120. },
  121. /**
  122. * 生命周期函数--监听页面显示
  123. */
  124. onShow() {
  125. },
  126. /**
  127. * 生命周期函数--监听页面隐藏
  128. */
  129. onHide() {
  130. },
  131. /**
  132. * 生命周期函数--监听页面卸载
  133. */
  134. onUnload() {
  135. },
  136. /**
  137. * 页面相关事件处理函数--监听用户下拉动作
  138. */
  139. onPullDownRefresh() {
  140. },
  141. /**
  142. * 页面上拉触底事件的处理函数
  143. */
  144. onReachBottom() {
  145. },
  146. /**
  147. * 用户点击右上角分享
  148. */
  149. onShareAppMessage() {
  150. },
  151. openHost() {
  152. wx.navigateToMiniProgram({
  153. appId: 'wxd55ee54235e90359',
  154. path: 'pages/paid-room/paid-room',
  155. extraData: {
  156. roomId: 'test-01586',
  157. role: "leader",
  158. userId: '066893f525e56f09ce8b4420dff7e0681',
  159. nickname: "四维展主持人",
  160. avatar: "https://4dkk.4dage.com/take-look/images/other/6d5298a02bd849119b7e5357cbd6edff.jpeg"
  161. },
  162. envVersion: 'develop',
  163. success(res) {
  164. // 打开成功
  165. }
  166. })
  167. },
  168. openCouse() {
  169. const {
  170. roomId,
  171. isCompere
  172. } = this.data.detail
  173. const userInfo = wx.getStorageSync('userInfo')
  174. const role = isCompere === 1 ? 'leader' : "customer"
  175. wx.showToast({
  176. title: `role-${role}`,
  177. })
  178. wx.navigateToMiniProgram({
  179. appId: 'wxd55ee54235e90359',
  180. path: 'pages/paid-room/paid-room',
  181. extraData: {
  182. roomId: roomId,
  183. role:role,
  184. userId: userInfo.id,
  185. nickname: userInfo.nickName,
  186. avatar: userInfo.avatarUrl,
  187. courseId: this.data.detail.id
  188. },
  189. envVersion: getApp().globalData.envVersion,
  190. success(res) {
  191. // 打开成功
  192. }
  193. })
  194. },
  195. })