select-teacher.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import OHeader from '@/components/o-header'
  2. import OPopup from '@/components/o-popup'
  3. import OSticky from '@/components/o-sticky'
  4. import { Button, Cell, CellGroup, Dialog, Field, showDialog, showToast } from 'vant'
  5. import { defineComponent, reactive } from 'vue'
  6. import TeacherList from '../modal/teacher-list'
  7. import styles from './select-teacher.module.less'
  8. import { state as baseState } from '@/state'
  9. import { createState as state, resestState } from './create'
  10. import { useRouter } from 'vue-router'
  11. import request from '@/helpers/request'
  12. import ODialog from '@/components/o-dialog'
  13. export default defineComponent({
  14. name: 'teacher-list',
  15. emits: ['close'],
  16. setup() {
  17. const router = useRouter()
  18. const forms = reactive({
  19. teacherStatus: false,
  20. status: false
  21. })
  22. console.log(state.selectLastTeacherSubjects)
  23. const onSubmit = async () => {
  24. // forms.status = true
  25. showDialog({
  26. title: '提示',
  27. message: '是否创建乐团?',
  28. showCancelButton: true
  29. }).then(async () => {
  30. try {
  31. const selectSubjects = state.selectLastTeacherSubjects || []
  32. const tempSelects: any = []
  33. selectSubjects.forEach((item: any) => {
  34. tempSelects.push({
  35. teacherId: item.teacher.id,
  36. type: item.type,
  37. subjectId: item.id,
  38. studentIdList: [...item.students]
  39. })
  40. })
  41. console.log(tempSelects, 'tempselects')
  42. // return
  43. await request.post('/api-school/orchestra/addOrchestra', {
  44. hideLoading: false,
  45. data: {
  46. schoolId: baseState.user.data.school.id,
  47. name: state.orchestraName,
  48. classGroupList: [...tempSelects]
  49. }
  50. })
  51. showToast('创建成功')
  52. forms.status = true
  53. } catch {
  54. //
  55. }
  56. })
  57. }
  58. const formatSubjectIds = (id: any) => {
  59. if (id) {
  60. const tempId = id.toString()
  61. return tempId.split(',')
  62. }
  63. return id
  64. }
  65. const onConfirm = () => {
  66. resestState()
  67. router.replace('/train-planning')
  68. }
  69. // 取消
  70. const onCancel = () => {
  71. resestState()
  72. router.replace('/my-orchestra')
  73. }
  74. return () => (
  75. <div class={styles.selectTeacher}>
  76. <OHeader title="选择伴学指导" />
  77. <CellGroup inset class={styles.cellGroup}>
  78. {state.selectLastTeacherSubjects.map((subject: any) => (
  79. <Cell
  80. center
  81. onClick={() => {
  82. forms.teacherStatus = true
  83. state.selectTeacher = subject
  84. }}
  85. isLink
  86. >
  87. {{
  88. title: () => <span class={styles.title}>{subject.name}</span>,
  89. value: () => (
  90. <>
  91. {subject.teacher?.nickname ? (
  92. <p class={styles.name}>{subject.teacher?.nickname || ''}</p>
  93. ) : (
  94. <p class={styles.tips}>请选择伴学指导</p>
  95. )}
  96. </>
  97. )
  98. }}
  99. </Cell>
  100. ))}
  101. </CellGroup>
  102. <OSticky position="bottom">
  103. <div class={['btnGroup']}>
  104. <Button type="primary" round block onClick={onSubmit}>
  105. 创建完成
  106. </Button>
  107. </div>
  108. </OSticky>
  109. <OPopup v-model:modelValue={forms.teacherStatus} position="bottom">
  110. <TeacherList
  111. subjectIdList={formatSubjectIds(state.selectTeacher.id)}
  112. onClose={() => (forms.teacherStatus = false)}
  113. onSelect={(item: any) => {
  114. state.selectTeacher.teacher = item
  115. forms.teacherStatus = false
  116. // console.log(state.selectTeacher, 'select')
  117. // console.log(state.selectSubjects, 'state.selectSubjects')
  118. }}
  119. />
  120. </OPopup>
  121. <ODialog
  122. v-model:show={forms.status}
  123. title="创建成功"
  124. messageAlign="left"
  125. confirmButtonText="去排课"
  126. cancelButtonText="暂不排课"
  127. showCancelButton
  128. message="乐团创建完成,是否需要排课?"
  129. onConfirm={onConfirm}
  130. onCancel={onCancel}
  131. ></ODialog>
  132. </div>
  133. )
  134. }
  135. })