index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { defineComponent, onMounted, reactive, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import { NInput, NScrollbar, NSelect, NSpin, NThing } from 'naive-ui';
  4. import { useRouter } from 'vue-router';
  5. import { BOOK_DATA } from '/src/views/natural-resources/model/add-teaching';
  6. import { classGroupPage, courseScheduleStart } from '../../api';
  7. import { useThrottleFn } from '@vueuse/core';
  8. import TheEmpty from '/src/components/TheEmpty';
  9. import { usePrepareStore } from '/src/store/modules/prepareLessons';
  10. const classList: any = [];
  11. for (let i = 1; i <= 40; i++) {
  12. classList.push({ label: i + '班', value: i });
  13. }
  14. export default defineComponent({
  15. name: 'attend-class',
  16. emits: ['close'],
  17. setup(props, { emit }) {
  18. const prepareStore = usePrepareStore();
  19. const router = useRouter();
  20. const forms = reactive({
  21. keyword: null,
  22. currentGradeNum: null,
  23. currentClass: null
  24. });
  25. const list = ref([] as any);
  26. const loading = ref(false);
  27. // 开始上课
  28. const onAttendClass = async (item: any) => {
  29. try {
  30. await courseScheduleStart({
  31. lessonCoursewareKnowledgeDetailId: prepareStore.selectKey,
  32. classGroupId: item.id
  33. });
  34. emit('close');
  35. const { href } = router.resolve({
  36. path: '/attend-class',
  37. query: {
  38. type: 'class',
  39. classGroupId: item.id,
  40. subjectId: prepareStore.getSubjectId,
  41. detailId: prepareStore.getSelectKey
  42. }
  43. });
  44. window.open(href, +new Date() + '');
  45. } catch {
  46. //
  47. }
  48. };
  49. const getList = async () => {
  50. loading.value = true;
  51. try {
  52. const { data } = await classGroupPage({
  53. page: 1,
  54. rows: 99,
  55. ...forms
  56. });
  57. const result = data.rows || [];
  58. result.forEach((item: any) => {
  59. // 判断班级里面有学生的
  60. if (item.preStudentNum > 0) {
  61. list.value.push(item);
  62. }
  63. });
  64. } catch {
  65. //
  66. }
  67. loading.value = false;
  68. };
  69. const throttleFn = useThrottleFn(() => getList(), 500);
  70. onMounted(() => {
  71. getList();
  72. });
  73. return () => (
  74. <div class={styles.attendClass}>
  75. <div class={styles.attendClassSearch}>
  76. <NInput
  77. placeholder="请输入班级名称"
  78. clearable
  79. v-model:value={forms.keyword}
  80. onKeyup={(e: KeyboardEvent) => {
  81. if (e.code === 'Enter') {
  82. throttleFn();
  83. }
  84. }}
  85. onClear={() => throttleFn()}>
  86. {{
  87. prefix: () => (
  88. <span
  89. class="icon-search-input"
  90. onClick={() => throttleFn()}></span>
  91. )
  92. }}
  93. </NInput>
  94. <NSelect
  95. placeholder="全部年级"
  96. clearable
  97. options={
  98. [{ label: '全部年级', value: null }, ...BOOK_DATA.grades] as any
  99. }
  100. v-model:value={forms.currentGradeNum}
  101. onUpdate:value={() => throttleFn()}
  102. />
  103. <NSelect
  104. placeholder="全部班级"
  105. clearable
  106. options={[{ label: '全部班级', value: null }, ...classList]}
  107. v-model:value={forms.currentClass}
  108. onUpdate:value={() => throttleFn()}
  109. />
  110. </div>
  111. <NScrollbar class={styles.classList}>
  112. <NSpin show={loading.value}>
  113. <div
  114. class={[
  115. styles.listSection,
  116. !loading.value && list.value.length <= 0
  117. ? styles.emptySection
  118. : ''
  119. ]}>
  120. {list.value.map((item: any) => (
  121. <div onClick={() => onAttendClass(item)}>
  122. <NThing class={styles.thingItem}>
  123. {{
  124. header: () => (
  125. <div class={styles.title}>
  126. {item.name} {item.preStudentNum}人
  127. </div>
  128. ),
  129. default: () =>
  130. item.lastStudy && (
  131. <div class={styles.content}>{item.lastStudy}</div>
  132. )
  133. }}
  134. </NThing>
  135. </div>
  136. ))}
  137. {!loading.value && list.value.length <= 0 && <TheEmpty />}
  138. </div>
  139. </NSpin>
  140. </NScrollbar>
  141. </div>
  142. );
  143. }
  144. });