detail.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. type: 'group',
  36. mixStudentNum: createState.live.mixStudentNum,
  37. lessonPrice: createState.live.coursePrice,
  38. lessonNum: createState.live.courseNum,
  39. lessonDesc: createState.live.courseIntroduce,
  40. lessonCoverUrl:
  41. createState.live.backgroundPic ||
  42. createState.live.backgroundPicTemplate,
  43. lessonName: createState.live.name,
  44. auditVersion:0
  45. }
  46. },
  47. courseInfo() {
  48. const tempArr = [] as IProps[]
  49. const coursePlanList = createState.live.coursePlanList || []
  50. coursePlanList.forEach((item: any) => {
  51. tempArr.push({
  52. courseTime: `${dayjs(item.startTime).format('YYYY-MM-DD')} ${dayjs(
  53. item.startTime
  54. ).format('HH:mm')}~${dayjs(item.endTime).format('HH:mm')}`,
  55. roomUid: item.roomUid,
  56. liveState: item.liveState,
  57. coursePlan: item.plan,
  58. id: item.courseId
  59. })
  60. })
  61. return tempArr || []
  62. }
  63. },
  64. data() {
  65. return {
  66. submitLoading: false
  67. }
  68. },
  69. methods: {
  70. async onSubmit() {
  71. if(this.submitLoading) return
  72. this.submitLoading = true;
  73. try {
  74. const params = {
  75. ...createState.live,
  76. startTime: createState.live.coursePlanList[0].startTime,
  77. backgroundPic:
  78. createState.live.backgroundPic ||
  79. createState.live.backgroundPicTemplate,
  80. teacherId: state.user.data?.userId,
  81. version: state.version,
  82. platform: state.platformType === 'STUDENT' ? 'ios-student' : 'ios-teacher',
  83. }
  84. await request.post('/api-teacher/courseGroup/addLiveCourse', {
  85. data: params
  86. })
  87. Toast.success('创建成功')
  88. setTimeout(() => {
  89. postMessage({ api: 'back' })
  90. }, 1000)
  91. } catch (e: any) {
  92. // 报错时需要重置日历表的数据
  93. const message = e.message
  94. Dialog.alert({
  95. title: '提示',
  96. confirmButtonColor: 'var(--van-primary)',
  97. message
  98. }).then(() => {
  99. createState.active = 3
  100. createState.selectCourseList = []
  101. createState.live.salesStartDate = ''
  102. createState.live.salesEndDate = ''
  103. createState.live.mixStudentNum = null
  104. createState.live.backgroundPic = ''
  105. createState.live.backgroundPicTemplate = ''
  106. createState.coursePlanStatus = false
  107. })
  108. }
  109. this.submitLoading = false;
  110. },
  111. async onUpdate() {
  112. if(this.submitLoading) return
  113. this.submitLoading = true;
  114. const params = {
  115. id: createState.live.courseGroupId,
  116. ...createState.live,
  117. startTime: createState.live.coursePlanList[0].startTime,
  118. backgroundPic:
  119. createState.live.backgroundPic ||
  120. createState.live.backgroundPicTemplate,
  121. }
  122. console.log({...params})
  123. await request.post('/api-teacher/courseGroup/updateLiveCourse', {
  124. data: params
  125. })
  126. this.submitLoading = false
  127. Toast({
  128. type: 'success',
  129. message: '编辑成功',
  130. duration: 1000,
  131. onClose: () => {
  132. postMessage({ api: 'back' })
  133. }
  134. })
  135. }
  136. },
  137. render() {
  138. return (
  139. <div class={[styles['detail']]}>
  140. <UserDetail userInfo={this.userInfo} />
  141. <SectionDetail>
  142. <p class={styles.introduction}>{this.userInfo.lessonDesc}</p>
  143. </SectionDetail>
  144. <SectionDetail
  145. title="课程安排"
  146. icon="courseList"
  147. titleShow={false}
  148. class={'mb12'}
  149. contentStyle={{ paddingTop: '0' }}
  150. >
  151. <CoursePlanStep courseInfo={this.courseInfo} />
  152. </SectionDetail>
  153. <Sticky offsetBottom={0} position="bottom">
  154. <div class={['btnGroup', 'btnMore']}>
  155. <Button
  156. block
  157. round
  158. type="primary"
  159. plain
  160. onClick={() => {
  161. createState.active = 4
  162. }}
  163. >
  164. 返回编辑
  165. </Button>
  166. {createState.live.courseGroupId ? (
  167. <Button block round type="primary" disabled={this.submitLoading} onClick={this.onUpdate}>
  168. 确认修改
  169. </Button>
  170. ) : (
  171. <Button block round type="primary" disabled={this.submitLoading} onClick={this.onSubmit}>
  172. 创建成功
  173. </Button>
  174. )}
  175. </div>
  176. </Sticky>
  177. </div>
  178. )
  179. }
  180. })