live-detail.tsx 15 KB

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