import { defineComponent, onMounted, reactive, ref } from 'vue';
import styles from './index.module.less';
import {
NButton,
NDataTable,
NForm,
NFormItem,
NImage,
NModal,
NSelect,
NSpace,
NTooltip,
useMessage
} 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 { useRoute, useRouter } from 'vue-router';
import { getStudentList, schoolDetail } from './api';
import { classGroupList } from '@/views/classList/api';
import AddStudentModel from './modals/addStudentModel';
import Studentguide from '@/custom-plugins/guide-page/student-guide';
import TheEmpty from '/src/components/TheEmpty';
// import NoticeModal from './modals/noticeModal';
import { useUserStore } from '/src/store/modules/users';
import UpdateStudent from './modals/update-student';
import { initCache, setCache } from '/src/hooks/use-async';
import { classArray, getgradeNumList } from '../classList/contants';
import { getGradeLevelList, getGradeYearList } from '../home/api';
export default defineComponent({
name: 'student-studentList',
setup(props, { emit }) {
const userStore = useUserStore();
const state = reactive({
searchForm: {
keyword: '',
gender: '' as any,
classGroupId: '' as any,
membership: '' as any,
currentClass: '' as any,
currentGradeNum: '' as any,
gradeYear: '' as any,
gradeLevel: ''
},
gradeNumList: [] 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,
classList: [],
addStudentVisible: false,
editStatus: false,
activeRow: {} as any,
popSelectYearList: [] as any,
popSelectLevelList: [] as any
});
state.gradeNumList = getgradeNumList();
const route = useRoute();
const router = useRouter();
const showGuide = ref(false);
const message = useMessage();
const search = () => {
state.pagination.page = 1;
getList();
setCache({ current: state.searchForm, saveKey: route.path });
};
const getClasslist = async () => {
try {
const res = await classGroupList({ page: 1, rows: 999 });
state.classList = res.data.rows.map((item: any) => {
return {
label: item.name,
value: item.id
};
});
} catch (e) {
console.log(e);
}
};
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 onReset = () => {
state.searchForm = {
keyword: '',
gender: '' as any,
classGroupId: '' as any,
membership: '' as any,
currentClass: '' as any,
currentGradeNum: '' as any,
gradeYear: '' as any,
gradeLevel: ''
};
if (state.popSelectYearList.length > 0) {
state.searchForm.gradeYear = state.popSelectYearList[0].id;
}
search();
setCache({ current: state.searchForm, saveKey: route.path });
};
initCache({
current: state.searchForm,
callBack: (active: any) => {
state.searchForm = active;
}
});
const getList = async () => {
try {
const res = await getStudentList({
...state.searchForm,
...state.pagination
});
state.tableList = res.data.rows;
state.pagination.pageTotal = res.data.total;
if (state.tableList.length > 0) {
setTimeout(() => {
showGuide.value = true;
}, 500);
}
} catch (e) {
console.log(e);
}
console.log('getList');
};
// 获取学年
const getYearList = async () => {
try {
const { data } = await getGradeYearList();
const temp = data || [];
temp.forEach((i: any) => {
i.name = i.name + '学年';
});
// temp.unshift({
// id: '',
// name: '全部学年'
// });
state.popSelectYearList = temp || [];
if (temp.length > 0 && !state.searchForm.gradeYear) {
state.searchForm.gradeYear = temp[0].id;
}
} catch {
//
}
};
// 获取学级
const getLevelList = async () => {
try {
const { data } = await getGradeLevelList();
const temp = data || [];
temp.forEach((i: any) => {
i.name = i.name + '级';
});
temp.unshift({
id: '',
name: '全部学级'
});
state.popSelectLevelList = temp || [];
if (temp.length > 0 && !state.searchForm.gradeLevel) {
state.searchForm.gradeLevel = temp[0].id;
}
} catch {
//
}
};
onMounted(async () => {
state.loading = true;
await getYearList();
await getLevelList();
await getList();
await getClasslist();
state.loading = false;
});
const columns = () => {
return [
{
title: '学生姓名',
key: 'nickname',
render: (row: any) => {
return (