video-detail.tsx 5.2 KB

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