index.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import { defineComponent, onMounted, reactive, watch } from 'vue';
  2. import styles from './index.module.less';
  3. import { NInput, NScrollbar, NSelect, NSpin } from 'naive-ui';
  4. import { useThrottleFn } from '@vueuse/core';
  5. import CoursewareType from '../courseware-type';
  6. import TheEmpty from '/src/components/TheEmpty';
  7. import { api_queryOpenCoursewareByPage } from '../../api';
  8. export default defineComponent({
  9. name: 'related-class',
  10. props: {
  11. tableList: {
  12. type: Array,
  13. default: () => []
  14. },
  15. subjectList: {
  16. type: Array,
  17. default: () => []
  18. },
  19. subjectId: {
  20. type: [String, Number],
  21. default: ''
  22. },
  23. coursewareDetailKnowledgeId: {
  24. type: [String, Number],
  25. default: ''
  26. }
  27. },
  28. emits: ['close', 'add', 'click'],
  29. setup(props, { emit }) {
  30. const forms = reactive({
  31. loading: false,
  32. finshed: false, // 是否加载完
  33. pagination: {
  34. page: 1,
  35. rows: 20
  36. },
  37. tableList: [] as any,
  38. searchGroup: {
  39. subjectId: props.subjectId,
  40. keyword: null
  41. }
  42. });
  43. const getList = async () => {
  44. try {
  45. if (forms.pagination.page === 1) {
  46. forms.loading = true;
  47. }
  48. // 查询公开课件列表
  49. const { data } = await api_queryOpenCoursewareByPage({
  50. coursewareDetailKnowledgeId: props.coursewareDetailKnowledgeId,
  51. ...forms.searchGroup,
  52. ...forms.pagination
  53. });
  54. const result = data.rows || [];
  55. const tempList: any = [];
  56. result.forEach((item: any) => {
  57. // const index = forms.tableList.findIndex(
  58. // (i: any) => i.fromChapterLessonCoursewareId === item.id
  59. // );
  60. const firstItem: any =
  61. item.chapterKnowledgeList[0]?.chapterKnowledgeMaterialList[0];
  62. tempList.push({
  63. id: item.id,
  64. openFlag: item.openFlag,
  65. openFlagEnable: item.openFlagEnable,
  66. subjectNames: item.subjectNames,
  67. fromChapterLessonCoursewareId: item.fromChapterLessonCoursewareId,
  68. name: item.name,
  69. coverImg: firstItem?.bizInfo.coverImg,
  70. type: firstItem?.bizInfo.type,
  71. isAdd: item.addFlag,
  72. isNotWork: item.lessonPreTrainingNum <= 0 ? true : false // 是否布置作业
  73. });
  74. });
  75. forms.loading = false;
  76. forms.tableList.push(...tempList);
  77. forms.finshed = data.pages <= data.current ? true : false;
  78. } catch {
  79. forms.loading = false;
  80. }
  81. };
  82. // 检测数据是否存在
  83. // watch(
  84. // () => props.tableList,
  85. // () => {
  86. // // fromChapterLessonCoursewareId;
  87. // forms.tableList.forEach((item: any) => {
  88. // const index = props.tableList.findIndex(
  89. // (i: any) => i.fromChapterLessonCoursewareId === item.id
  90. // );
  91. // item.isAdd = index !== -1 ? true : false;
  92. // });
  93. // }
  94. // );
  95. const throttleFn = useThrottleFn(() => {
  96. forms.tableList = [];
  97. getList();
  98. }, 500);
  99. onMounted(() => {
  100. getList();
  101. });
  102. return () => (
  103. <div class={styles.relatedClass}>
  104. <div class={styles.attendClassSearch}>
  105. <NSelect
  106. placeholder="全部声部"
  107. clearable
  108. options={[
  109. { name: '全部声部', id: '' },
  110. ...(props.subjectList as any)
  111. ]}
  112. labelField="name"
  113. valueField="id"
  114. v-model:value={forms.searchGroup.subjectId}
  115. onUpdate:value={() => throttleFn()}
  116. />
  117. <NInput
  118. placeholder="请输入课件标题关键词"
  119. clearable
  120. v-model:value={forms.searchGroup.keyword}
  121. onKeyup={(e: KeyboardEvent) => {
  122. if (e.code === 'Enter') {
  123. throttleFn();
  124. }
  125. }}
  126. onClear={() => throttleFn()}>
  127. {{
  128. prefix: () => (
  129. <span
  130. class="icon-search-input"
  131. style={{ cursor: 'pointer' }}
  132. onClick={() => throttleFn()}></span>
  133. )
  134. }}
  135. </NInput>
  136. </div>
  137. <NScrollbar
  138. class={styles.classList}
  139. style={{
  140. 'max-height': `60vh`
  141. }}
  142. onScroll={(e: any) => {
  143. const clientHeight = e.target?.clientHeight;
  144. const scrollTop = e.target?.scrollTop;
  145. const scrollHeight = e.target?.scrollHeight;
  146. // 是否到底,是否加载完
  147. if (
  148. clientHeight + scrollTop + 20 >= scrollHeight &&
  149. !forms.finshed &&
  150. !forms.loading
  151. ) {
  152. throttleFn();
  153. }
  154. }}>
  155. <NSpin show={forms.loading} size={'small'}>
  156. <div
  157. style={{
  158. 'min-height': `60vh)`
  159. }}
  160. class={[
  161. styles.listSection,
  162. !forms.loading && forms.tableList.length <= 0
  163. ? styles.emptySection
  164. : ''
  165. ]}>
  166. {forms.tableList.length > 0 && (
  167. <div class={[styles.list]}>
  168. {forms.tableList.map((item: any) => (
  169. <div class={[styles.itemWrap, styles.itemBlock, 'row-nav']}>
  170. <div class={styles.itemWrapBox}>
  171. <CoursewareType
  172. isHoverShowAdd={false}
  173. isShowOpenFlag={false}
  174. isShowAdd
  175. item={item}
  176. onAdd={() => {
  177. emit('add', item);
  178. }}
  179. onLook={() => emit('click', item)}
  180. />
  181. </div>
  182. </div>
  183. ))}
  184. </div>
  185. )}
  186. {!forms.loading && forms.tableList.length <= 0 && <TheEmpty />}
  187. </div>
  188. </NSpin>
  189. </NScrollbar>
  190. </div>
  191. );
  192. }
  193. });