import React,{ Component } from "react";
import { Input,Checkbox,Table, Pagination, Modal,Menu ,Spin, Tooltip , Divider, Popconfirm } from "antd";
import ClipboardJS from 'clipboard'
import '../css/Courses.css'
import '../css/members.css'
import CourseLayoutcomponent from '../common/CourseLayoutComponent'
import Titlesearchsection from '../common/titleSearch/TitleSearchSection'
import ColorCountText from '../common/titleSearch/ColorCountText'
import { WordsBtn, trigger, on, off, getRandomcode, getRandomNumber , sortDirections } from 'educoder'
import Modals from "../../modals/Modals";
import axios from 'axios'
import _ from 'lodash'
import NoneData from "../coursesPublic/NoneData"
import DownloadMessageysl from "../../modals/DownloadMessageysl";
import CreateGroupByImportModal from './modal/CreateGroupByImportModal'
import ChangeRolePop from './ChangeRolePop'
import "./studentsList.css"
const Search =Input.Search;
const TYPE_STUDENTS = 1
const TYPE_COURSE_GOURP_PARENT = 2
const TYPE_COURSE_GOURP_CHILD = 3
const buildColumns = (that,isParent) => {
const { course_groups , sortedInfo } = that.state
let showSorter = isParent==true
const courseId = that.props.match.params.coursesId
const columns=[{
title: '序号',
dataIndex: 'id',
key: 'id',
align:'center',
width:"8%",
className:"color-grey-6",
render: (id, student, index) => {
return (that.state.page - 1) * 20 + index + 1
}
},
// {
// title: '用户id',
// dataIndex: 'login',
// key: 'login',
// align:'center',
// width:"10%",
// className:"color-grey-6",
// render: (login, record) => {
// return 10 ? login : ''}
// >{login}
// }
// },
{
title: '姓名',
dataIndex: 'name',
key: 'name',
align:'center',
width:"10%",
className:"color-grey-6",
render: (name, record) => {
return {name}
}
}, {
title: '学号',
dataIndex: 'student_id',
key: 'student_id',
align:'center',
width:"10%",
className:"color-grey-6",
sorter: true,
sortDirections: sortDirections,
sortOrder: sortedInfo.columnKey === 'student_id' && sortedInfo.order,
render: (student_id, record) => {
return 10 ? student_id : ''}
style={{maxWidth: '160px'}} >{student_id}
}
}
, {
title: '手机号',
dataIndex: 'user_phone',
key: 'user_phone',
align:'center',
width:"10%",
className:"color-grey-6",
// sorter: true,
// sortDirections: sortDirections,
// sortOrder: sortedInfo.columnKey === 'user_phone' && sortedInfo.order,
render: (user_phone, record) => {
return 10 ? user_phone : ''}
style={{maxWidth: '160px'}} >{user_phone}
}
}
, {
title: '邮箱',
dataIndex: 'user_mail',
key: 'user_mail',
align:'center',
width:"10%",
className:"color-grey-6",
// sorter: true,
// sortDirections: sortDirections,
// sortOrder: sortedInfo.columnKey === 'user_mail' && sortedInfo.order,
render: (user_mail, record) => {
return 10 ? user_mail : ''}
style={{maxWidth: '160px'}} >{user_mail}
}
}
];
if (that.hasGroupModule()) {
that.isStudentPage && columns.push({
title: '分班',
dataIndex: 'course_group_name',
key: 'course_group_name',
align:'center',
width:"25%",
className:"color-grey-6",
sorter:showSorter,
sortDirections: sortDirections,
sortOrder: sortedInfo.columnKey === 'course_group_name' && sortedInfo.order,
})
}
const isAdminOrStudent = that.props.isAdminOrStudent()
if (!isAdminOrStudent) {
columns.some((item,key)=> {
if (item.title === "学号") {
columns.splice(key, 1)
return true
}
})
}
const isAdmin = that.props.isAdmin()
if (isAdmin) {
!that.isStudentPage && columns.unshift({
title: '',
dataIndex: 'check',
key: 'check',
render: (text, item) => {
return
},
width:"5%"
})
columns.push({
title: '操作',
key: 'action',
width: '22%',
align:'center',
render: (text, record) => {
return (
that.onDelete(record)} style={'grey'}>删除学生
{record.member_roles && record.member_roles.length && }
)
},
})
}
return columns;
}
// 1-按照学生学号 2-按照分班名称,
const ORDER_BY_NUM = 1;
const ORDER_BY_GROUP = 2;
class studentsList extends Component{
constructor(props){
super(props);
this.state={
page:1,
order: ORDER_BY_NUM,
searchValue: '',
course_groups: [],
students: [],
checkBoxValues: [],
stu_new_flag:false,
StudentList_value:"",
modalsType:"",
modalsTopval:"",
modalsBottomval:"",
modalCancel:"",
n_And_e:1,
isSpin:false,
DownloadType:false,
DownloadMessageval:undefined,
sortedInfo: {order:'ascend',columnKey: 'student_id'}
}
}
/// 确认是否下载
confirmysl(url,urls){
// this.props.showGlobalLoading('正在生成文件,请稍后...')
axios.get(url + 'export=true').then((response) => {
if(response === undefined){
return
}
if(response.data.status&&response.data.status===-1){
}else if(response.data.status&&response.data.status===-2){
if(response.data.message === "100"){
// 已超出文件导出的上限数量(100 ),建议:
this.setState({
DownloadType:true,
DownloadMessageval:100
})
}else {
//因附件资料超过500M
this.setState({
DownloadType:true,
DownloadMessageval:500
})
}
}else {
// this.props.showNotification(`正在下载中`);
// window.open("/api"+url, '_blank');
this.props.slowDownload(getRandomcode(url))
// getUrl() + "/api"+
// const fileUrl = url;
// this.props.slowDownload(fileUrl)
// return;
// downloadFile({
// url: fileUrl,
// successCallback: (url) => {
// console.log('successCallback')
// },
// failCallback: (responseHtml, url) => {
// console.log('failCallback')
// }
// })
// window.open(fileUrl, "_self");// , '_blank'
}
}).catch((error) => {
console.log(error)
});
}
hasGroupModule = () => {
const { course_modules } = this.props;
const result = course_modules && course_modules.filter( item => {
return item.type == 'course_group'
})
return result && result.length > 0
}
Downloadcal=()=>{
this.setState({
DownloadType:false,
DownloadMessageval:undefined
})
}
inputStudent=(e)=>{
this.setState({
StudentList_value:e.target.value
})
}
// 有关新建分班和分班重命名
showStuNewBox=(index)=>{
this.setState({
stu_new_flag:true,
n_And_e:index
})
}
hideStuNewBox=()=>{
this.setState({
stu_new_flag:false
})
}
// 有关删除分班
delClasses=()=>{
this.setState({
modalsType:true,
modalsTopval:"该分班的学生将被移动到“XX班”",
modalsBottomval:"是否确认删除?",
modalCancel:true
})
}
cancelDelClasses=()=>{
this.setState({
modalsType:false,
modalsTopval:"",
modalsBottomval:"",
modalCancel:false
})
}
// 确认删除
sureDelClasses=()=>{
this.setState({
modalsType:false,
modalsTopval:"",
modalsBottomval:"",
modalCancel:false
})
}
onChange=()=>{
}
onChangeRoleSuccess = () => {
this.fetchAll()
}
componentDidMount() {
this.setState({
isSpin:true
})
this.fetchAll()
const isAdmin = this.props.isAdmin()
// if (isAdmin) {
this.fetchCourseGroups();
// }
isAdmin && on('addStudentSuccess', this.addStudentSuccessListener)
isAdmin && on('updateNavSuccess', this.updateNavSuccess)
}
componentWillUnmount() {
if (this.clipboard) {
this.clipboard.destroy()
}
const isAdmin = this.props.isAdmin()
if (isAdmin) {
off('addStudentSuccess', this.addStudentSuccessListener)
off('updateNavSuccess', this.updateNavSuccess)
}
}
createGroupImportSuccess = () => {
this.props.updataleftNavfun()
}
updateNavSuccess = () => {
this.fetchCourseGroups()
this.fetchAll()
}
addStudentSuccessListener=(e, data)=>{
const params = JSON.parse(data)
this.props.updataleftNavfun()
const course_group_id = this.props.match.params.course_group_id
const coursesId = this.props.match.params.coursesId
if (params.course_group_id == course_group_id) {
this.fetchAll(1)
} else {
this.props.history.push(`/classrooms/${coursesId}/course_groups/${params.course_group_id || '0'}`)
}
// console.log('addStudentSuccessListener', data)
}
fetchCourseGroups = () => {
const courseId = this.props.match.params.coursesId
let url = `/courses/${courseId}/all_course_groups.json`
axios.get(url, {
})
.then((response) => {
if (response.data.course_groups && response.data.course_groups.length) {
this.setState({
course_groups: response.data.course_groups
})
} else {
// showNotification('')
}
})
.catch(function (error) {
console.log(error);
});
}
componentDidUpdate(prevProps) {
if (prevProps.match.params.course_group_id != this.props.match.params.course_group_id) {
this.setState({checkBoxValues: [], checkAllValue: false })
this.fetchAll(1)
}
// 加载了2次
// else if (prevProps.coursesids != this.props.coursesids) {
// this.fetchAll(1)
// }
}
fetchAll = (argPage) => {
this.setState({
isSpin:true
})
let id = this.props.match.params.coursesId
let course_group_id = this.props.match.params.course_group_id
const { coursesids } = this.props
// if (!coursesids) {
// return;
// }
if (!course_group_id || course_group_id == coursesids) {
course_group_id = ''
}
if (argPage) {
this.setState({ page: argPage })
}
let page = argPage || this.state.page
let { searchValue , sortedInfo }=this.state
let order = 1;
if (sortedInfo.columnKey == 'student_id') {
order = 1;
} else if (sortedInfo.columnKey == 'course_group_name') {
order = 2;
}
let sort = 'desc';
if (sortedInfo.order == 'ascend') {
sort = 'asc'
}
let url=`/courses/${id}/students.json?order=${order}&sort=${sort}&page=${page}&limit=20&course_group_id=${course_group_id}`;
if(!!searchValue){
url+='&search='+searchValue;
}
axios.get(encodeURI(url)).then((result)=>{
if (result.data.students) {
this.setState({
students: result.data.students,
total_count: result.data.students_count,
course_group_name: result.data.course_group_name,
invite_code: result.data.invite_code,
isSpin:false
}, () => {
if (course_group_id) {
if (!this.clipboard) {
const clipboard = new ClipboardJS('.copybtn');
clipboard.on('success', (e) => {
this.props.showNotification('复制成功')
});
this.clipboard = clipboard
}
}
})
}
}).catch((error)=>{
console.log(error);
this.setState({
isSpin:false
})
})
}
onInputSearchChange = (e) => {
this.setState({
searchValue: e.target.value
})
// if (this.timeoutHandler) {
// clearTimeout(this.timeoutHandler)
// }
// this.timeoutHandler = setTimeout(() => {
// this.fetchAll(1)
// }, 1200)
}
onSortTypeChange = (order) => {
this.setState({ order: order }, () => {
this.fetchAll()
})
}
onPageChange = (page) => {
this.fetchAll(page)
this.setState({ checkAllValue: false })
}
onPressEnter = (e) => {
this.fetchAll(1)
}
onCheckBoxChange = (checkedValues) => {
this.setState({
checkBoxValues: checkedValues,
checkAllValue: checkedValues.length == this.state.students.length
})
}
// 多选
moveToGroup = (group) => {
const len = this.state.checkBoxValues.length
if (len == 0) {
this.props.showNotification('请从列表先选择要移动的学生')
return;
}
let id = this.props.match.params.coursesId
let { order, searchValue }=this.state
let url=`/courses/${id}/transfer_to_course_group.json`;
axios.post((url), {
students: this.state.checkBoxValues.map(item => {return {course_member_id: item} }),
course_group_id: group.id
}).then((result)=>{
if (result.data.status == 0) {
this.props.showNotification('移动成功')
this.setState({checkBoxValues: []})
this.fetchAll()
this.props.updataleftNavfun()
}
}).catch((error)=>{
console.log(error);
})
}
onCheckAll = (e) => {
this.setState({
checkAllValue: e.target.checked
})
const values = this.state.students.map(item => {
return item.course_member_id
})
if (e.target.checked) {
const concated = this.state.checkBoxValues.concat(values);
const sortedUniqed = _.uniq(concated)
this.setState({
checkBoxValues: sortedUniqed
})
} else {
this.setState({
checkBoxValues: _.difference(this.state.checkBoxValues, values)
})
}
}
// 多选
onDelete = (record) => {
if (!record) {
const len = this.state.checkBoxValues.length
if (len == 0) {
this.props.showNotification('请先从列表选择要删除的学生')
return;
}
}
this.props.confirm({
// content: `确认要删除所选的${len}个学生吗?`,
content: `是否确认删除?`,
onOk: () => {
let id = this.props.match.params.coursesId
let url=`/courses/${id}/delete_from_course.json`;
axios.post((url), {
students: [{course_member_id: record.course_member_id}] // this.state.checkBoxValues.map(item => {return {course_member_id: item} }),
}).then((result)=>{
if (result.data.status == 0) {
this.props.showNotification('删除成功')
this.props.updataleftNavfun()
this.fetchAll()
this.setState({checkBoxValues: []})
trigger('updatabanner')
}
}).catch((error)=>{
console.log(error);
})
}
})
}
addDir = () => {
trigger('groupAdd', this.props.coursesids)
}
doAddToDir = async () => {
const courseId = this.props.match.params.coursesId
const url = `/courses/${courseId}/join_course_group.json`
const course_group_id = this.props.match.params.course_group_id
const response = await axios.post(url, {
course_group_id
})
if (response && response.data.status == 0) {
this.props.showNotification(`已加入分班:${this.state.course_group_name}`)
this.props.updataleftNavfun()
this.fetchAll()
}
}
addToDir = (record) => {
this.props.confirm({
content: `是否确认加入分班: ${this.state.course_group_name}?`,
okText: '确认',
cancelText: '取消',
onOk: () => {
this.doAddToDir()
},
onCancel() {
console.log('Cancel');
},
});
}
renameDir = () => {
const course_group_id = this.props.match.params.course_group_id
trigger('groupRename', { id: parseInt(course_group_id), name: this.state.course_group_name})
}
deleteDir = () => {
this.props.confirm({
content:
,
onOk: () => {
const course_group_id = this.props.match.params.course_group_id
const courseId = this.props.match.params.coursesId
const url = `/course_groups/${course_group_id}.json`
axios.delete(url)
.then((response) => {
if (response.data.status == 0) {
this.props.showNotification('删除成功')
this.props.history.push(`/classrooms/${courseId}/course_groups`)
}
})
.catch(function (error) {
console.log(error);
});
}
})
}
jsCopy = () => {
var e = document.getElementById("copy_invite_code");
e.select();
document.execCommand("Copy");
this.props.showNotification('复制成功')
}
onTableChange = (pagination, filters, sorter) =>{
this.setState({
sortedInfo: sorter,
}, () => {
this.fetchAll();
});
}
render(){
const isAdmin = this.props.isAdmin()
const isStudent = this.props.isStudent()
const isSuperAdmin = this.props.isSuperAdmin()
const isCourseEnd = this.props.isCourseEnd()
let {
page,
order,
StudentList_value,
stu_new_flag,
modalsType,
modalsTopval,
modalsBottomval,
n_And_e ,
students,
searchValue,
total_count,
course_groups,
checkBoxValues,
checkAllValue
}=this.state;
let currentOrderName = '学生学号排序'
if (order == ORDER_BY_GROUP) {
currentOrderName = '分班名称排序'
}
const { coursesids } = this.props
const course_group_id = this.props.match.params.course_group_id
const isParent = !course_group_id || course_group_id == coursesids
const { course_group_name, invite_code } = this.state;
const courseId = this.props.match.params.coursesId
let exportUrl = `/courses/${courseId}/export_member_scores_excel.xlsx?`; //总成绩
let exportUrltwo = `/courses/${courseId}/export_couser_info.xlsx?`; //课堂信息
let exportUrlthree = `/courses/${courseId}/export_member_act_score.xlsx?`; //活跃度
const params = {}
if (course_group_id) {
params.group_id = course_group_id
}
if (searchValue) {
searchValue = searchValue.trim()
if (searchValue) {
params.search = searchValue
}
}
let paramsString = ''
for (let key in params) {
paramsString += `&${key}=${params[key]}&`
}
exportUrl += paramsString;
exportUrltwo+=paramsString;
exportUrlthree += paramsString;
// console.log(paramsString);
// console.log(checkBoxValues);
// console.log(searchValue);
let pageType = TYPE_STUDENTS
if (this.props.match.path.endsWith('students')) {
} else if (course_group_id) {
pageType = TYPE_COURSE_GOURP_CHILD
} else {
pageType = TYPE_COURSE_GOURP_PARENT
}
// 本页面有2个状态,学生列表、具体分班
const isStudentPage = pageType == TYPE_STUDENTS
this.isStudentPage = isStudentPage
const isGroupChildPage = pageType == TYPE_COURSE_GOURP_CHILD
let studentlist=buildColumns(this,isParent);
if(this.props.isexcellent===true){
studentlist.some((item,key)=> {
if (item.title === "手机号") {
studentlist.splice(key, 1)
return true
}
}
)
}
if(this.props.isexcellent===true){
studentlist.some((item,key)=> {
if (item.title === "邮箱") {
studentlist.splice(key, 1)
return true
}
}
)
}
return(
{
course_group_name ?
{ this.props.history.push(`/classrooms/${courseId}/course_groups`)}}
style={{color: '#212121', verticalAlign: 'initial', marginRight: '14px' }}
>
{course_group_name}
:
- { this.props.history.push(`/classrooms/${courseId}/course_groups`)}}>分班列表
- 未分班
}
{isAdmin && invite_code &&
邀请码:
{invite_code}
成员可以通过邀请码主动加入分班
点击立刻复制邀请码
}>
}
}
searchValue={ searchValue }
onInputSearchChange={this.onInputSearchChange}
showSearchInput={total_count >= 10}
searchPlaceholder={ '请输入姓名、学号进行搜索' }
firstRowRight={
{/* {
// pageType !== TYPE_STUDENTS &&
!isStudentPage && isSuperAdmin &&
this.refs['createGroupByImportModal'].setVisible(true)}>导入创建分班
} */}
{
!isStudentPage && isAdmin && !isParent && course_group_id != 0 && this.deleteDir()}>删除分班 }
{
!isStudentPage && isAdmin && !isParent && course_group_id != 0 && this.renameDir()}>分班重命名 }
{
!isStudentPage && !isCourseEnd && isAdmin && this.addDir()}>新建分班 }
{
!isStudentPage && isStudent && !isParent && course_group_id != 0 && this.addToDir()}>加入分班 }
{ isAdmin &&
导出
}
{/*this.confirmysl(exportUrl)} >导出成绩*/}
{/* */}
}
secondRowLeft={
total_count ? : ''
}
onPressEnter={this.onPressEnter}
>
{
total_count > 0 || this.state.isSpin == true ?
{isAdmin && !isStudentPage &&
已选 {checkBoxValues.length} 个}
{/* {isAdmin &&
删除} */}
{isAdmin && !isStudentPage &&
移动到...
}
{/*
{currentOrderName}
{ course_groups && !!course_groups.length &&
- this.onSortTypeChange(ORDER_BY_NUM)} >学生学号排序
- this.onSortTypeChange(ORDER_BY_GROUP)} >分班名称排序
}
*/}
{students && !!students.length &&
}
:
}
{/* showQuickJumper */}
{ total_count > 20 && }
)
}
}
export default studentsList;