123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 |
- 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 (
- <NTooltip showArrow={false} placement="top-start">
- {{
- trigger: () => (
- <div class={styles.cell}>
- 练习天数
- <img
- class={styles.sortIcon}
- src={
- practiceDaysRef.sortOrder === 'descend'
- ? iconSortDesc
- : practiceDaysRef.sortOrder === 'ascend'
- ? iconSortAsc
- : iconSortDefault
- }
- />
- </div>
- ),
- default:
- practiceDaysRef.sortOrder === 'descend'
- ? '点击升序'
- : practiceDaysRef.sortOrder === 'ascend'
- ? '取消排序'
- : '点击降序'
- }}
- </NTooltip>
- );
- },
- key: 'practiceDays',
- sorter: true,
- sortOrder: false as any,
- render(row: any) {
- return <>{row.practiceDays ? row.practiceDays : 0}天</>;
- }
- });
- const practiceDurationRef = reactive({
- title() {
- return (
- <NTooltip showArrow={false} placement="top-start">
- {{
- trigger: () => (
- <div class={styles.cell}>
- 学练时长
- <img
- class={styles.sortIcon}
- src={
- practiceDurationRef.sortOrder === 'descend'
- ? iconSortDesc
- : practiceDurationRef.sortOrder === 'ascend'
- ? iconSortAsc
- : iconSortDefault
- }
- />
- </div>
- ),
- default:
- practiceDurationRef.sortOrder === 'descend'
- ? '点击升序'
- : practiceDurationRef.sortOrder === 'ascend'
- ? '取消排序'
- : '点击降序'
- }}
- </NTooltip>
- );
- },
- 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 (
- <NButton
- text
- type="primary"
- onClick={() => {
- gotoStudentDetail(row);
- }}>
- 详情
- </NButton>
- );
- }
- }
- ];
- };
- 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 () => (
- <div>
- <div class={styles.searchList}>
- <NForm label-placement="left" inline>
- <NFormItem>
- <SearchInput
- {...{ placeholder: '请输入学生姓名' }}
- class={styles.searchInput}
- searchWord={state.searchForm.keyword}
- onChangeValue={(val: string) =>
- (state.searchForm.keyword = val)
- }></SearchInput>
- </NFormItem>
- <NFormItem>
- <CSelect
- {...({
- options: [
- {
- label: '全部类型',
- value: ''
- },
- {
- label: '会员',
- value: true
- },
- {
- label: '普通',
- value: false
- }
- ],
- placeholder: '学生类型',
- clearable: true,
- inline: true
- } as any)}
- v-model:value={state.searchForm.vipFlag}></CSelect>
- </NFormItem>
- <NFormItem>
- <CDatePicker
- v-model:value={timer.value}
- separator={'至'}
- type="daterange"
- timerValue={timer.value}></CDatePicker>
- </NFormItem>
- <NFormItem>
- <NSpace justify="end">
- <NButton type="primary" class="searchBtn" onClick={search}>
- 搜索
- </NButton>
- <NButton
- type="primary"
- ghost
- class="resetBtn"
- onClick={onReset}>
- 重置
- </NButton>
- </NSpace>
- </NFormItem>
- </NForm>
- </div>
- <div class={['section-container']}>
- <NGrid x-gap="12" cols={8}>
- <NGi>
- <div class={styles.TrainDataItem}>
- <div>
- <p class={styles.TrainDataItemTitle}>
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={
- state.testInfo.practiceUserCount
- }></NNumberAnimation>
- </span>{' '}
- 人
- </div>
- </p>
- </div>
- <p class={styles.TrainDataItemsubTitle}>练习人数</p>
- </div>
- </NGi>
- <NGi>
- <div class={styles.TrainDataItem}>
- <p class={styles.TrainDataItemTitle}>
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={state.testInfo.vipUserCount}></NNumberAnimation>
- </span>{' '}
- 人
- </div>
- </p>
- <p class={styles.TrainDataItemsubTitle}>会员人数</p>
- </div>
- </NGi>
- <NGi>
- <div class={styles.TrainDataItem}>
- <p class={styles.TrainDataItemTitle}>
- {getHours(state.testInfo.practiceDurationAvg) > 0 ? (
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={getHours(
- state.testInfo.practiceDurationAvg
- )}></NNumberAnimation>
- </span>
- <i style={{ width: '4px', display: 'inline-block' }}></i>
- 时
- <i style={{ width: '4px', display: 'inline-block' }}></i>
- </div>
- ) : null}
- {getHours(state.testInfo.practiceDurationAvg) > 0 || getLastMinutes(state.testInfo.practiceDurationAvg) > 0 ? (
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={getLastMinutes(
- state.testInfo.practiceDurationAvg
- )}></NNumberAnimation>
- </span>{' '}
- 分
- </div>
- ) : null}
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={getSecend(
- state.testInfo.practiceDurationAvg
- )}></NNumberAnimation>
- </span>{' '}
- 秒
- </div>
- </p>
- <p class={styles.TrainDataItemsubTitle}>平均每天练习时长</p>
- </div>
- </NGi>
- </NGrid>
- </div>
- <div class={[styles.tableWrap, styles.noSort]}>
- <NDataTable
- v-slots={{
- empty: () => <TheEmpty></TheEmpty>
- }}
- class={styles.classTable}
- loading={state.loading}
- columns={columns()}
- data={state.tableList}
- onUpdate:sorter={handleSorterChange}></NDataTable>
- <Pagination
- v-model:page={state.pagination.page}
- v-model:pageSize={state.pagination.rows}
- v-model:pageTotal={state.pagination.pageTotal}
- onList={getList}
- sync
- />
- </div>
- </div>
- );
- }
- });
|