detail.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. import TheSticky from '@/components/the-sticky'
  13. interface IProps {
  14. courseTime: string
  15. coursePlan: string
  16. videoPosterUrl?: string
  17. roomUid?: string
  18. liveState?: number
  19. id?: number | string
  20. }
  21. export default defineComponent({
  22. name: 'detail',
  23. computed: {
  24. userInfo() {
  25. const startTime = createState.live.coursePlanList[0].startTime
  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. )}` || '',
  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. data() {
  63. return {
  64. submitLoading: false
  65. }
  66. },
  67. methods: {
  68. async onSubmit() {
  69. if(this.submitLoading) return
  70. this.submitLoading = true;
  71. try {
  72. const params = {
  73. ...createState.live,
  74. startTime: createState.live.coursePlanList[0].startTime,
  75. backgroundPic:
  76. createState.live.backgroundPic ||
  77. createState.live.backgroundPicTemplate,
  78. teacherId: state.user.data?.userId,
  79. version: state.version,
  80. platform: state.platformType === 'STUDENT' ? 'ios-student' : 'ios-teacher',
  81. }
  82. await request.post('/api-teacher/courseGroup/addLiveCourse', {
  83. data: params
  84. })
  85. Toast.success('创建成功')
  86. setTimeout(() => {
  87. postMessage({ api: 'back' })
  88. }, 1000)
  89. } catch (e: any) {
  90. // 报错时需要重置日历表的数据
  91. const message = e.message
  92. Dialog.alert({
  93. title: '提示',
  94. confirmButtonColor: 'var(--van-primary)',
  95. message
  96. }).then(() => {
  97. createState.active = 3
  98. createState.selectCourseList = []
  99. createState.live.salesStartDate = ''
  100. createState.live.salesEndDate = ''
  101. createState.live.mixStudentNum = null
  102. createState.live.backgroundPic = ''
  103. createState.live.backgroundPicTemplate = ''
  104. createState.coursePlanStatus = false
  105. })
  106. }
  107. this.submitLoading = false;
  108. },
  109. async onUpdate() {
  110. if(this.submitLoading) return
  111. this.submitLoading = true;
  112. const params = {
  113. id: createState.live.courseGroupId,
  114. ...createState.live,
  115. startTime: createState.live.coursePlanList[0].startTime,
  116. backgroundPic:
  117. createState.live.backgroundPic ||
  118. createState.live.backgroundPicTemplate,
  119. }
  120. console.log({...params})
  121. await request.post('/api-teacher/courseGroup/updateLiveCourse', {
  122. data: params
  123. })
  124. this.submitLoading = false
  125. Toast({
  126. type: 'success',
  127. message: '编辑成功',
  128. duration: 1000,
  129. onClose: () => {
  130. postMessage({ api: 'back' })
  131. }
  132. })
  133. }
  134. },
  135. render() {
  136. return (
  137. <div class={[styles['detail']]}>
  138. <UserDetail userInfo={this.userInfo} />
  139. <SectionDetail>
  140. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  141. </SectionDetail>
  142. <SectionDetail
  143. title="课程安排"
  144. icon="courseList"
  145. titleShow={false}
  146. class={'mb12'}
  147. contentStyle={{ paddingTop: '0' }}
  148. >
  149. <CoursePlanStep courseInfo={this.courseInfo} />
  150. </SectionDetail>
  151. <TheSticky position="bottom">
  152. <div class={['btnGroup', styles.btnMore]}>
  153. <Button
  154. block
  155. round
  156. type="primary"
  157. plain
  158. onClick={() => {
  159. createState.active = 4
  160. }}
  161. >
  162. 返回编辑
  163. </Button>
  164. {createState.live.courseGroupId ? (
  165. <Button block round type="primary" disabled={this.submitLoading} onClick={this.onUpdate}>
  166. 确认修改
  167. </Button>
  168. ) : (
  169. <Button block round type="primary" disabled={this.submitLoading} onClick={this.onSubmit}>
  170. 创建成功
  171. </Button>
  172. )}
  173. </div>
  174. </TheSticky>
  175. </div>
  176. )
  177. }
  178. })