index.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. classGroupId: item.id
  43. }
  44. });
  45. window.open(href, +new Date() + '');
  46. } catch {
  47. //
  48. }
  49. };
  50. const getList = async () => {
  51. loading.value = true;
  52. try {
  53. const { data } = await classGroupPage({
  54. page: 1,
  55. rows: 99,
  56. ...forms
  57. });
  58. list.value = data.rows || [];
  59. } catch {
  60. //
  61. }
  62. loading.value = false;
  63. };
  64. const throttleFn = useThrottleFn(() => getList(), 500);
  65. onMounted(() => {
  66. getList();
  67. });
  68. return () => (
  69. <div class={styles.attendClass}>
  70. <div class={styles.attendClassSearch}>
  71. <NInput
  72. placeholder="请输入班级名称"
  73. clearable
  74. v-model:value={forms.keyword}
  75. onKeyup={(e: KeyboardEvent) => {
  76. if (e.code === 'Enter') {
  77. throttleFn();
  78. }
  79. }}
  80. onClear={() => throttleFn()}>
  81. {{
  82. prefix: () => (
  83. <span
  84. class="icon-search-input"
  85. onClick={() => throttleFn()}></span>
  86. )
  87. }}
  88. </NInput>
  89. <NSelect
  90. placeholder="全部年级"
  91. clearable
  92. options={
  93. [{ label: '全部年级', value: null }, ...BOOK_DATA.grades] as any
  94. }
  95. v-model:value={forms.currentGradeNum}
  96. onUpdate:value={() => throttleFn()}
  97. />
  98. <NSelect
  99. placeholder="全部班级"
  100. clearable
  101. options={[{ label: '全部班级', value: null }, ...classList]}
  102. v-model:value={forms.currentClass}
  103. onUpdate:value={() => throttleFn()}
  104. />
  105. </div>
  106. <NScrollbar class={styles.classList}>
  107. <NSpin show={loading.value}>
  108. <div
  109. class={[
  110. styles.listSection,
  111. !loading.value && list.value.length <= 0
  112. ? styles.emptySection
  113. : ''
  114. ]}>
  115. {list.value.map((item: any) => (
  116. <div onClick={() => onAttendClass(item)}>
  117. <NThing class={styles.thingItem}>
  118. {{
  119. header: () => (
  120. <div class={styles.title}>
  121. {item.name} {item.preStudentNum}人
  122. </div>
  123. ),
  124. default: () =>
  125. item.lastStudy && (
  126. <div class={styles.content}>{item.lastStudy}</div>
  127. )
  128. }}
  129. </NThing>
  130. </div>
  131. ))}
  132. {!loading.value && list.value.length <= 0 && <TheEmpty />}
  133. </div>
  134. </NSpin>
  135. </NScrollbar>
  136. </div>
  137. );
  138. }
  139. });