import { defineComponent, reactive, onMounted, ref } from 'vue'; import styles from './index.module.less'; import { NButton, NDataTable, NForm, NFormItem, NImage, NModal, NSpace, useMessage } from 'naive-ui'; import SearchInput from '@/components/searchInput'; import CSelect from '@/components/CSelect'; import Pagination from '@/components/pagination'; import { classGroupList, deleteClass, getSubject, addGroup } from './api'; import CreateClass from './modals/createClass'; import RestStudentBox from './modals/restStudentBox'; import { getgradeNumList, classArray } from './contants'; import add from '@/views/studentList/images/add.png'; import ClassGuide from '@/custom-plugins/guide-page/class-guide'; import { useRoute, useRouter } from 'vue-router'; import TheEmpty from '/src/components/TheEmpty'; import TheTooltip from '/src/components/TheTooltip'; import PreviewWindow from '../preview-window'; import ResetSubject from './modals/resetSubject'; import UpdateSubject from './modals/updateSubject'; import { getGradeLevelList, getGradeYearList } from '../home/api'; import { initCache, setCache } from '/src/hooks/use-async'; export default defineComponent({ name: 'class-classList', setup() { const state = reactive({ searchForm: { keyword: null as any, currentClass: '', currentGradeNum: '', subjectId: '', gradeYear: '', gradeLevel: '' }, orchestraType: null, courseTypeCode: null, loading: false, pagination: { page: 1, rows: 10, pageTotal: 6 }, gradeNumList: [] as any, tableList: [] as any, studentVisible: false, activeRow: null as any, showaddClass: false, goCourseVisiable: false, removeVisiable: false, removeRow: {} as any, previewModal: false, previewParams: {} as any, lastCourse: null as any, groupBtnLoading: false, // 按钮是否在请求中 subjectList: [] as any, showResetClass: false, showSubjectClass: false, groupVisiable: false, popSelectYearList: [] as any, popSelectLevelList: [] as any }); const formRef = ref(); const message = useMessage(); const router = useRouter(); const route = useRoute(); const search = () => { state.pagination.page = 1; getList(); setCache({ current: state.searchForm, saveKey: route.path }); }; const showGuide = ref(false); state.gradeNumList = getgradeNumList(); const onReset = () => { state.searchForm = { keyword: null as any, currentClass: '' as any, currentGradeNum: '' as any, subjectId: '' as any, gradeYear: '' as any, gradeLevel: '' }; if (state.popSelectYearList.length > 0) { state.searchForm.gradeYear = state.popSelectYearList[1].id; } getList(); setCache({ current: state.searchForm, saveKey: route.path }); }; const removeClass = async () => { try { await deleteClass({ ids: state.removeRow.id }); getList(); message.success(`删除成功`); state.removeVisiable = false; } catch (e) { console.log(e); } }; const getList = async () => { // classGroupList state.loading = true; try { const res = await classGroupList({ ...state.searchForm, ...state.pagination }); state.tableList = res.data.rows; state.pagination.pageTotal = res.data.total; state.loading = false; setTimeout(() => { if (state.tableList.length > 0) { showGuide.value = true; } }, 500); } catch (e) { state.loading = false; console.log(e); } console.log('getList'); }; const getSubjectList = async () => { const res = await getSubject({ page: 1, rows: 9999 }); state.subjectList = res.data.rows.map((item: any) => { return { value: item.id, label: item.name }; }); state.subjectList.unshift({ value: '', label: '全部声部' }); }; const columns = () => { return [ { title: '班级名称', key: 'name' }, { title: '学年', key: 'gradeYear' }, { title: '学级', key: 'gradeLevel', render(row: any) { return row.gradeLevel ? `${row.gradeLevel}级` : ''; } }, { title: '班级声部', key: 'subjectName' }, { title: '学生人数', key: 'preStudentNum' }, { title: '上次学习', key: 'lastStudy', width: '20%', render(row: any) { return row.lastStudy ? ( ) : ( '--' ); } }, { title: '操作', key: 'id', render(row: any, index: number) { return (
{index == 0 ? (
{ router.push({ path: '/classDetail', query: { name: row.name, id: row.id, gradeYear: row.gradeYear, upgradeFlag: row.upgradeFlag ? 1 : 0 // 是否为历史班 } }); }}> 详情
) : ( { router.push({ path: '/classDetail', query: { name: row.name, id: row.id, gradeYear: row.gradeYear, upgradeFlag: row.upgradeFlag ? 1 : 0 // 是否为历史班 } }); }}> 详情 )} resetClassSubject(row)}> 修改声部 {index == 0 ? ( { startResetStudent(row); }}> 学生调整 ) : ( { startResetStudent(row); }}> 学生调整 )} {index == 0 ? ( classesBegin(row)}> 开始上课 ) : ( classesBegin(row)}> 开始上课 )} {!(row.preStudentNum > 0) ? ( { state.removeVisiable = true; state.removeRow = row; }}> 删除 ) : //

{ // state.removeVisiable = true; // state.removeRow = row; // }}> // 删除 //

null} {row.imGroupId ? null : ( { createImgroup(row); }}> 创建群聊 )}
); } } ]; }; const startResetStudent = (row: any) => { state.activeRow = row; state.studentVisible = true; }; const classesBegin = async (row: any) => { try { // 判断是否有声部 if (row.subjectId) { // // 声部先取上次上课的声部,如果没有则取班级上面的声部 router.push({ path: '/prepare-lessons', query: { lastUseCoursewareId: row.lessonCoursewareId, unit: row.lessonCoursewareKnowledgeDetailId, subjectId: row.subjectId, courseScheduleSubjectId: row.courseScheduleSubjectId, preStudentNum: row.preStudentNum, name: row.name, // 班级名称 classGroupId: row.id // 班级编号 } }); } else { state.showSubjectClass = true; state.activeRow = row; } } catch (e) { console.log(e); } }; const resetClassSubject = (row: any) => { state.activeRow = row; state.showResetClass = true; }; const createImgroup = async (row: any) => { state.activeRow = row; state.groupVisiable = true; }; const submitGroup = async () => { console.log(state.activeRow, 'row'); state.groupBtnLoading = true; try { await addGroup({ classGroupId: state.activeRow.id }); message.success('创建成功'); state.groupVisiable = false; await getList(); } catch (e) { console.log(e); } state.groupBtnLoading = false; }; // 获取学年 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[1].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 { // } }; initCache({ current: state.searchForm, callBack: (active: any) => { state.searchForm = active; } }); onMounted(async () => { state.loading = true; getSubjectList(); await getYearList(); await getLevelList(); await getList(); state.loading = false; }); return () => (
(state.searchForm.keyword = val) }> 搜索 重置
(state.showaddClass = true)} v-slots={{ icon: () => ( <> ) }}> 创建班级
}} class={styles.classTable} loading={state.loading} columns={columns()} data={state.tableList}>
(state.studentVisible = false)} onGetList={() => getList()}> getList()} onClose={() => (state.showaddClass = false)} /> getList()} onClose={() => (state.showResetClass = false)} /> {state.showSubjectClass ? ( getList()} onConfirm={(item: any) => { // router.push({ path: '/prepare-lessons', query: { ...item } }); }} onClose={() => (state.showSubjectClass = false)} /> ) : null} {/* 上课弹窗 */}

确定要删除班级么? 删除班级信息将会清空

确定 (state.removeVisiable = false)}> 取消

是否创建班级群聊

确定 (state.groupVisiable = false)}> 取消
{showGuide.value ? : null}
); } });