video-detail.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 UserList from '@/business-components/user-list'
  5. import { Button, List, Popup, Sticky, Tab, Tabs, Toast } from 'vant'
  6. import { defineComponent } from 'vue'
  7. import styles from './video-detail.module.less'
  8. import request from '@/helpers/request'
  9. import ColResult from '@/components/col-result'
  10. import ColShare from '@/components/col-share'
  11. import ColSticky from '@/components/col-sticky'
  12. import LiveItem from '@/views/live-class/live-item'
  13. export default defineComponent({
  14. name: 'VideoDetail',
  15. data() {
  16. const query = this.$route.query
  17. return {
  18. userInfo: {} as any,
  19. detailList: [],
  20. buyUserList: [], // 购买学生数
  21. dataShow: true, // 判断是否有数据
  22. loading: false,
  23. finished: false,
  24. share: query.share,
  25. params: {
  26. videoLessonGroupId: query.groupId,
  27. page: 1,
  28. rows: 20
  29. },
  30. shareStatus: false,
  31. shareUrl: ''
  32. }
  33. },
  34. async mounted() {
  35. try {
  36. const res = await request.get(
  37. '/api-teacher/videoLessonGroup/selectVideoLesson',
  38. {
  39. params: {
  40. groupId: this.params.videoLessonGroupId
  41. }
  42. }
  43. )
  44. const result = res.data || {}
  45. this.userInfo = {
  46. id: result.lessonGroup.teacherId,
  47. username: result.lessonGroup.username,
  48. headUrl: result.lessonGroup.avatar,
  49. buyNum: result.lessonGroup.countStudent,
  50. lessonId: result.lessonGroup.id,
  51. lessonNum: result.lessonGroup.lessonCount,
  52. lessonName: result.lessonGroup.lessonName,
  53. lessonDesc: result.lessonGroup.lessonDesc,
  54. lessonPrice: result.lessonGroup.lessonPrice,
  55. lessonCoverUrl: result.lessonGroup.lessonCoverUrl,
  56. lessonSubjectName: result.lessonGroup.lessonSubjectName
  57. }
  58. this.detailList = result.detailList || []
  59. // shareVideo?recomUserId=56&groupId=124
  60. this.shareUrl = `${location.origin}/teacher/#/shareVideo?recomUserId=${this.userInfo.id}&groupId=${this.params.videoLessonGroupId}`
  61. this.getList()
  62. } catch (e) {
  63. console.log(e)
  64. }
  65. },
  66. methods: {
  67. async getList() {
  68. try {
  69. const params = this.params
  70. const res = await request.post('/api-teacher/videoLesson/pageStudent', {
  71. data: {
  72. ...params
  73. }
  74. })
  75. this.loading = false
  76. const result = res.data || {}
  77. // 处理重复请求数据
  78. if (this.buyUserList.length > 0 && result.pageNo === 1) {
  79. return
  80. }
  81. this.buyUserList = this.buyUserList.concat(result.rows || [])
  82. this.finished = result.pageNo >= result.totalPage
  83. this.params.page = result.pageNo + 1
  84. this.dataShow = this.buyUserList.length > 0
  85. } catch {
  86. this.dataShow = false
  87. this.finished = true
  88. }
  89. },
  90. onPlay(detail: any) {
  91. this.$router.push({
  92. path: '/videoClassDetail',
  93. query: {
  94. groupId: this.params.videoLessonGroupId,
  95. classId: detail.id
  96. }
  97. })
  98. }
  99. },
  100. render() {
  101. return (
  102. <div class={[styles['video-detail'], 'mb12']}>
  103. {this.userInfo.id && <UserDetail userInfo={this.userInfo} />}
  104. <SectionDetail border>
  105. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  106. </SectionDetail>
  107. <SectionDetail
  108. title="课程列表"
  109. icon="courseList"
  110. titleShow={false}
  111. contentStyle={{ paddingTop: '0' }}
  112. >
  113. <Tabs color="var(--van-primary)" lineWidth={20} sticky>
  114. <Tab title="课程" titleClass="van-hairline--bottom">
  115. {this.detailList.map((item: any) => (
  116. <CourseVideoItem
  117. class={'mb12'}
  118. detail={{
  119. id: item.id,
  120. title: item.videoTitle,
  121. content: item.videoContent,
  122. imgUrl: item.coverUrl
  123. }}
  124. onPlay={this.onPlay}
  125. />
  126. ))}
  127. </Tab>
  128. <Tab title="学员列表" titleClass="van-hairline--bottom">
  129. {this.dataShow ? (
  130. <List
  131. v-model:loading={this.loading}
  132. finished={this.finished}
  133. finishedText="没有更多了"
  134. onLoad={this.getList}
  135. >
  136. {this.buyUserList.map((item: any) => (
  137. <UserList
  138. class="mb12"
  139. users={{
  140. avatar: item.avatar,
  141. studentId: item.userId,
  142. studentName: item.username,
  143. createTime: item.createTime
  144. }}
  145. />
  146. ))}
  147. </List>
  148. ) : (
  149. <ColResult
  150. btnStatus={false}
  151. classImgSize="SMALL"
  152. tips="暂无学生购买"
  153. />
  154. )}
  155. </Tab>
  156. </Tabs>
  157. </SectionDetail>
  158. {this.share == '1' && this.detailList.length > 0 && (
  159. <ColSticky position="bottom">
  160. <div class={['btnGroup']} style={{ paddingTop: '12px' }}>
  161. <Button
  162. block
  163. round
  164. type="primary"
  165. onClick={() => {
  166. this.shareStatus = true
  167. }}
  168. >
  169. 分享课程
  170. </Button>
  171. </div>
  172. </ColSticky>
  173. )}
  174. <Popup
  175. v-model:show={this.shareStatus}
  176. style={{ background: 'transparent' }}
  177. >
  178. <ColShare teacherId={this.userInfo.id} shareUrl={this.shareUrl}>
  179. <LiveItem
  180. class={styles.shareCourse}
  181. liveInfo={{
  182. backgroundPic: this.userInfo.lessonCoverUrl,
  183. courseGroupId: this.userInfo.lessonId,
  184. courseGroupName: this.userInfo.lessonName,
  185. courseNum: this.userInfo.lessonNum,
  186. coursePrice: this.userInfo.lessonPrice,
  187. teacherName: this.userInfo.username,
  188. teacherId: this.userInfo.id,
  189. avatar: this.userInfo.avatar,
  190. studentCount: this.userInfo.buyNum,
  191. existBuy: 0,
  192. subjectName: this.userInfo.lessonSubjectName
  193. }}
  194. />
  195. </ColShare>
  196. </Popup>
  197. </div>
  198. )
  199. }
  200. })