import { defineComponent, onMounted, reactive, ref } from 'vue'; import styles from './index.module.less'; import { NButton, NCheckbox, NCheckboxGroup, // NBreadcrumb, // NBreadcrumbItem, // NScrollbar, NSlider, NSpace, NSpin } from 'naive-ui'; import iconT from '/src/views/content-information/images/icon-t.png'; import iconAddT from '/src/views/content-information/images/icon-add-t.png'; import iconPlusT from '/src/views/content-information/images/icon-plus-t.png'; import { api_lessonCoursewareDetail_listKnowledge, api_lessonCoursewareKnowledgeDetail } from '/src/views/content-information/api'; import TheEmpty from '/src/components/TheEmpty'; import { PageEnum } from '/src/enums/pageEnum'; export default defineComponent({ name: 'cotnent-knowledge', emits: ['close', 'confirm'], setup(props, { emit }) { const show = ref(false); const content = ref(false); const musicContentRef = ref(); const state = reactive({ fontSize: 18, tableList: [] as any, selectKey: null, details: {} as any, selectCheckboxs: [] as any }); const getDetails = async () => { show.value = true; content.value = true; try { const { data } = await api_lessonCoursewareDetail_listKnowledge({ type: 'COURSEWARE' }); state.tableList = data || []; if (state.tableList.length > 0) { const item = state.tableList[0].lessonCoursewareDetailKnowledgeDetailList; state.tableList[0].selected = true; if (item && item.length) { const child = item[0]; state.selectKey = child.id; await getDetail(); } state.tableList.forEach((item: any) => { item.checked = false; item.indeterminate = false; }); } } catch { // } content.value = false; show.value = false; }; const getDetail = async () => { content.value = true; try { const { data } = await api_lessonCoursewareKnowledgeDetail({ id: state.selectKey }); state.details = data; } catch { // } content.value = false; }; const onSubmit = () => { const items: any[] = []; for (const i in state.selectCheckboxs) { const ids = state.selectCheckboxs[i]; const item = state.tableList[i]; if (Array.isArray(item.lessonCoursewareDetailKnowledgeDetailList)) { item.lessonCoursewareDetailKnowledgeDetailList.forEach( (child: any) => { if (ids.includes(child.id)) { items.push(child); } } ); } } const result: any[] = []; items.forEach(item => { result.push({ coverImg: PageEnum.THEORY_DEFAULT_COVER, title: item.name, materialId: item.id, content: item.id }); }); emit('confirm', result); }; onMounted(() => { getDetails(); }); return () => (
{state.tableList.map((item: any, index: number) => (
{ state.tableList.forEach((child: any) => { if (item.id !== child.id) { child.selected = false; } }); item.selected = item.selected ? false : true; }}> {item.lessonCoursewareDetailKnowledgeDetailList && item.lessonCoursewareDetailKnowledgeDetailList .length > 0 && ( )}

{item.name}

{ e.stopPropagation(); }}> { item.checked = val; const child = item.lessonCoursewareDetailKnowledgeDetailList || []; if (val) { const ids: any = []; child.forEach((c: any) => { ids.push(c.id); }); state.selectCheckboxs[index] = ids; } else { state.selectCheckboxs[index] = []; } item.indeterminate = false; }}>
{ state.selectCheckboxs[index] = val; const child = item.lessonCoursewareDetailKnowledgeDetailList || []; if (val.length <= 0) { item.checked = false; item.indeterminate = false; } else if (val.length === child.length) { item.checked = true; item.indeterminate = false; } else { item.checked = false; item.indeterminate = true; } }}> {item.selected && item.lessonCoursewareDetailKnowledgeDetailList && item.lessonCoursewareDetailKnowledgeDetailList.map( (child: any, j: number) => (
{ if (state.selectKey === child.id) return; state.selectKey = child.id; getDetail(); musicContentRef.value.$el.scrollTo(0, 0); }}>

{child.name}

e.stopPropagation()}>
) )}
))}
{!show.value && state.tableList.length <= 0 && ( )}
{state.details?.desc ? (
) : ( '' )} {!content.value && !state.details?.desc && }
{ if (state.fontSize >= 32) return; state.fontSize += 1; }} /> { if (state.fontSize <= 12) return; state.fontSize -= 1; }} />
emit('close')}> 取消 确认添加
); } });