import { defineComponent, nextTick, onMounted, reactive, ref } from 'vue'; import styles from '../index.module.less'; import { NButton, NDataTable, NForm, NFormItem, NGi, NGrid, NImage, NModal, NNumberAnimation, NSelect, NSpace, NTooltip } from 'naive-ui'; import SearchInput from '@/components/searchInput'; import CSelect from '@/components/CSelect'; import Pagination from '@/components/pagination'; import add from './images/add.png'; import { getNowDateAndMonday, getNowDateAndSunday, getTimes, getMinutes, getSecend, formateSeconds, getHours, getLastMinutes } from '/src/utils/dateFormat'; import { getTestList, getTrainingStat } from '../api'; import CDatePicker from '/src/components/CDatePicker'; import { useRoute, useRouter } from 'vue-router'; import TheEmpty from '/src/components/TheEmpty'; import { initCache, setCache } from '/src/hooks/use-async'; import iconSortDefault from '@/common/images/icon-sort-default.png'; import iconSortDesc from '@/common/images/icon-sort-desc.png'; import iconSortAsc from '@/common/images/icon-sort-asc.png'; export default defineComponent({ name: 'student-studentList', setup(props, { emit }) { const state = reactive({ searchForm: { ase: 0, sortType: 1, keyword: '', trainingStatus: null as any, vipFlag: '' as any }, searchWord: '', orchestraType: null, courseTypeCode: null, subjectId: null, classId: null, studentType: null, loading: false, pagination: { page: 1, rows: 10, pageTotal: 4 }, tableList: [] as any, memberNumber: 0, testInfo: { practiceDurationAvg: 0, vipUserCount: 0, practiceUserCount: 0 }, activeRow: null }); const route = useRoute(); const router = useRouter(); const search = () => { state.pagination.page = 1; getInfo(); getList(); setCache({ current: { ...state.searchForm, timer: timer.value }, saveKey: 'classDetailTestRecord' }); }; const timer = ref<[number, number]>([ getNowDateAndMonday(new Date().getTime()), getNowDateAndSunday(new Date().getTime()) ]); const onReset = () => { timer.value = [ getNowDateAndMonday(new Date().getTime()), getNowDateAndSunday(new Date().getTime()) ]; state.searchForm = { ase: 0, sortType: 1, keyword: '', trainingStatus: null as any, vipFlag: '' }; search(); setCache({ current: { ...state.searchForm, timer: timer.value }, saveKey: 'classDetailTestRecord' }); }; initCache({ current: { ...state.searchForm, timer: timer.value }, saveKey: 'classDetailTestRecord', callBack: (active: any) => { state.searchForm = active; timer.value = active.timer; } }); const getList = async () => { state.loading = true; try { const res = await getTestList({ classGroupId: route.query.id, ...state.searchForm, ...state.pagination, ...getTimes(timer.value, ['startTime', 'endTime'], 'YYYY-MM-DD') }); state.tableList = res.data.rows; state.pagination.pageTotal = res.data.total; state.loading = false; } catch (e) { state.loading = false; console.log(e); } }; const getInfo = async () => { try { const res = await getTrainingStat({ classGroupId: route.query.id, ...getTimes(timer.value, ['startTime', 'endTime'], 'YYYY-MM-DD') }); state.testInfo.practiceDurationAvg = res.data.practiceDurationAvg; state.testInfo.practiceUserCount = res.data.practiceUserCount; state.testInfo.vipUserCount = res.data.vipUserCount; } catch (e) { console.log(e); } }; onMounted(() => { getInfo(); getList(); // nextTick(() => { // // 把默认的排序删除 // const dom = document.querySelectorAll('.n-data-table-sorter'); // dom.forEach((item: any) => { // item.style.display = 'none'; // }); // }); }); const gotoStudentDetail = (row: any) => { router.push({ path: '/classStudentRecode', query: { ...route.query, studentId: row.studentId, studentName: row.studentName } }); }; const practiceDaysRef = reactive({ title() { return ( {{ trigger: () => (
练习天数
), default: practiceDaysRef.sortOrder === 'descend' ? '点击升序' : practiceDaysRef.sortOrder === 'ascend' ? '取消排序' : '点击降序' }}
); }, key: 'practiceDays', sorter: true, sortOrder: false as any, render(row: any) { return <>{row.practiceDays ? row.practiceDays : 0}天; } }); const practiceDurationRef = reactive({ title() { return ( {{ trigger: () => (
学练时长
), default: practiceDurationRef.sortOrder === 'descend' ? '点击升序' : practiceDurationRef.sortOrder === 'ascend' ? '取消排序' : '点击降序' }}
); }, key: 'practiceDuration', sorter: true, sortOrder: false as any, render(row: any) { return ( <> {row.practiceDuration ? formateSeconds(row.practiceDuration, 1) : 0 + '秒'} ); } }); const columns = () => { return [ { title: '学生姓名', key: 'studentName' }, { title: '手机号', key: 'studentPhone' }, { title: '性别', key: 'sex', render(row: any) { return ( <> {row.gender + '' != 'null' ? row.gender == '0' ? '女' : '男' : '--'} ); } }, { title: '学生类型', key: 'studentType', render(row: any) { return <>{row.vipFlag ? '会员' : '普通'}; } }, practiceDaysRef, practiceDurationRef, // { // title: '练习天数', // key: 'practiceDays', // render(row: any) { // return <>{row.practiceDays ? row.practiceDays : 0}天; // } // }, // { // title: '学练时长', // key: 'studentType', // render(row: any) { // return ( // <> // {row.practiceDuration // ? getMinutes(row.practiceDuration) > 0 // ? getMinutes(row.practiceDuration) + // '分' + // getSecend(row.practiceDuration) + // '秒' // : getSecend(row.practiceDuration) + '秒' // : 0 + '秒'} // // ); // } // }, { title: '操作', key: 'id', render(row: any) { return ( { gotoStudentDetail(row); }}> 详情 ); } } ]; }; const handleSorterChange = (sroter: any) => { if (!sroter) { state.searchForm.ase = 0; state.searchForm.sortType = 1; practiceDaysRef.sortOrder = false; practiceDurationRef.sortOrder = false; } else { const list = { practiceDuration: 1, practiceDays: 2 }; state.searchForm.sortType = list[sroter.columnKey as 'practiceDuration' | 'practiceDays']; if (sroter.columnKey == 'practiceDuration') { practiceDurationRef.sortOrder = sroter.order; practiceDaysRef.sortOrder = false; } if (sroter.columnKey == 'practiceDays') { practiceDaysRef.sortOrder = sroter.order; practiceDurationRef.sortOrder = false; } state.searchForm.ase = sroter.order == 'ascend' ? 1 : 0; } getList(); }; return () => (
(state.searchForm.keyword = val) }> 搜索 重置

{' '} 人

练习人数

{' '} 人

会员人数

{getHours(state.testInfo.practiceDurationAvg) > 0 ? (

) : null} {getHours(state.testInfo.practiceDurationAvg) > 0 || getLastMinutes(state.testInfo.practiceDurationAvg) > 0 ? (
{' '} 分
) : null}
{' '} 秒

平均每天练习时长

}} class={styles.classTable} loading={state.loading} columns={columns()} data={state.tableList} onUpdate:sorter={handleSorterChange}>
); } });