video-detail.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import CourseVideoItem from '@/business-components/course-video-item'
  2. import SectionDetail from '@/business-components/section-detail'
  3. import UserDetail from '@/business-components/user-detail'
  4. import { Sticky, Button, Dialog } from 'vant'
  5. import { defineComponent } from 'vue'
  6. import styles from './video-detail.module.less'
  7. import request from '@/helpers/request'
  8. import ColHeader from '@/components/col-header'
  9. import { orderStatus } from '@/views/order-detail/orderStatus'
  10. export default defineComponent({
  11. name: 'VideoDetail',
  12. data() {
  13. const query = this.$route.query
  14. return {
  15. userInfo: {} as any,
  16. detailList: [],
  17. params: {
  18. groupId: query.groupId
  19. }
  20. }
  21. },
  22. async mounted() {
  23. try {
  24. const res = await request.get(
  25. '/api-teacher/videoLessonGroup/selectVideoLesson',
  26. {
  27. params: {
  28. groupId: this.params.groupId
  29. }
  30. }
  31. )
  32. const result = res.data || {}
  33. const lessonGroup = result.lessonGroup || {}
  34. this.userInfo = {
  35. alreadyBuy: result.alreadyBuy,
  36. username: lessonGroup.username || `游客${lessonGroup.teacherId || ''}`,
  37. headUrl: lessonGroup.avatar,
  38. buyNum: lessonGroup.countStudent,
  39. id: lessonGroup.id,
  40. lessonNum: lessonGroup.lessonCount,
  41. lessonName: lessonGroup.lessonName,
  42. lessonDesc: lessonGroup.lessonDesc,
  43. lessonPrice: lessonGroup.lessonPrice,
  44. teacherId: lessonGroup.teacherId,
  45. lessonCoverUrl: lessonGroup.lessonCoverUrl
  46. }
  47. this.detailList = result.detailList || []
  48. } catch {}
  49. },
  50. methods: {
  51. onPlay(detail: any) {
  52. this.$router.push({
  53. path: '/videoClassDetail',
  54. query: {
  55. groupId: this.params.groupId,
  56. classId: detail.id
  57. }
  58. })
  59. },
  60. async onBuy() {
  61. try {
  62. const res = await request.post(
  63. '/api-student/userOrder/getPendingOrder',
  64. {
  65. data: {
  66. goodType: 'LIVE',
  67. bizId: this.params.groupId
  68. }
  69. }
  70. )
  71. const userInfo = this.userInfo
  72. orderStatus.orderType = 'LIVE'
  73. orderStatus.videoInfo = {
  74. courseGroupId: userInfo.id,
  75. courseGroupName: userInfo.lessonName,
  76. coursePrice: userInfo.lessonPrice,
  77. teacherName: userInfo.username || `游客${userInfo.teacherId || ''}`,
  78. teacherId: userInfo.teacherId,
  79. avatar: userInfo.avatar,
  80. courseInfo: this.detailList
  81. }
  82. const result = res.data
  83. if (result) {
  84. Dialog.confirm({
  85. title: '提示',
  86. message: '您有一个未支付的订单,是否继续支付?',
  87. confirmButtonColor: '#269a93',
  88. cancelButtonText: '取消订单',
  89. confirmButtonText: '继续支付'
  90. })
  91. .then(async () => {
  92. orderStatus.orderInfo = {
  93. orderNo: result.orderNo,
  94. actualPrice: result.actualPrice,
  95. payStatus: true
  96. }
  97. this.routerTo()
  98. })
  99. .catch(() => {
  100. Dialog.close()
  101. // 只用取消订单,不用做其它处理
  102. this.cancelPayment(result.orderNo)
  103. })
  104. } else {
  105. this.routerTo()
  106. }
  107. } catch {}
  108. },
  109. routerTo() {
  110. this.$router.push({
  111. path: '/orderDetail',
  112. query: {
  113. orderType: 'VIDEO',
  114. courseGroupId: this.params.groupId
  115. }
  116. })
  117. },
  118. async cancelPayment(orderNo: string) {
  119. try {
  120. await request.post('/api-student/userOrder/orderCancel', {
  121. data: {
  122. orderNo
  123. }
  124. })
  125. } catch {}
  126. }
  127. },
  128. render() {
  129. return (
  130. <div class={[styles['video-detail']]}>
  131. <ColHeader />
  132. <UserDetail userInfo={this.userInfo} />
  133. <SectionDetail>
  134. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  135. </SectionDetail>
  136. <SectionDetail title="课程列表" icon="courseList" class="mb12">
  137. {this.detailList.map((item: any) => (
  138. <CourseVideoItem
  139. class={'mb12'}
  140. detail={{
  141. id: item.id,
  142. title: item.videoTitle,
  143. content: item.videoContent,
  144. imgUrl: item.coverUrl
  145. }}
  146. onPlay={this.onPlay}
  147. />
  148. ))}
  149. </SectionDetail>
  150. {this.userInfo.id && (
  151. <Sticky offsetBottom={0} position="bottom">
  152. <div class={['btnGroup', styles.btnMore]}>
  153. <Button
  154. block
  155. round
  156. type="primary"
  157. onClick={this.onBuy}
  158. disabled={this.userInfo.alreadyBuy}
  159. >
  160. {this.userInfo.alreadyBuy ? '已购买' : '立即购买'}
  161. </Button>
  162. </div>
  163. </Sticky>
  164. )}
  165. </div>
  166. )
  167. }
  168. })