live-detail.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 } 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 { orderStatus } from '@/views/order-detail/orderStatus'
  11. import ColHeader from '@/components/col-header'
  12. interface IProps {
  13. courseTime: string
  14. coursePlan: string
  15. videoPosterUrl?: string
  16. id?: number | string
  17. }
  18. export default defineComponent({
  19. name: 'LiveDetail',
  20. data() {
  21. const query = this.$route.query
  22. return {
  23. groupId: query.groupId,
  24. courseId: query.classId,
  25. live: {} as any
  26. }
  27. },
  28. computed: {
  29. userInfo() {
  30. const live = this.live as any
  31. const planList = live.planList || []
  32. const startTime = planList[0]?.startTime || new Date()
  33. const endTime = planList[0]?.endTime || new Date()
  34. return {
  35. headUrl: live.avatar,
  36. username: live.userName || `游客${live.teacherId || ''}`,
  37. startTime:
  38. `${dayjs(startTime).format('YYYY-MM-DD')} ${dayjs(startTime).format(
  39. 'HH:mm'
  40. )}~${dayjs(endTime).format('HH:mm')}` || '',
  41. buyNum: live.studentCount,
  42. lessonPrice: live.coursePrice,
  43. lessonNum: live.courseNum,
  44. lessonDesc: live.courseIntroduce,
  45. lessonCoverUrl: live.backgroundPic || live.backgroundPicTemplate,
  46. lessonName: live.courseGroupName
  47. }
  48. },
  49. courseInfo() {
  50. let tempArr = [] as IProps[]
  51. const coursePlanList = this.live.planList || []
  52. coursePlanList.forEach((item: any) => {
  53. const startTime = item.startTime || new Date()
  54. const endTime = item.endTime || new Date()
  55. tempArr.push({
  56. courseTime: `${dayjs(startTime).format('YYYY-MM-DD')} ${dayjs(
  57. startTime
  58. ).format('HH:mm')}~${dayjs(endTime).format('HH:mm')}`,
  59. coursePlan: item.plan,
  60. id: item.courseId
  61. })
  62. })
  63. return tempArr || []
  64. },
  65. salesEndDate() {
  66. const live = this.live as any
  67. return dayjs(live.salesEndDate || new Date()).format('YYYY-MM-DD')
  68. }
  69. },
  70. async mounted() {
  71. try {
  72. const res = await request.get(
  73. '/api-student/courseGroup/queryLiveCourseInfo',
  74. {
  75. params: {
  76. groupId: this.groupId
  77. }
  78. }
  79. )
  80. this.live = res.data || {}
  81. } catch {}
  82. },
  83. methods: {
  84. async onBuy() {
  85. try {
  86. const res = await request.post(
  87. '/api-student/userOrder/getPendingOrder',
  88. {
  89. data: {
  90. goodType: 'LIVE',
  91. bizId: this.groupId
  92. }
  93. }
  94. )
  95. console.log(res, res.data)
  96. const live = this.live
  97. orderStatus.orderObject.orderType = 'LIVE'
  98. orderStatus.orderObject.orderName = '直播课购买'
  99. orderStatus.orderObject.orderDesc = '直播课购买'
  100. orderStatus.orderObject.actualPrice = live.coursePrice
  101. orderStatus.orderObject.orderNo = ''
  102. orderStatus.orderObject.orderList = [
  103. {
  104. orderType: 'LIVE',
  105. goodsName: '直播课购买',
  106. courseGroupId: live.courseGroupId,
  107. courseGroupName: live.courseGroupName,
  108. coursePrice: live.coursePrice,
  109. teacherName: live.teacherName || `游客${live.teacherId || ''}`,
  110. teacherId: live.teacherId,
  111. avatar: live.avatar,
  112. courseInfo: this.courseInfo
  113. }
  114. ]
  115. const result = res.data
  116. if (result) {
  117. Dialog.confirm({
  118. title: '提示',
  119. message: '您有一个未支付的订单,是否继续支付?',
  120. confirmButtonColor: '#269a93',
  121. cancelButtonText: '取消订单',
  122. confirmButtonText: '继续支付'
  123. })
  124. .then(async () => {
  125. orderStatus.orderObject.orderNo = result.orderNo
  126. orderStatus.orderObject.actualPrice = result.actualPrice
  127. 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. const live = this.live
  141. this.$router.push({
  142. path: '/orderDetail',
  143. query: {
  144. orderType: 'LIVE',
  145. courseGroupId: live.courseGroupId
  146. }
  147. })
  148. },
  149. async cancelPayment(orderNo: string) {
  150. try {
  151. await request.post('/api-student/userOrder/orderCancel', {
  152. data: {
  153. orderNo
  154. }
  155. })
  156. // this.routerTo()
  157. } catch {}
  158. }
  159. },
  160. render() {
  161. return (
  162. <div class={[styles['live-detail'], 'mb12']}>
  163. <ColHeader />
  164. <UserDetail userInfo={this.userInfo} />
  165. <SectionDetail>
  166. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  167. </SectionDetail>
  168. <SectionDetail
  169. title="课程列表"
  170. icon="courseList"
  171. contentStyle={{ paddingTop: '0' }}
  172. >
  173. {this.courseInfo.length > 0 && (
  174. <CoursePlanStep
  175. courseInfo={this.courseInfo}
  176. courseId={Number(this.courseId) || 0}
  177. />
  178. )}
  179. </SectionDetail>
  180. <div class={styles.tips}>
  181. <h3>
  182. <Icon name={iconTips} size={15} />
  183. 温馨提示
  184. </h3>
  185. <p>
  186. 1、该直播课程销售截止后,报名人数若少于
  187. {this.live.mixStudentNum || 0}
  188. 人将取消开课,已购买学员付费金额将自动返还,请您放心购买;
  189. <br />
  190. 2、直播课教学计划中的上课时间为老师预计时间,实际上课时间以老师开启直播时间为准;
  191. <br />
  192. 3、若您错过老师直播,可通过视频回放观看完整课程。
  193. </p>
  194. </div>
  195. {this.courseInfo.length > 0 && this.live.existBuy !== 1 && (
  196. <Sticky offsetBottom={0} position="bottom">
  197. <div class={['btnGroup', styles.btnMore]}>
  198. <Button block round type="primary" onClick={this.onBuy}>
  199. 立即购买
  200. </Button>
  201. </div>
  202. </Sticky>
  203. )}
  204. </div>
  205. )
  206. }
  207. })