unbind.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import OHeader from '@/components/o-header'
  2. import OSticky from '@/components/o-sticky'
  3. import { Button, Cell, CellGroup, Image, showDialog, showToast } from 'vant'
  4. import { defineComponent, onMounted, reactive } from 'vue'
  5. import styles from './unbind.module.less'
  6. import { state as baseState } from '@/state'
  7. import { useRoute, useRouter } from 'vue-router'
  8. import request from '@/helpers/request'
  9. import OPopup from '@/components/o-popup'
  10. import Teacher from './compontent/teacher'
  11. export default defineComponent({
  12. name: 'unbind',
  13. setup() {
  14. const route = useRoute()
  15. const router = useRouter()
  16. const state = reactive({
  17. teacherStatus: false,
  18. classList: [] as any,
  19. selectTeacher: {} as any,
  20. teacherId: route.query.id
  21. })
  22. const getClassDetail = async () => {
  23. try {
  24. const { data } = await request.post('/api-school/classGroup/page', {
  25. data: {
  26. teacherId: state.teacherId,
  27. schoolId: baseState.user.data.school.id,
  28. page: 1,
  29. rows: 100
  30. }
  31. })
  32. state.classList = data.rows || []
  33. } catch {
  34. //
  35. }
  36. }
  37. // 选择交接老师
  38. const onSelectTeacher = (item: any) => {
  39. state.teacherStatus = true
  40. state.selectTeacher = item
  41. }
  42. // 选择了交接老师之后
  43. const onSelectItem = (item: any) => {
  44. console.log(item, 'steacher')
  45. state.selectTeacher.sTeacher = item
  46. }
  47. const onSubmit = () => {
  48. console.log('submit')
  49. let isSelectAll = false // 是否有没有选择交接老师的数据
  50. const courseInfo = [] as any
  51. state.classList.forEach((item: any) => {
  52. if (!item.sTeacher || (item.sTeacher && !item.sTeacher.id)) {
  53. isSelectAll = true
  54. }
  55. if (item.sTeacher) {
  56. courseInfo.push({
  57. classGroupId: item.id,
  58. teacherId: item.sTeacher.id
  59. })
  60. }
  61. })
  62. if (isSelectAll) {
  63. showToast('请选择交接老师')
  64. return
  65. }
  66. try {
  67. showDialog({
  68. title: '提示',
  69. message: '是否确认交接',
  70. showCancelButton: true
  71. }).then(async () => {
  72. await request.post('/api-school/classGroup/handoverTeacher', {
  73. data: {
  74. teacherId: route.query.id,
  75. updateTeacherList: [...courseInfo]
  76. }
  77. })
  78. setTimeout(() => {
  79. showToast('交接成功')
  80. }, 100)
  81. setTimeout(() => {
  82. router.replace('/companion-teacher')
  83. }, 1000)
  84. })
  85. } catch {
  86. //
  87. }
  88. }
  89. onMounted(() => {
  90. getClassDetail()
  91. })
  92. return () => (
  93. <>
  94. <OHeader />
  95. <div class={styles.unbindTips}>该伴学老师存在以下班级及课程未开始,请选择交接老师</div>
  96. <CellGroup inset class={styles.detailCellGroup}>
  97. {state.classList.map((item: any) => (
  98. <Cell
  99. center
  100. class={styles.detailCell}
  101. isLink
  102. onClick={() => onSelectTeacher(item)}
  103. valueClass={styles.valueClass}
  104. >
  105. {{
  106. title: () => (
  107. <div class={styles.teacherContent}>
  108. <div class={styles.classInfo}>
  109. <p class={styles.className}>{item.name}</p>
  110. <p class={[styles.musicName, 'van-ellipsis']}>{item.orchestraName}</p>
  111. </div>
  112. <div class={styles.classNum}>
  113. <p class={styles.nums}>
  114. {item.courseScheduleNum - item.completeCourseScheduleNum}
  115. </p>
  116. <p class={styles.numTip}>剩余课时</p>
  117. </div>
  118. </div>
  119. ),
  120. value: () => (
  121. <div class={[styles.teacherName, 'van-ellipsis']}>
  122. {item.sTeacher && item.sTeacher.nickname}
  123. </div>
  124. )
  125. }}
  126. </Cell>
  127. ))}
  128. </CellGroup>
  129. <OSticky position="bottom">
  130. <div class={['btnGroup']} style={{ paddingLeft: '13px', paddingRight: '13px' }}>
  131. <Button type="primary" round block onClick={onSubmit}>
  132. 确认交接
  133. </Button>
  134. </div>
  135. </OSticky>
  136. <OPopup v-model:modelValue={state.teacherStatus}>
  137. <Teacher
  138. courseType={state.selectTeacher.courseType}
  139. teacherId={state.teacherId as any}
  140. onClose={() => (state.teacherStatus = false)}
  141. onSelect={onSelectItem}
  142. />
  143. </OPopup>
  144. </>
  145. )
  146. }
  147. })