import React, { Component } from 'react';
import { Modal , Radio , Table , Pagination , Select ,Divider ,Icon , Input } from "antd";
import {Link} from 'react-router-dom'
import axios from 'axios';
import '../style.css'
const RadioGroup = Radio.Group;
const { Option } = Select;
const $ = window.$;
const bindTableColumn=(that)=>{
let { course_groups }=that.state
const filter=course_groups && course_groups.map((i,key)=>{
let list={
value: i.id,
text: i.name
}
return list;
})
const columns = [
{
title: '序号',
dataIndex: 'index',
key: 'index',
width:"50px",
className:"edu-txt-center",
render: (id, student, index) => {
return (that.state.page - 1) * that.state.limit + index + 1
}
},
{
title: '姓名',
dataIndex: 'user_name',
key: 'user_name',
render: (user_name, line, index) => {
return(
{user_name}
)
}
},{
title: '学号',
dataIndex: 'student_id',
key: 'student_id',
render: (student_id, line, index) => {
return(
{student_id}
)
}
},{
title: '分班',
dataIndex: 'course_group_name',
key: 'course_group_name',
filters:filter,
render: (course_group_name, line, index) => {
return(
{course_group_name}
)
}
}
];
if(that.state.comment_status == 2){
columns.push({
title: '交叉评阅老师',
dataIndex: 'cross_teachers',
key: 'cross_teachers',
width:"200px",
render: (cross_teachers, line, index) => {
return(
{cross_teachers}
)
}
})
}else{
columns.push({
title: '答辩组',
dataIndex: 'cross_groups',
key: 'cross_groups',
width:"200px",
render: (cross_groups, line, index) => {
return(
{cross_groups}
)
}
})
}
return columns;
}
class GraduationAcross extends Component{
constructor(props){
super(props);
this.state={
comment_status:2,
page:1,
limit:7,
group_ids:undefined,
users:undefined,
user_count:undefined,
graduation_groups:undefined,
course_groups:undefined,
teachers:undefined,
tableLoading:false,
chooseCount:0,
chooseId:undefined,
AcrossTeamIds:undefined,
searchValue:undefined,
showflag:false
}
}
// 根据分班筛选
filterByGroup=(value,record)=>{
console.log(value);
console.log(record)
}
// 切换分配方式
funcommentstatus = (e) =>{
this.setState({
comment_status:e.target.value,
chooseCount:0,
chooseId:[],
AcrossTeamIds:undefined,
searchValue:undefined,
showflag:false,
page:1
})
let { group_ids }=this.state;
this.getList(1,group_ids,e.target.value);
}
componentDidMount =()=>{
let { comment_status }=this.props;
let { page,group_ids }=this.state;
this.setState({
comment_status
})
this.getList(page,group_ids,comment_status);
window.addEventListener('click', this.clickOther)
}
clickOther = (e) =>{
if(e.target && e.target.matches('#acrossContent') || e.target.matches(".ant-modal-body")
|| e.target.matches(".acrossfoot") || e.target.matches(".acrossHead") || e.target.matches ('.ant-radio-wrapper') ||
e.target.matches("th") || e.target.matches("td")) {
this.setState({
showflag:false
})
}
}
componentWillUnmount() {
window.removeEventListener('click', this.clickOther);
}
getList=(page,group_ids,comment_status)=>{
let { limit }=this.state;
let { task_Id }=this.props;
this.setState({
tableLoading:true
})
let url=`/graduation_tasks/${task_Id}/cross_comment_setting.json`;
axios.get((url),{params:{
page,limit,group_ids,comment_status
}}).then((result)=>{
if(result){
this.setState({
users:result.data.work_users && result.data.work_users.map((item,key)=>{
let list = {
key:item.work_id,
course_group_name:item.course_group_name,
cross_teachers: item.cross_teachers,
student_id:item.student_id,
user_name:item.user_name,
work_id:item.work_id
}
return list;
}),
user_count:result.data.user_count,
graduation_groups:result.data.graduation_groups,
course_groups:result.data.course_groups,
teachers:result.data.teachers,
tableLoading:false,
// AcrossTeamIds:result.data
})
}
}).catch((error)=>{
this.setState({
tableLoading:false
})
console.log(error);
})
}
// 切换分页
onPageChange=(page)=>{
this.setState({
page,
showflag:false
})
let{group_ids,comment_status}=this.state;
this.getList(page,group_ids,comment_status);
}
// 下拉切换
changeSelect = (AcrossTeamIds) =>{
this.setState({
AcrossTeamIds
})
}
// 重置
clearSelect =()=>{
this.setState({
AcrossTeamIds:undefined,
searchValue:undefined
})
}
// 确定分配
sureAcross=()=>{
let { AcrossTeamIds , chooseId , group_ids , comment_status }=this.state;
let { task_Id }=this.props;
let type = comment_status == 2 ? "user_ids" : "graduation_group_ids";
let url=`/graduation_tasks/${task_Id}/assign_works.json`;
if(!AcrossTeamIds || (AcrossTeamIds && AcrossTeamIds.length==0)){
this.props.showNotification(`请先选择${ comment_status == 2 ? "老师": "答辩组" }!`);
return;
}
if(!chooseId || (chooseId && chooseId.length==0)){
this.props.showNotification("请先选择毕设作品!");
return;
}
axios.post((url),{
[type]:AcrossTeamIds,
work_ids:chooseId
}).then((result)=>{
if(result){
this.props.showNotification(result.data.message);
this.getList(1,group_ids,comment_status);
this.setState({
showflag:false,
AcrossTeamIds:undefined,
chooseCount:0,
chooseId:[]
})
}
}).catch((error)=>{
console.log(error);
})
}
// 筛选
handleTableChange =(pagination, filters, sorter)=>{
console.log(filters.course_group_name)
// if(filters.course_group_name.length > 0){
this.setState({
page:1,
group_ids:filters.course_group_name
})
let { comment_status }= this.state;
this.getList(1,filters.course_group_name,comment_status);
// }
}
// 下拉搜索
changeSearchValue=(e)=>{
this.setState({
searchValue:e.target.value
})
}
// 显示下拉
changeFlag=(flag)=>{
this.setState({
showflag:flag
})
}
render(){
let {
comment_status,
users,
user_count,
graduation_groups,
course_groups,
teachers,
page,
limit,
tableLoading,
chooseCount,
chooseId,
AcrossTeamIds,
searchValue,showflag
} = this.state;
let { modalVisible } = this.props;
let courseId = this.props.match.params.coursesId;
const radioStyle = {
display: 'block',
height: '30px',
lineHeight: '30px',
marginRight:'0px'
};
const rowSelection = {
// 选中行的key,选中行
onChange: (selectedRowKeys, selectedRows) => {
this.setState({
chooseId:selectedRowKeys,
chooseCount:selectedRowKeys.length,
showflag:false
})
console.log(selectedRowKeys);
},
selectedRowKeys:chooseId,
getCheckboxProps: record => ({
disabled: record.name === 'Disabled User', // Column configuration not to be checked
name: record.name,
}),
};
// 筛选下拉列表
const teacherList = searchValue ? teachers.filter(e=>e.user_name.indexOf(searchValue)>-1) : teachers;
const course_groupsList = searchValue ? course_groups.filter(e=>e.name.indexOf(searchValue)>-1) : course_groups;
return(
评阅分配方式:
手动分配评阅(逐一指定每个学生的交叉评阅老师)
答辩组分配评阅(将老师加入不同答辩组,指定每个学生的交叉评阅答辩组,
立即设置答辩组
)
已选 { chooseCount == 0 ? 0 : {chooseCount}} 个
分配给{ comment_status && comment_status == 2 ? "老师":"答辩组"}:
{
user_count > limit ?
:""
}
)
}
}
export default GraduationAcross;