index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 { Button, Dialog, Toast } from 'vant'
  5. import { defineComponent } from 'vue'
  6. import styles from './index.module.less'
  7. import request from '@/helpers/request'
  8. import ColSticky from '@/components/col-sticky'
  9. import { shareCall } from '../share'
  10. import { browser } from '@/helpers/utils'
  11. import { postMessage } from '@/helpers/native-message'
  12. import { state } from '@/state'
  13. import qs from 'query-string'
  14. export const getAssetsHomeFile = (fileName: string) => {
  15. const path = `../images/${fileName}`
  16. const modules = import.meta.globEager('../images/*')
  17. return modules[path].default
  18. }
  19. export default defineComponent({
  20. name: 'VideoDetail',
  21. data() {
  22. const query = this.$route.query
  23. return {
  24. userInfo: {} as any,
  25. detailList: [],
  26. buyUserList: [], // 购买学生数
  27. dataShow: true, // 判断是否有数据
  28. loading: false,
  29. finished: false,
  30. recomUserId: query.recomUserId, // 分享人编号
  31. params: {
  32. videoLessonGroupId: query.groupId,
  33. page: 1,
  34. rows: 20
  35. },
  36. wxStatus: false
  37. }
  38. },
  39. created() {
  40. if (browser().isApp) {
  41. if (state.platformType === 'STUDENT') {
  42. // 自动跳转到学生端视频课详情购买页
  43. window.location.replace(
  44. `${location.origin}/student/#/videoDetail?${qs.stringify(
  45. this.$route.query
  46. )}`
  47. )
  48. } else if (state.platformType === 'TEACHER') {
  49. Dialog.alert({
  50. title: '提示',
  51. message: '请使用酷乐秀学生端扫码打开',
  52. confirmButtonColor: '#2dc7aa'
  53. }).then(() => {
  54. postMessage({ api: 'back' })
  55. })
  56. }
  57. } else {
  58. // 如果不在app里面则不需要唤起操作
  59. this.reCall()
  60. }
  61. },
  62. async mounted() {
  63. try {
  64. const res = await request.post(`/api-teacher/open/videoShareProfit`, {
  65. data: {
  66. bizId: this.params.videoLessonGroupId,
  67. userId: this.recomUserId
  68. }
  69. })
  70. const result = res.data || {}
  71. const { lessonGroup, detailList } = result.videoGroup
  72. this.userInfo = {
  73. username: result.name,
  74. headUrl: result.avatar,
  75. buyNum: lessonGroup.countStudent,
  76. lessonNum: lessonGroup.lessonCount,
  77. lessonName: lessonGroup.lessonName,
  78. lessonDesc: lessonGroup.lessonDesc,
  79. lessonPrice: lessonGroup.lessonPrice,
  80. lessonCoverUrl: lessonGroup.lessonCoverUrl
  81. }
  82. this.detailList = detailList || []
  83. } catch {
  84. //
  85. }
  86. console.log()
  87. },
  88. methods: {
  89. reCall() {
  90. const { origin } = location
  91. let str = origin + '/student/#/videoDetail'
  92. const params = this.$route.query
  93. str += `?recomUserId=${this.recomUserId}&groupId=${params.groupId}`
  94. console.log(str)
  95. shareCall(str, {})
  96. },
  97. onShare() {
  98. if (browser().weixin) {
  99. this.wxStatus = true
  100. return
  101. }
  102. this.reCall()
  103. setTimeout(() => {
  104. window.location.href = location.origin + '/student/#/download'
  105. }, 3000)
  106. }
  107. },
  108. render() {
  109. return (
  110. <div class={[styles['video-detail'], 'mb12']}>
  111. <UserDetail userInfo={this.userInfo} />
  112. <SectionDetail border>
  113. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  114. </SectionDetail>
  115. <SectionDetail
  116. title="课程列表"
  117. icon="courseList"
  118. contentStyle={{ paddingTop: '0' }}
  119. >
  120. {this.detailList.map((item: any) => (
  121. <CourseVideoItem
  122. class={'mb12'}
  123. detail={{
  124. id: item.id,
  125. title: item.videoTitle,
  126. content: item.videoContent,
  127. imgUrl: item.coverUrl
  128. }}
  129. />
  130. ))}
  131. </SectionDetail>
  132. <ColSticky position="bottom">
  133. <div class={['btnGroup']} style={{ paddingTop: '12px' }}>
  134. <Button block round type="primary" onClick={this.onShare}>
  135. 下载酷乐秀进入课程
  136. </Button>
  137. </div>
  138. </ColSticky>
  139. {this.wxStatus && (
  140. <div
  141. class={styles.wxpopup}
  142. onClick={() => {
  143. this.wxStatus = false
  144. }}
  145. >
  146. <img src={getAssetsHomeFile('wx_bg.png')} alt="" />
  147. </div>
  148. )}
  149. </div>
  150. )
  151. }
  152. })