video-detail.tsx 6.0 KB

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