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 (
班级人数
会员人数