live-detail.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. import CoursePlanStep from '@/business-components/course-plan-step'
  2. import SectionDetail from '@/business-components/section-detail'
  3. import UserDetail from '@/business-components/user-detail'
  4. import request from '@/helpers/request'
  5. import dayjs from 'dayjs'
  6. import { Icon, Sticky, Button, Dialog, Toast, Popup } from 'vant'
  7. import { defineComponent } from 'vue'
  8. import styles from './live-detail.module.less'
  9. import iconTips from '@common/images/icon_tips.png'
  10. import { onSubmitZero, orderStatus } from '@/views/order-detail/orderStatus'
  11. import ColHeader from '@/components/col-header'
  12. import { postMessage } from '@/helpers/native-message'
  13. import ColSticky from '@/components/col-sticky'
  14. import ColShare from '@/components/col-share'
  15. import LiveItem from '@/views/live-class/live-item'
  16. import iconShare from '@/views/shop-mall/images/icon-share.svg'
  17. import { state } from '@/state'
  18. import { browser } from '@/helpers/utils'
  19. import { tradeOrder } from '../trade/tradeOrder'
  20. import TheSticky from '@/components/the-sticky'
  21. import { useStatisticTracking } from '@/helpers/hooks'
  22. interface IProps {
  23. courseTime: string
  24. coursePlan: string
  25. videoPosterUrl?: string
  26. roomUid?: string
  27. liveState?: number
  28. id?: number | string
  29. }
  30. export default defineComponent({
  31. name: 'LiveDetail',
  32. data() {
  33. const query = this.$route.query
  34. return {
  35. joinRoom: query.joinRoom, // 原生传递过来的参数,判断是否进入直播间
  36. recomUserId: query.recomUserId, // 推荐人id
  37. groupId: query.groupId,
  38. courseId: query.classId,
  39. platform: query.p, // 属于哪个平台,//机构老师 tenant,平台老师 无
  40. live: {} as any,
  41. shareStatus: false,
  42. shareUrl: ''
  43. }
  44. },
  45. computed: {
  46. userInfo() {
  47. const live = this.live as any
  48. // console.log('live', live)
  49. const planList = live.planList || []
  50. const startTime = planList[0]?.startTime || new Date()
  51. // const endTime = planList[0]?.endTime || new Date()
  52. return {
  53. avatar: live.avatar,
  54. headUrl: live.avatar,
  55. username: live.userName || `游客${live.teacherId || ''}`,
  56. id: live.teacherId,
  57. startTime:
  58. `${dayjs(startTime).format('YYYY-MM-DD')} ${dayjs(startTime).format(
  59. 'HH:mm'
  60. )}` || '',
  61. courseStartTime: dayjs(live.courseStartTime).format('YYYY-MM-DD HH:mm'),
  62. buyNum: live.studentCount,
  63. type: 'live',
  64. lessonId: live.courseGroupId,
  65. lessonPrice: live.coursePrice,
  66. isShowCourse: live.status !== 'APPLY',
  67. completeCourseNum: live.completeCourseNum,
  68. lessonNum: live.courseNum,
  69. lessonDesc: live.courseIntroduce,
  70. lessonCoverUrl: live.backgroundPic || live.backgroundPicTemplate,
  71. lessonName: live.courseGroupName,
  72. subjectName: live.subjectName,
  73. auditVersion: live.auditVersion || 0,
  74. isDegree: live.degreeFlag ? true : false,
  75. isTeacher: live.teacherFlag ? true : false
  76. }
  77. },
  78. platformStatus() {
  79. const userInfo = state.user.data as any
  80. // 是机构学生 并且 是机构老师分享
  81. const query = this.$route.query
  82. return userInfo.tenantId > 0 && query.p == 'tenant'
  83. },
  84. courseInfo() {
  85. const tempArr = [] as IProps[]
  86. const coursePlanList = this.live.planList || []
  87. coursePlanList.forEach((item: any) => {
  88. const startTime = item.startTime || new Date()
  89. const endTime = item.endTime || new Date()
  90. tempArr.push({
  91. courseTime: `${dayjs(startTime).format('YYYY-MM-DD')} ${dayjs(
  92. startTime
  93. ).format('HH:mm')}~${dayjs(endTime).format('HH:mm')}`,
  94. coursePlan: item.plan,
  95. roomUid: item.roomUid,
  96. liveState: item.liveState,
  97. id: item.courseId
  98. })
  99. })
  100. return tempArr || []
  101. },
  102. salesEndDate() {
  103. const live = this.live as any
  104. return dayjs(live.salesEndDate || new Date()).format('YYYY-MM-DD')
  105. },
  106. liveStatus() {
  107. const coursePlanList = this.live.planList || []
  108. const tempObj = {
  109. status: false,
  110. liveStatus: 0,
  111. roomUid: ''
  112. }
  113. coursePlanList.forEach((item: any) => {
  114. if (item.courseId === Number(this.courseId)) {
  115. tempObj.status = true
  116. tempObj.liveStatus = item.liveStatus
  117. tempObj.roomUid = item.roomUid
  118. }
  119. })
  120. return tempObj
  121. }
  122. },
  123. async mounted() {
  124. await this._init()
  125. if (/(localhost|192)/g.test(location.origin)) {
  126. this.shareUrl = `https://dev.colexiu.com/teacher/#/shareLive?recomUserId=${state.user.data?.userId}&groupId=${this.groupId}&userType=${state.platformType}&p=tenant`
  127. } else {
  128. this.shareUrl = `${location.origin}/teacher/#/shareLive?recomUserId=${state.user.data?.userId}&groupId=${this.groupId}&userType=${state.platformType}&p=tenant`
  129. }
  130. /** 埋点 */
  131. useStatisticTracking({
  132. objectType: "LIVE",
  133. objectId: this.groupId as any
  134. })
  135. },
  136. methods: {
  137. async _init() {
  138. try {
  139. const res = await request.get(
  140. '/api-student/courseGroup/queryLiveCourseInfo',
  141. {
  142. params: {
  143. groupId: this.groupId
  144. }
  145. }
  146. )
  147. this.live = res.data || {}
  148. } catch {}
  149. },
  150. async onJoinRoom() {
  151. try {
  152. const res = await request.get(
  153. '/api-student/courseGroup/queryLiveCourseInfo',
  154. {
  155. params: {
  156. groupId: this.groupId
  157. }
  158. }
  159. )
  160. const result = res.data || {}
  161. const coursePlanList = result.planList || []
  162. let tempObj: any = {}
  163. coursePlanList.forEach((item: any) => {
  164. if (item.courseId === Number(this.courseId)) {
  165. tempObj = item
  166. }
  167. })
  168. if (tempObj && tempObj.liveState === 1) {
  169. postMessage({
  170. api: 'joinLiveRoom',
  171. content: {
  172. roomId: tempObj.roomUid,
  173. teacherId: this.live.teacherId
  174. }
  175. })
  176. } else if (tempObj && tempObj.liveState === 2) {
  177. setTimeout(() => {
  178. Toast('课程已结束')
  179. }, 100)
  180. } else {
  181. setTimeout(() => {
  182. Toast('课程尚未开始,请耐心等候')
  183. }, 100)
  184. }
  185. } catch {}
  186. },
  187. initLive () {
  188. const live = this.live
  189. orderStatus.orderObject.orderType = 'LIVE'
  190. orderStatus.orderObject.orderName = '直播课购买'
  191. orderStatus.orderObject.orderDesc = '直播课购买'
  192. orderStatus.orderObject.actualPrice = live.coursePrice
  193. orderStatus.orderObject.recomUserId = this.recomUserId
  194. orderStatus.orderObject.orderNo = ''
  195. orderStatus.orderObject.orderList = [
  196. {
  197. orderType: 'LIVE',
  198. goodsName: '直播课购买',
  199. courseGroupId: live.courseGroupId,
  200. courseGroupName: live.courseGroupName,
  201. coursePrice: live.coursePrice,
  202. price: live.coursePrice,
  203. teacherName: live.userName || `游客${live.teacherId || ''}`,
  204. teacherId: live.teacherId,
  205. avatar: live.avatar,
  206. courseInfo: this.courseInfo,
  207. recomUserId: this.recomUserId
  208. }
  209. ]
  210. },
  211. async onBuy() {
  212. try {
  213. // const live = this.live
  214. // // 判断是否是0无订单
  215. // if (live.coursePrice <= 0) {
  216. // this.initLive()
  217. // await onSubmitZero(() => {
  218. // Dialog.alert({
  219. // message: '领取成功',
  220. // confirmButtonText: '确定',
  221. // confirmButtonColor: '#2dc7aa'
  222. // }).then(() => {
  223. // this._init()
  224. // })
  225. // })
  226. // return
  227. // }
  228. const res = await request.post(
  229. '/api-student/userOrder/getPendingOrder',
  230. {
  231. data: {
  232. goodType: 'LIVE',
  233. bizId: this.groupId
  234. }
  235. }
  236. )
  237. const result = res.data
  238. if (result) {
  239. Dialog.confirm({
  240. title: '提示',
  241. message: '您有一个未支付的订单,是否继续支付?',
  242. confirmButtonColor: '#269a93',
  243. cancelButtonText: '取消订单',
  244. confirmButtonText: '继续支付'
  245. })
  246. .then(async () => {
  247. tradeOrder(result, this.routerTo)
  248. })
  249. .catch(() => {
  250. Dialog.close()
  251. // 只用取消订单,不用做其它处理
  252. this.cancelPayment(result.orderNo)
  253. })
  254. } else {
  255. this.initLive()
  256. this.routerTo()
  257. }
  258. } catch {
  259. //
  260. }
  261. },
  262. routerTo() {
  263. const live = this.live
  264. this.$router.push({
  265. path: '/orderDetail',
  266. query: {
  267. orderType: 'LIVE',
  268. courseGroupId: live.courseGroupId
  269. }
  270. })
  271. },
  272. async cancelPayment(orderNo: string) {
  273. try {
  274. await request.post('/api-student/userOrder/orderCancel', {
  275. data: {
  276. orderNo
  277. }
  278. })
  279. // this.routerTo()
  280. } catch {}
  281. }
  282. },
  283. render() {
  284. return (
  285. <div class={[styles['live-detail'], 'mb12']}>
  286. <ColHeader
  287. v-slots={{
  288. right: () => (
  289. <img src={iconShare} onClick={() => (this.shareStatus = true)} />
  290. )
  291. }}
  292. />
  293. <UserDetail
  294. userInfo={this.userInfo}
  295. showBuy={false}
  296. onUserDetail={(item: any) => {
  297. if (state.platformType === 'STUDENT' && browser().isApp) {
  298. this.$router.push({
  299. path: '/teacherHome',
  300. query: {
  301. teacherId: item.id,
  302. tabs: 'live'
  303. }
  304. })
  305. }
  306. }}
  307. />
  308. <SectionDetail border>
  309. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  310. </SectionDetail>
  311. <SectionDetail
  312. title="课程列表"
  313. icon="courseList"
  314. border
  315. contentStyle={{ paddingTop: '0' }}
  316. >
  317. {this.courseInfo.length > 0 && (
  318. <CoursePlanStep
  319. courseInfo={this.courseInfo}
  320. courseId={Number(this.courseId) || 0}
  321. />
  322. )}
  323. </SectionDetail>
  324. <div class={styles.tips}>
  325. <h3>
  326. <Icon name={iconTips} size={15} />
  327. 温馨提示
  328. </h3>
  329. <p>
  330. 1、该直播课程销售截止后,报名人数若少于
  331. {this.live.mixStudentNum || 0}
  332. 人将取消开课,已购买学员付费金额将自动返还,请您放心购买;
  333. <br />
  334. 2、直播课教学计划中的上课时间为老师预计时间,实际上课时间以老师开启直播时间为准;
  335. <br />
  336. 3、若您错过老师直播,可通过视频回放观看完整课程。
  337. </p>
  338. </div>
  339. {this.courseInfo.length > 0 && this.live.existBuy !== 1 && (
  340. <TheSticky position="bottom">
  341. <div class={["btnGroup", styles.btnMore]}>
  342. <Button
  343. block
  344. round
  345. type="primary"
  346. onClick={this.onBuy}
  347. disabled={this.platformStatus}
  348. >
  349. {this.live.coursePrice <= 0 ? '免费领取' : `立即购买`}
  350. </Button>
  351. </div>
  352. </TheSticky>
  353. )}
  354. {this.joinRoom == '1' && this.liveStatus.liveStatus !== 2 && (
  355. <TheSticky position="bottom">
  356. <div class={["btnGroup", styles.btnMore]}>
  357. <Button block round type="primary" onClick={this.onJoinRoom}>
  358. 进入直播间
  359. </Button>
  360. </div>
  361. </TheSticky>
  362. )}
  363. <Popup
  364. v-model:show={this.shareStatus}
  365. style={{ background: 'transparent' }}
  366. >
  367. <ColShare
  368. teacherId={this.userInfo.id}
  369. shareUrl={this.shareUrl}
  370. shareType="live"
  371. >
  372. <LiveItem
  373. class={styles.shareCourse}
  374. liveInfo={{
  375. backgroundPic: this.userInfo.lessonCoverUrl,
  376. courseGroupId: this.userInfo.lessonId,
  377. courseGroupName: this.userInfo.lessonName,
  378. courseNum: this.userInfo.lessonNum,
  379. coursePrice: this.userInfo.lessonPrice,
  380. teacherName: this.userInfo.username,
  381. teacherId: this.userInfo.id,
  382. avatar: this.userInfo.avatar,
  383. studentCount: this.userInfo.buyNum,
  384. courseStartTime: this.userInfo.courseStartTime,
  385. existBuy: 0,
  386. subjectName: this.userInfo.subjectName
  387. }}
  388. />
  389. </ColShare>
  390. </Popup>
  391. </div>
  392. )
  393. }
  394. })