import { PropType, defineComponent, nextTick, onMounted, reactive, ref, toRef } from 'vue'; import styles from './index.module.less'; import { NButton, NForm, NFormItem, NImage, NPopselect, NSpace } from 'naive-ui'; import { resourceTypeArray } from '/src/utils/searchArray'; import { useCatchStore } from '/src/store/modules/catchData'; import { useThrottleFn } from '@vueuse/core'; import TheSearch from '/src/components/TheSearch'; import isCollaose from '/src/views/natural-resources/images/isCollaose.png'; export default defineComponent({ name: 'resource-search-group', props: { type: { type: String as PropType< 'relateResources' | 'shareResources' | 'myResources' | 'myCollect' >, default: 'shareResources' }, subjectId: { type: String, default: '' } }, emits: ['search'], setup(props, { emit }) { const subjectId = toRef(props.subjectId); const catchStore = useCatchStore(); const forms = reactive({ type: 'MUSIC', // name: '', subjectId: subjectId.value as any, bookVersionId: null }); const resourceType = ref([] as any); const onSearch = () => { emit('search', forms); }; const throttleFn = useThrottleFn(() => onSearch(), 500); // const collapseWrapRef = ref(); // const divDomList = ref([] as any); // const orginHeight = ref(0); // const hiddenHeight = ref(0); // const line = ref(0); // const isCollapse = ref(false); // const loadingCollapse = ref(false); // 是否加载完成 // const musicCateRef = (el: any) => { // if (el?.selfElRef) { // divDomList.value.push(el.selfElRef.parentNode); // } // }; // const setCollapse = (flag: boolean) => { // isCollapse.value = flag; // getLive(); // }; // const getLive = () => { // try { // divDomList.value = [...new Set(divDomList.value)]; // let offsetLeft = -1; // divDomList.value.forEach((item: any, index: number) => { // if (index === 0) { // line.value = 1; // offsetLeft = item.offsetLeft; // } else if (item.offsetLeft === offsetLeft && index != 0) { // // 如果某个标签的offsetLeft和第一个标签的offsetLeft相等 说明增加了一行 // line.value++; // } // if (!isCollapse.value) { // if (line.value > 1) { // //从第3行开始 隐藏标签 // item.style.display = 'none'; // // 显示展开按钮 class名chu是在前面动态添加的 // } else { // item.style.display = 'block'; // } // } else { // item.style.display = 'block'; // } // }); // loadingCollapse.value = true; // } catch { // // // } // }; const selectChildObj = (item: any) => { const obj: any = {}; item?.forEach((child: any) => { if (child.id === forms.subjectId) { obj.selected = true; obj.name = child.name; } }); return obj; }; onMounted(async () => { // if (props.type === 'myCollect') { // resourceType.value.push({ // label: '全部', // value: '' // }); // forms.type = ''; // 默认全部 // } resourceTypeArray.forEach((item: any) => { // if (props.type === 'myResources') { // item.value !== 'MUSIC' && resourceType.value.push(item); // } else { resourceType.value.push(item); // } }); // 获取教材分类列表 await catchStore.getMusicSheetCategory(); // 获取声部 await catchStore.getSubjects(); catchStore.getSubjectInstruments.forEach((item: any) => { if (item.id == props.subjectId) { if (item.instruments.length > 0) { forms.subjectId = item.instruments[0].value; } else { forms.subjectId = item.value; } } }); // 这里开始 // musicCateRef // if (forms.type === 'MUSIC') { // orginHeight.value = collapseWrapRef.value?.offsetHeight; // hiddenHeight.value = collapseWrapRef.value?.offsetHeight / line.value; // // 默认隐藏 // getLive(); // } }); return () => (