index.tsx 4.3 KB

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