index.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. state.isClick = false
  47. emit('confirm')
  48. emit('close')
  49. } catch {
  50. //
  51. state.isClick = false
  52. }
  53. // emit('close')
  54. }
  55. // 监听变化
  56. watch(
  57. () => props.classList,
  58. () => {
  59. state.list = [...props.classList]
  60. }
  61. )
  62. onMounted(() => {
  63. state.list = [...props.classList]
  64. })
  65. return () => (
  66. <div class={[styles.classList, state.list.length <= 0 && 'emptyRootContainer']}>
  67. <OHeader title="指定伴学老师" desotry={false} />
  68. {state.list.map((item: any) => (
  69. <Cell
  70. class={styles.cell}
  71. center
  72. isLink
  73. onClick={() => {
  74. state.selectItem = item
  75. state.teacherStatus = true
  76. }}
  77. valueClass={[styles.teacherName, 'van-ellipsis']}
  78. >
  79. {{
  80. title: () => (
  81. <div class={styles.content}>
  82. <div class={styles.title}>
  83. <i></i>
  84. {item.name}
  85. </div>
  86. <div class={[styles.name, 'van-ellipsis']}>{item.orchestraName}</div>
  87. </div>
  88. ),
  89. value: () => (
  90. <div
  91. style={{
  92. color: item.teacherName ? '' : 'var(--van-primary)'
  93. }}
  94. >
  95. {item.teacherName ? item.teacherName : '去设置'}
  96. </div>
  97. )
  98. }}
  99. </Cell>
  100. ))}
  101. {/* 判断是否有班级没有设置伴学老师 */}
  102. {props.classList.length <= 0 && <OEmpty btnStatus={false} tips="暂无班级" />}
  103. <Sticky position="bottom" style={{ width: '100%' }}>
  104. <div class={'btnGroup'}>
  105. <Button round block type="primary" onClick={onSubmit} disabled={state.isClick}>
  106. 完成
  107. </Button>
  108. </div>
  109. </Sticky>
  110. <Popup v-model:show={state.teacherStatus} position="bottom" round style={{ height: '80%' }}>
  111. <TeacherList
  112. header={false}
  113. mode={'sticky'}
  114. courseType={state.selectItem.courseType}
  115. onClose={() => (state.teacherStatus = false)}
  116. onSelect={(val: any) => {
  117. state.selectItem.teacherId = val.id
  118. state.selectItem.teacherName = val.nickname
  119. }}
  120. />
  121. </Popup>
  122. </div>
  123. )
  124. }
  125. })