detail.tsx 6.0 KB

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