import { defineComponent, onMounted, reactive, watch } from 'vue'; import styles from '../index.module.less'; import { NButton, NDataTable, NForm, NFormItem, NModal, NNumberAnimation, NSpace, NTooltip, useMessage } from 'naive-ui'; import SearchInput from '@/components/searchInput'; import CSelect from '@/components/CSelect'; import Pagination from '@/components/pagination'; import { api_studentStat, getStudentList } from '../api'; import { useRoute, useRouter } from 'vue-router'; import TheEmpty from '/src/components/TheEmpty'; import UpdateStudent from '../../studentList/modals/update-student'; import { initCache, setCache } from '/src/hooks/use-async'; import { modalClickMask } from '/src/state'; export default defineComponent({ name: 'student-studentList', props: { upgradeFlag: { type: Number } }, setup(props) { const message = useMessage(); const route = useRoute(); const router = useRouter(); const payForm = reactive({ vipStudentNum: 0, studentNum: 0 }); const state = reactive({ upgradeFlag: props.upgradeFlag == 0 ? true : false, // 是否为历史班 searchForm: { keyword: '', gender: '' as any, membership: '' as any }, loading: false, pagination: { page: 1, rows: 10, pageTotal: 4 }, tableList: [] as any, editStatus: false, activeRow: {} as any }); watch( () => props.upgradeFlag, () => { state.upgradeFlag = props.upgradeFlag == 0 ? true : false; } ); const search = () => { state.pagination.page = 1; getList(); setCache({ current: state.searchForm, saveKey: 'classDetailStudent' }); }; const onReset = () => { state.searchForm = { keyword: '', gender: '' as any, membership: '' as any }; search(); setCache({ current: state.searchForm, saveKey: 'classDetailStudent' }); }; const getList = async () => { state.loading = true; try { const res = await getStudentList({ classGroupId: route.query.id, ...state.searchForm, ...state.pagination }); state.tableList = res.data.rows; state.pagination.pageTotal = res.data.total; state.loading = false; } catch (e) { state.loading = false; console.log(e); } }; initCache({ current: state.searchForm, saveKey: 'classDetailStudent', callBack: (active: any) => { state.searchForm = active; } }); const getInfo = async () => { try { const { data } = await api_studentStat({ classGroupId: route.query.id as any // ...state.searchForm }); payForm.studentNum = data.studentNum || 0; payForm.vipStudentNum = data.vipStudentNum || 0; } catch (e) { console.log(e); } }; onMounted(() => { getInfo(); getList(); }); const copyTo = (text: string) => { const input = document.createElement('input'); input.value = text; document.body.appendChild(input); input.select(); input.setSelectionRange(0, input.value.length); document.execCommand('Copy'); document.body.removeChild(input); message.success('复制成功'); }; const gotoDetail = (row: any) => { router.push({ path: '/classStudentDetail', query: { ...route.query, studentId: row.id, studentName: row.nickname, upgradeFlag: state.upgradeFlag ? 0 : 1 } }); }; const columns = () => { return [ { title: '学生姓名', key: 'nickname', render: (row: any) => { return ( {{ trigger: () => (
copyTo(row.nickname)}> {row.nickname}
), default: '点击复制' }}
); } }, { title: '手机号', key: 'phone', render: (row: any) => { return ( {{ trigger: () => (
copyTo(row.phone)}> {row.phone}
), default: '点击复制' }}
); } }, { title: '性别', key: 'gender', render(row: any) { return ( <> {row.gender + '' != 'null' ? row.gender == '0' ? '女' : '男' : '--'} ); } }, { title: '学生类型', key: 'vipMember', render(row: any) { return <>{row.vipMember ? '会员' : '普通'}; } }, { title: '操作', key: 'id', render(row: any) { return ( gotoDetail(row)}> 详情 onUpdate(row)} disabled={row.historyClassStudent}> 修改 ); } } ]; }; // 修改 const onUpdate = (row: any) => { state.editStatus = true; state.activeRow = row; }; return () => (

班级人数

会员人数

(state.searchForm.keyword = val) }> 搜索 重置
}} class={styles.classTable} loading={state.loading} columns={columns()} data={state.tableList}>
(state.editStatus = false)} onConfirm={() => getList()} row={state.activeRow} />
); } });