live-detail.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 UserList from '@/business-components/user-list'
  5. import ColResult from '@/components/col-result'
  6. import { postMessage } from '@/helpers/native-message'
  7. import request from '@/helpers/request'
  8. import { state } from '@/state'
  9. import dayjs from 'dayjs'
  10. import { Button, Sticky, Tab, Tabs, Toast } from 'vant'
  11. import { defineComponent } from 'vue'
  12. import styles from './live-detail.module.less'
  13. interface IProps {
  14. courseTime: string
  15. coursePlan: string
  16. videoPosterUrl?: string
  17. id?: number | string
  18. }
  19. export default defineComponent({
  20. name: 'LiveDetail',
  21. data() {
  22. const query = this.$route.query
  23. return {
  24. groupId: query.groupId,
  25. courseId: query.courseId,
  26. live: {} as any
  27. }
  28. },
  29. computed: {
  30. userInfo() {
  31. const live = this.live as any
  32. const planList = live.planList || []
  33. const startTime = planList[0]?.startTime || new Date()
  34. const endTime = planList[0]?.endTime || new Date()
  35. return {
  36. headUrl: state.user.data?.heardUrl,
  37. username:
  38. state.user.data?.username || `游客${state.user.data?.userId || ''}`,
  39. startTime:
  40. `${dayjs(startTime).format('YYYY-MM-DD')} ${dayjs(startTime).format(
  41. 'HH:mm'
  42. )}~${dayjs(endTime).format('HH:mm')}` || '',
  43. lessonPrice: live.coursePrice,
  44. buyNum: live.studentCount || 0,
  45. lessonDesc: live.courseIntroduce,
  46. lessonCoverUrl: live.backgroundPic || live.backgroundPicTemplate,
  47. lessonName: live.courseGroupName
  48. }
  49. },
  50. courseInfo() {
  51. let tempArr = [] as IProps[]
  52. const coursePlanList = this.live.planList || []
  53. coursePlanList.forEach((item: any) => {
  54. const startTime = item.startTime || new Date()
  55. const endTime = item.endTime || new Date()
  56. tempArr.push({
  57. courseTime: `${dayjs(startTime).format('YYYY-MM-DD')} ${dayjs(
  58. startTime
  59. ).format('HH:mm')}~${dayjs(endTime).format('HH:mm')}`,
  60. coursePlan: item.plan,
  61. id: item.id
  62. })
  63. })
  64. return tempArr || []
  65. },
  66. studentList() {
  67. const live = this.live as any
  68. return live.studentList || []
  69. },
  70. courseOffStatus() {
  71. const live = this.live as any
  72. let status = false
  73. if (
  74. (live.status === 'APPLY' && live.studentList.length === 0) ||
  75. live.status === 'NOT_SALE'
  76. ) {
  77. status = true
  78. }
  79. return status
  80. }
  81. },
  82. async mounted() {
  83. try {
  84. const res = await request.get(
  85. '/api-teacher/courseGroup/queryLiveCourseInfo',
  86. {
  87. params: {
  88. groupId: this.groupId
  89. }
  90. }
  91. )
  92. console.log(res)
  93. this.live = res.data || {}
  94. console.log(this.live)
  95. } catch {}
  96. },
  97. methods: {
  98. async cancelCourseGroup() {
  99. try {
  100. const res = await request.get(
  101. '/api-teacher/courseGroup/cancelCourseGroup',
  102. {
  103. params: {
  104. groupId: this.groupId
  105. }
  106. }
  107. )
  108. Toast('下架成功')
  109. setTimeout(() => {
  110. postMessage({ api: 'back', content: {} })
  111. }, 500)
  112. } catch {}
  113. }
  114. },
  115. render() {
  116. return (
  117. <div class={[styles['live-detail'], 'mb12']}>
  118. <UserDetail userInfo={this.userInfo} />
  119. <SectionDetail>
  120. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  121. </SectionDetail>
  122. <SectionDetail
  123. title="课程列表"
  124. icon="courseList"
  125. titleShow={false}
  126. contentStyle={{ paddingTop: '0' }}
  127. >
  128. <Tabs color="var(--van-primary)" lineWidth={20} sticky>
  129. <Tab title="课程" titleClass="van-hairline--bottom">
  130. <CoursePlanStep
  131. courseInfo={this.courseInfo}
  132. courseId={Number(this.courseId) || 0}
  133. />
  134. </Tab>
  135. <Tab title="学员列表" titleClass="van-hairline--bottom">
  136. {this.studentList.map((item: any) => (
  137. <UserList
  138. class="mb12"
  139. users={{
  140. avatar: item.avatar,
  141. studentId: item.studentId,
  142. studentName: item.userName,
  143. createTime: item.createTime
  144. }}
  145. />
  146. ))}
  147. {this.studentList.length === 0 && (
  148. <ColResult
  149. tips="暂无购买学员"
  150. classImgSize="SMALL"
  151. btnStatus={false}
  152. />
  153. )}
  154. </Tab>
  155. </Tabs>
  156. </SectionDetail>
  157. {this.courseOffStatus && (
  158. <Sticky offsetBottom={0} position="bottom">
  159. <div class={['btnGroup']} style={{ paddingTop: '12px' }}>
  160. <Button
  161. block
  162. round
  163. type="primary"
  164. onClick={this.cancelCourseGroup}
  165. >
  166. 下架
  167. </Button>
  168. </div>
  169. </Sticky>
  170. )}
  171. </div>
  172. )
  173. }
  174. })