index.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import OEmpty from '@/components/o-empty'
  2. import OHeader from '@/components/o-header'
  3. import OSticky from '@/components/o-sticky'
  4. import request from '@/helpers/request'
  5. import TeacherList from '@/school/orchestra/modal/teacher-list'
  6. import { Button, Cell, Popup, showToast, Sticky } from 'vant'
  7. import { defineComponent, onMounted, reactive, watch } from 'vue'
  8. import styles from './index.module.less'
  9. export default defineComponent({
  10. name: 'class-list',
  11. props: {
  12. classList: {
  13. type: Array,
  14. default: () => []
  15. }
  16. },
  17. emits: ['close', 'confirm'],
  18. setup(props, { slots, attrs, emit }) {
  19. const state = reactive({
  20. teacherStatus: false,
  21. list: [] as any,
  22. isClick: false,
  23. selectItem: {} as any // 选择的班级
  24. })
  25. // 可以不用全部设置完
  26. const onSubmit = async () => {
  27. try {
  28. const tempList: any = []
  29. state.list.forEach((item: any) => {
  30. // 判断是否已经设置过伴学老师
  31. if (item.teacherId) {
  32. tempList.push({
  33. classGroupId: item.id,
  34. teacherId: item.teacherId
  35. })
  36. }
  37. })
  38. if (tempList.length <= 0) {
  39. emit('close')
  40. return
  41. }
  42. state.isClick = true
  43. await request.post('/api-school/classGroup/updateTeacher', {
  44. data: tempList
  45. })
  46. setTimeout(() => {
  47. showToast('设置成功')
  48. }, 100)
  49. setTimeout(() => {
  50. state.isClick = false
  51. emit('confirm')
  52. emit('close')
  53. }, 1100)
  54. } catch {
  55. //
  56. state.isClick = false
  57. }
  58. // emit('close')
  59. }
  60. // 监听变化
  61. watch(
  62. () => props.classList,
  63. () => {
  64. state.list = [...props.classList]
  65. }
  66. )
  67. onMounted(() => {
  68. state.list = [...props.classList]
  69. })
  70. return () => (
  71. <div class={styles.classList}>
  72. <OHeader title="指定伴学老师" desotry={false} />
  73. {state.list.map((item: any) => (
  74. <Cell
  75. class={styles.cell}
  76. center
  77. isLink
  78. onClick={() => {
  79. state.selectItem = item
  80. state.teacherStatus = true
  81. }}
  82. >
  83. {{
  84. title: () => (
  85. <div class={styles.content}>
  86. <div class={styles.title}>
  87. <i></i>
  88. {item.name}
  89. </div>
  90. <div class={styles.name}>{item.orchestraName}</div>
  91. </div>
  92. ),
  93. value: () => <span class={styles.teacherName}>{item.teacherName}</span>
  94. }}
  95. </Cell>
  96. ))}
  97. {/* 判断是否有班级没有设置伴学指导 */}
  98. {props.classList.length <= 0 && (
  99. <OEmpty btnStatus={false} classImgSize="SMALL" tips="暂无班级" />
  100. )}
  101. <Sticky position="bottom">
  102. <div class={'btnGroup'}>
  103. <Button
  104. round
  105. block
  106. type="primary"
  107. size="large"
  108. onClick={onSubmit}
  109. disabled={state.isClick}
  110. >
  111. 完成
  112. </Button>
  113. </div>
  114. </Sticky>
  115. <Popup v-model:show={state.teacherStatus} position="bottom" round style={{ height: '80%' }}>
  116. <TeacherList
  117. header={false}
  118. mode={'sticky'}
  119. courseType={state.selectItem.type}
  120. onClose={() => (state.teacherStatus = false)}
  121. onSelect={(val: any) => {
  122. state.selectItem.teacherId = val.id
  123. state.selectItem.teacherName = val.nickname
  124. }}
  125. />
  126. </Popup>
  127. </div>
  128. )
  129. }
  130. })