import { NScrollbar, NSpin, NTabPane, NTabs } from 'naive-ui'; import { defineComponent, onMounted, reactive } from 'vue'; import styles from './index.module.less'; import CardType from '@/components/card-type'; import SearchGroup from './search-group'; import TheEmpty from '/src/components/TheEmpty'; import { useThrottleFn } from '@vueuse/core'; import { usePrepareStore } from '/src/store/modules/prepareLessons'; import { musicSheetPage } from '../../api'; export default defineComponent({ name: 'select-music', emits: ['select', 'add'], setup(props, { emit }) { const prepareStore = usePrepareStore(); const state = reactive({ loading: false, finshed: false, // 是否加载完 pagination: { page: 1, rows: 20 }, searchGroup: { keyword: '', musicSheetCategoriesId: '', status: 1, versionFlag: false, subjectId: null }, tableList: [] as any }); const getList = async () => { try { if (state.pagination.page === 1) { state.loading = true; } const { data } = await musicSheetPage({ ...state.searchGroup, ...state.pagination, subjectId: prepareStore.getSubjectId }); state.loading = false; const tempRows = data.rows || []; const temp: any = []; tempRows.forEach((row: any) => { temp.push({ id: row.id, coverImg: row.titleImg, type: 'MUSIC', title: row.musicSheetName, isCollect: false, isSelected: true, content: row.id, xmlFileUrl: row.xmlFileUrl }); }); state.tableList.push(...temp); state.finshed = data.pages <= data.current ? true : false; } catch { state.loading = false; } }; const onSearch = async (item: any) => { state.pagination.page = 1; state.tableList = []; state.searchGroup = Object.assign(state.searchGroup, item); getList(); }; const throttledFn = useThrottleFn(() => { state.pagination.page = state.pagination.page + 1; getList(); }, 500); onMounted(() => { getList(); }); return () => (