detail.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 { state } from '@/state'
  6. import { Button, Dialog, Sticky, Toast } from 'vant'
  7. import { defineComponent } from 'vue'
  8. import { createState } from './createState'
  9. import styles from './detail.module.less'
  10. import dayjs from 'dayjs'
  11. import { postMessage } from '@/helpers/native-message'
  12. interface IProps {
  13. courseTime: string
  14. coursePlan: string
  15. videoPosterUrl?: string
  16. roomUid?: string
  17. liveState?: number
  18. id?: number | string
  19. }
  20. export default defineComponent({
  21. name: 'detail',
  22. computed: {
  23. userInfo() {
  24. const startTime = createState.live.coursePlanList[0].startTime
  25. const endTime = createState.live.coursePlanList[0].endTime
  26. return {
  27. headUrl: state.user.data?.heardUrl,
  28. username:
  29. state.user.data?.username || `游客${state.user.data?.userId || ''}`,
  30. startTime:
  31. `${dayjs(startTime).format('YYYY-MM-DD')} ${dayjs(startTime).format(
  32. 'HH:mm'
  33. )}~${dayjs(endTime).format('HH:mm')}` || '',
  34. buyNum: 0,
  35. lessonPrice: createState.live.coursePrice,
  36. lessonNum: createState.live.courseNum,
  37. lessonDesc: createState.live.courseIntroduce,
  38. lessonCoverUrl:
  39. createState.live.backgroundPic ||
  40. createState.live.backgroundPicTemplate,
  41. lessonName: createState.live.name,
  42. auditVersion:0
  43. }
  44. },
  45. courseInfo() {
  46. const tempArr = [] as IProps[]
  47. const coursePlanList = createState.live.coursePlanList || []
  48. coursePlanList.forEach((item: any) => {
  49. tempArr.push({
  50. courseTime: `${dayjs(item.startTime).format('YYYY-MM-DD')} ${dayjs(
  51. item.startTime
  52. ).format('HH:mm')}~${dayjs(item.endTime).format('HH:mm')}`,
  53. roomUid: item.roomUid,
  54. liveState: item.liveState,
  55. coursePlan: item.plan,
  56. id: item.courseId
  57. })
  58. })
  59. return tempArr || []
  60. }
  61. },
  62. methods: {
  63. async onSubmit() {
  64. try {
  65. const params = {
  66. ...createState.live,
  67. startTime: createState.live.coursePlanList[0].startTime,
  68. backgroundPic:
  69. createState.live.backgroundPic ||
  70. createState.live.backgroundPicTemplate,
  71. teacherId: state.user.data?.userId
  72. }
  73. await request.post('/api-teacher/courseGroup/addLiveCourse', {
  74. data: params
  75. })
  76. Toast.success('创建成功')
  77. setTimeout(() => {
  78. postMessage({ api: 'back' })
  79. }, 1000)
  80. } catch (e: any) {
  81. // 报错时需要重置日历表的数据
  82. const message = e.message
  83. Dialog.alert({
  84. title: '提示',
  85. confirmButtonColor: 'var(--van-primary)',
  86. message
  87. }).then(() => {
  88. createState.active = 3
  89. createState.selectCourseList = []
  90. createState.live.salesStartDate = ''
  91. createState.live.salesEndDate = ''
  92. createState.live.mixStudentNum = null
  93. createState.live.backgroundPic = ''
  94. createState.live.backgroundPicTemplate = ''
  95. createState.coursePlanStatus = false
  96. })
  97. }
  98. },
  99. async onUpdate(){
  100. const params = {
  101. id: createState.live.courseGroupId,
  102. ...createState.live,
  103. startTime: createState.live.coursePlanList[0].startTime,
  104. backgroundPic:
  105. createState.live.backgroundPic ||
  106. createState.live.backgroundPicTemplate,
  107. }
  108. console.log({...params})
  109. await request.post('/api-teacher/courseGroup/updateLiveCourse', {
  110. data: params
  111. })
  112. Toast({
  113. type: 'success',
  114. message: '编辑成功',
  115. duration: 1000,
  116. onClose: () => {
  117. postMessage({ api: 'back' })
  118. }
  119. })
  120. }
  121. },
  122. render() {
  123. return (
  124. <div class={[styles['detail']]}>
  125. <UserDetail userInfo={this.userInfo} />
  126. <SectionDetail>
  127. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  128. </SectionDetail>
  129. <SectionDetail
  130. title="课程安排"
  131. icon="courseList"
  132. titleShow={false}
  133. class={'mb12'}
  134. contentStyle={{ paddingTop: '0' }}
  135. >
  136. <CoursePlanStep courseInfo={this.courseInfo} />
  137. </SectionDetail>
  138. <Sticky offsetBottom={0} position="bottom">
  139. <div class={['btnGroup', 'btnMore']}>
  140. <Button
  141. block
  142. round
  143. type="primary"
  144. plain
  145. onClick={() => {
  146. createState.active = 4
  147. }}
  148. >
  149. 返回编辑
  150. </Button>
  151. {createState.live.courseGroupId ? (
  152. <Button block round type="primary" onClick={this.onUpdate}>
  153. 确认修改
  154. </Button>
  155. ) : (
  156. <Button block round type="primary" onClick={this.onSubmit}>
  157. 创建成功
  158. </Button>
  159. )}
  160. </div>
  161. </Sticky>
  162. </div>
  163. )
  164. }
  165. })