import { PropType, computed, defineComponent, onMounted, toRefs, watch } from 'vue'; import styles from '../index.module.less'; import icons from '../icons.json'; import { Badge, Image } from 'vant'; import { ISubjectGradeDistribution } from '../type'; const colors = [ '#21B3D7', '#DF8010', '#17BDA6', '#21B3D7', '#DF8010', '#17BDA6', '#21B3D7', '#DF8010', '#17BDA6', '#21B3D7', '#DF8010', '#17BDA6', '#21B3D7', '#DF8010', '#17BDA6', ]; export default defineComponent({ name: 'DetailData', props: { data: { type: Array as PropType, default: () => [] } }, setup(props) { const { data } = toRefs(props); /** 声部列表 */ const subjects = computed(() => { let list = data.value.reduce((list: any[], item) => { const _itemIndex = list.findIndex( _item => _item.subjectName === item.subjectName ); if (_itemIndex > -1) { const listItem = list[_itemIndex]; listItem[item.grade] = item.studentNum; } else { list.push({ subjectName: item.subjectName, [item.grade]: item.studentNum }); } return list; }, []); if (!list.length) { list = ['长笛', '单簧管', '萨克斯', '小号', '圆号', '长号', '上低音号'].map((n, i) => { return { subjectName: n, '总人数': 0, '一年级': 0, '二年级': 0, '三年级': 0, '四年级': 0, '五年级': 0, '六年级': 0, }; }) } return list; }); /** 年级列表 */ const gradeList = computed(() => { let index = -1; let _list = Array.from(new Set(data.value.map(item => item.grade))) .filter(item => item !== '总人数') .map(item => { if (index >= colors.length - 1) index = 0; else ++index; return { name: item, color: colors[index] }; }); if (!_list.length) { _list = ['一', '二', '三', '四', '五', '六'].map((n, i) => { if (index >= colors.length - 1) index = 0; else ++index; return { name: n + '年级', color: colors[index] }; }); } return _list; }); return () => (
详细数据
(单位:人)
声部
{subjects.value.map(item => (
{item.subjectName}
))}
总人数
{subjects.value.map(item => (
{item['总人数']}
))}
e.stopPropagation()} onMousemove={(e: Event) => e.stopPropagation()}> {gradeList.value.map(item => (
{item.name}
{subjects.value.map((_n, _index) => (
{_n[item.name] || 0}
))}
))}
); } });