import React,{ Component } from "react"; import { Input,Checkbox,Table, Divider, Tooltip,Spin, Menu, Popconfirm } from "antd"; import CourseLayoutcomponent from '../common/CourseLayoutComponent' import NoneData from "../coursesPublic/NoneData" import Titlesearchsection from '../common/titleSearch/TitleSearchSection' import ColorCountText from '../common/titleSearch/ColorCountText' import update from 'immutability-helper' import { WordsBtn, ConditionToolTip, on, off ,trigger, sortDirections } from 'educoder' import axios from 'axios' import _ from 'lodash' // import { RouteHOC } from './common.js' import '../css/members.css' import { from } from "array-flatten"; // import AddTeacherModal from './modal/AddTeacherModal' // import AddStudentModal from './modal/AddStudentModal' import AddGraduationGroupModal from './modal/AddGraduationGroupModal' import AddAdminModal from './modal/AddAdminModal' import CourseGroupChooserModal from './modal/CourseGroupChooserModal' import { ROLE_TEACHER_NUM, ROLE_ASSISTANT_NUM } from './common' import CourseGroupChooser from './CourseGroupChooser' import ChangeRolePop from './ChangeRolePop' const Search = Input.Search; const ROLE_ADMIN = "管理员" const ROLE_TEACHER = "教师" const ROLE_TEACHER_ASSISTANT = "助教" const pageSize = 20; function buildColumns(that) { let sortedInfo = that.state.sortedInfo || {} const isAdmin = that.props.isAdmin() const isAdminOrCreator = that.props.isAdminOrCreator(); const isAdminOrTeacher = that.props.isAdminOrTeacher() const { course_groups, filterKey } = that.state const showSorter = filterKey == '1' const courseId = that.props.match.params.coursesId const columns = [{ title: '序号', dataIndex: 'name', key: 'index', width: 78, render: (content, item, index) => { return index + 1 // return item.isApply == true ? '' : {(that.state.page - 1) * 20 + index + 1 // - (that.state.application_list ? that.state.application_list.length : 0)}  } } // ,{ // title: '用户ID', // width: 120, // dataIndex: 'login', // key: 'login', // render: (login, record) => { // return 8 ? login : ''}`}>{login} // } // } , { title: '姓名', dataIndex: 'name', width: 120, key: 'name', sorter: showSorter, sortDirections: sortDirections, sortOrder: sortedInfo.columnKey === 'name' && sortedInfo.order, render: (name, record) => { return 4 ? name : ''}`}>{name} } }, { title: '角色', dataIndex: 'role', key: 'role', sorter: showSorter, width: 86, // 'ascend' | 'descend' defaultSortOrder: 'ascend', sortDirections: sortDirections, sortOrder: sortedInfo.columnKey === 'role' && sortedInfo.order, }] that.state.course_groups && that.state.course_groups.length && showSorter && columns.push({ title: 管理权限, width: 260, key: 'course_groups', dataIndex: 'course_groups', // onClick={() => that.joinCourseGroup(item.id)} // "right":"0px", render: (arg_course_groups, item, index) => { if (!arg_course_groups) { return '' } // ((!course_groups || course_groups.length == 0) &&

暂未有分班信息,不能操作

) const noGroups = (!course_groups || course_groups.length == 0); return ( { arg_course_groups.length == 0 ? '全部分班' : arg_course_groups.map(item => item.name).join(', ') } { isAdmin && {!noGroups && } } ) } , }); const hasGraduationModule = that.hasGraduationModule() if (hasGraduationModule && showSorter) { columns.push({ title: '所在答辩组', // width: 90, sorter: showSorter, sortDirections: sortDirections, key: 'graduation_group', dataIndex: 'graduation_group', sortOrder: sortedInfo.columnKey === 'graduation_group' && sortedInfo.order, render: text => ( 10 ? text : ''}`} > {text} ), }) } if (isAdminOrTeacher) { columns.push({ title: '操作', key: 'action', width: 150, align:'center', render: (text, record) => { const isAdmin = record.role == ROLE_ADMIN const isTeacher = record.role == ROLE_TEACHER const isAssitant = record.role == ROLE_TEACHER_ASSISTANT if (record.application_id) { return ( that.onRefuse(record)} style={'grey'}>拒绝 that.onAgree(record)} style={{color: '#4CACFF'}}>同意 ) } else { return ( that.onDelete(record)} style={'grey'}>删除 {/* 管理员 助教 学生 } > 修改角色 */} // // {record.role != ROLE_ADMIN && that.onDelete(record)} style={'grey'}>删除} // {(record.role == ROLE_TEACHER || record.role == ROLE_TEACHER_ASSISTANT || isAdminOrCreator) && record.role != ROLE_ADMIN // && } // { record.role == ROLE_TEACHER ? that.changeToAssistant(record)}>变更为助教 : '' } // { record.role == ROLE_TEACHER_ASSISTANT ? that.changeToTeacher(record)}>变更为教师 : '' } // { record.role == ROLE_ADMIN && isAdminOrCreator ? that.showChangeAdminModal(record)}>更换管理员 : '' } // ) } }, }) } // 待审批不需要 if(filterKey == '1' && isAdminOrTeacher && hasGraduationModule) { columns.unshift({ title: '', dataIndex: 'course_member_id', key: 'course_member_id', render: (content, item, index) => { return content ? : '' } }) } return columns } const ORDER_BY_NAME = 1; const ORDER_BY_DATE = 2; const ORDER_BY_GRADUATION_GROUP = 3; class studentsList extends Component{ constructor(props){ super(props); this.state={ headIndex:"1", page:1, sortedInfo: { columnKey: 'role', order: 'ascend'}, totalPage:undefined, searchValue:"", order: ORDER_BY_DATE, search:"", groupList:undefined, teachers: [], checkBoxValues: [], isSpin:false, application_list: [], course_groups: [], checkAllArray: [], filterKey: 1, // 1 已审批 2 待审批 } } onCheckAllChange = (e, item, index) => { const that = this; const checkAllArray = that.state.checkAllArray.slice(0) checkAllArray[index] = !checkAllArray[index] that.setState({checkAllArray}) if (checkAllArray[index]) { that.joinCourseGroup(that.state.course_groups.map((item) => item.id), item, index) } else { that.joinCourseGroup([], item, index) } } inputSearch=(e)=>{ this.setState({ searchValue:e.target.value }) } // approval 2 - 拒绝 onAgree = (record, approval = 1) => { const isAdminOrCreator = this.props.isAdminOrCreator() const { course_groups ,filterKey} = this.state if (approval == 1 && isAdminOrCreator && course_groups && course_groups.length) { this.setState({ clickRecord: record}, () => { this.setGroupChooserModalVisible(true) }) return; } const courseId = this.props.match.params.coursesId let url = `/courses/${courseId}/teacher_application_review.json` this.props.confirm({ content: `是否确认${ approval == 1 ? '同意' : '拒绝'}TA的加入?`, onOk: () => { axios.post(url, { user_id: record.user_id, application_id: record.application_id, approval: approval }) .then((response) => { if (response.data.status == 0) { this.props.showNotification(`已${approval == 1? '同意' : '拒绝'}`) this.fetchAll(1,filterKey) } }) .catch(function (error) { console.log(error); }); } }) } onRefuse = (record) => { this.onAgree(record, 2) } componentDidMount(){ this.setState({ isSpin:true }) let newmenuid=this.props.location.search.replace('?tab=', ''); if(newmenuid===undefined||newmenuid===""||newmenuid==="1"||newmenuid===1){ this.setState({ filterKey:'1' }) this.fetchAll(1,'1'); }else{ this.setState({ filterKey:'2' }) this.fetchAll(1,'2'); } const isAdminOrTeacher = this.props.isAdminOrTeacher() const isAdmin = this.props.isAdmin() isAdminOrTeacher && this.getGroupList(); this.getCourseGroups(); on('addTeacherSuccess', this.addTeacherSuccessListener) isAdmin && on('updateNavSuccess', this.updateNavSuccess) } componentWillUnmount() { off('addTeacherSuccess', this.addTeacherSuccessListener) const isAdmin = this.props.isAdmin() isAdmin && off('updateNavSuccess', this.updateNavSuccess) } updateNavSuccess = () => { this.getCourseGroups() } addTeacherSuccessListener = (e, data) => { // const params = JSON.parse(data) // const coursesId = this.props.match.params.coursesId if (window.location.pathname.endsWith('teachers')) { this.fetchAll(1,this.state.filterKey) } else { // this.props.history.push(`/courses/${coursesId}/teachers`) } // console.log('addTeacherSuccessListener', data) } getCourseGroups = () => { const courseId = this.props.match.params.coursesId let url = `/courses/${courseId}/all_course_groups.json` axios.get(url, { params: { all: true } }) .then((response) => { if (response.data.course_groups && response.data.course_groups.length) { let course_groups_map = {} response.data.course_groups.forEach(item => { course_groups_map[item.id] = item.name }) this.setState({ course_groups: response.data.course_groups, course_groups_map }) } else { } }) .catch(function (error) { console.log(error); }); } joinCourseGroup = (ids, item, index) => { // console.log('join ', ids, item) const courseId = this.props.match.params.coursesId let url = `/courses/${courseId}/set_course_group.json` axios.post(url, { course_group_ids: ids, user_id: item.user_id, course_member_id: item.course_member_id }) .then((response) => { if (response.data.status == 0) { this.props.showNotification('修改成功') const newArray = ids.map((item) => {return {id: item, name: this.state.course_groups_map[item]}}); this.setState( (prevState) => ({ teachers : update(prevState.teachers, {[ this.state.page == 1 ? index - this.state.application_list.length : index]: { course_groups: {$set: newArray }}}) })) // this.fetchAll() } else { } }) .catch(function (error) { console.log(error); }); } onChangeRoleSuccess = () => { this.fetchAll(undefined,this.state.filterKey) } fetchAll = async (argPage,filterKey) => { let { searchValue }=this.state this.setState({ isSpin:true }) let id = this.props.match.params.coursesId if (argPage) { this.setState({ page: argPage }) } const sortedInfo = this.state.sortedInfo; let page = argPage || this.state.page let order = 1; if (sortedInfo.columnKey == 'role') { order = 1; } else if (sortedInfo.columnKey == 'name') { order = 2; } else if (sortedInfo.columnKey == 'graduation_group') { order = 3; } let sort = 'desc' if (sortedInfo.order == 'ascend') { sort = 'asc' } let url=`/courses/${id}/teachers.json?order=${order}&page=${page}&sort=${sort}`; if (filterKey == '1') { } else if (filterKey == '2') { url = `/courses/${id}/apply_teachers.json?_a=1` } if(searchValue!=""){ url+='&search='+searchValue; } const result = await axios.get(encodeURI(url)) // axios.get((url)).then((result)=>{ if (result.data.teacher_list) { this.setState({ teachers: result.data.teacher_list, total_count: result.data.teacher_list_size, application_list: result.data.application_list || [], is_admin: result.data.is_admin, apply_size: result.data.apply_size, isSpin:false }) } else if (result.data.application_list) { this.setState({ total_count: result.data.teacher_list_size, application_list: result.data.application_list || [], is_admin: result.data.is_admin, apply_size: result.data.apply_size, isSpin:false }) } // }).catch((error)=>{ // console.log(error); // this.setState({ // isSpin:false // }) // }) } getGroupList(){ let id = this.props.match.params.coursesId let url='/courses/'+id+'/graduation_group_list.json'; axios.get((url)).then((result)=>{ if(result.status==200){ this.setState({ groupList:result.data }) } }).catch((error)=>{ console.log(error); }) } onAddGraduationGroupOk = () => { this.getGroupList() } // join_graduation_group joinGraduationGroup = (graduation_group_id) => { const courseId = this.props.match.params.coursesId let { filterKey }=this.state let url= `/courses/${courseId}/join_graduation_group.json`; axios.post(url, { course_member_list: this.state.checkBoxValues.map (item => { return { course_member_id: item } }), graduation_group_id: graduation_group_id }).then((result)=>{ if(result.data.status==0){ this.props.showNotification('操作成功。') this.fetchAll(undefined,filterKey) } }).catch((error)=>{ console.log(error); }) } onInputSearchChange = (e) => { let {filterKey}=this.state; this.setState({ searchValue: e.target.value }) if (this.timeoutHandler) { clearTimeout(this.timeoutHandler) } this.timeoutHandler = setTimeout(() => { this.fetchAll(1,filterKey) }, 1200) } onPressEnter = (e) => { this.fetchAll(1,this.state.filterKey) } onCheckBoxChange = (checkedValues) => { this.setState({ checkBoxValues: checkedValues, checkAllValue: checkedValues.length == this.state.teachers.length }) } onCheckAll = (e) => { this.setState({ checkAllValue: e.target.checked }) const values = this.state.teachers.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) }) } } onSortTypeChange = (order) => { this.setState({ order: order }, () => { this.fetchAll() }) } changeRole = (member, role) => { const courseId = this.props.match.params.coursesId let {filterKey}=this.state; let url= `/courses/${courseId}/change_course_teacher.json`; axios.post(url, { course_member_id: member.course_member_id // "user_list": [ // { "user_id": member.user_id } // ], // "graduation_group_id": member.graduation_group_id, // "course_group_id": "820", // "role": role }).then((result)=>{ if(result.data.status==0){ this.props.showNotification('操作成功。') this.fetchAll(undefined,filterKey) } }).catch((error)=>{ console.log(error); }) } changeToAssistant = (member) => { this.changeRole(member, ROLE_ASSISTANT_NUM) } changeToTeacher = (member) => { this.changeRole(member, ROLE_TEACHER_NUM) } showChangeAdminModal = () => { this.refs.addAdminModal.setVisible(true) } changeAdminSuccess = () => { let {filterKey}=this.state; this.fetchAll(undefined,filterKey) } onDelete = (member) => { let {filterKey}=this.state; this.props.confirm({ content: `确认要将“${member.name}”从教师列表中移除吗?`, onOk: () => { // const cid = this.props.match.params.coursesId const courseId = this.props.match.params.coursesId const url = `/courses/${courseId}/delete_course_teacher.json` axios.post(url, { course_member_id: member.course_member_id }) .then((response) => { if (response.data.status == 0) { // {"status":1,"message":"删除成功"} this.props.showNotification('删除成功') trigger('updatabanner') this.fetchAll(undefined,filterKey) } }) .catch(function (error) { console.log(error); }); } }) } addTeacher = () => { this.refs.addTeacherModal.setVisible(true) } addStudent = () => { this.refs.addStudentModal.setVisible(true) } hasGraduationModule = () => { const { course_modules } = this.props; const result = course_modules && course_modules.filter( item => { return item.type == 'graduation' }) return result && result.length > 0 } onTableChange = (pagination, filters, sorter) => { let {filterKey}=this.state; console.log('Various parameters', pagination, filters, sorter); this.setState({ page: pagination.current, sortedInfo: sorter, }, () => { this.fetchAll(undefined,filterKey) }); }; clearSelection = () => { this.setState({ checkBoxValues: [] }) } selectedStatus=(e)=>{ this.clearSelection() this.setState({ filterKey: e.key, page:1, isSpin:true }, () => { this.fetchAll(undefined,e.key); }) } setGroupChooserModalVisible = (visible) => { // 这里只会调用open this.setState({groupChooserModalVisible: !this.state.groupChooserModalVisible}) } render(){ const isAdmin = this.props.isAdmin() const columns = buildColumns(this) let { searchValue, checkBoxValues, checkAllValue, course_groups, groupList, total_count, teachers, order, page, apply_size, filterKey }=this.state let currentOrderName = '加入时间排序' if (order == ORDER_BY_NAME) { currentOrderName = '姓名排序' } else if (order == ORDER_BY_GRADUATION_GROUP) { currentOrderName = '答辩组排序' } let combineArray = teachers.slice(0) if (page == 1 && filterKey == '2') { // this.state.application_list && this.state.application_list.slice(0).reverse().forEach(item => { // item.isApply = true // combineArray.unshift(item) // }) combineArray = this.state.application_list } const isAdminOrTeacher = this.props.isAdminOrTeacher() const isAdminOrCreator = this.props.isAdminOrCreator() const isSuperAdmin = this.props.isSuperAdmin() const hasGraduationModule = this.hasGraduationModule() const coursesId = this.props.match.params.coursesId return( {/* */} {isAdminOrTeacher && } 教师列表 {!isSuperAdmin && coursesId == '1309' && (示例课堂,部分成员不可见)} } searchValue={ searchValue } onInputSearchChange={this.onInputSearchChange} showSearchInput={total_count >= 10} searchPlaceholder={ '请输入姓名进行搜索' } firstRowRight={ {/* { isAdmin && this.addTeacher()}>添加教师 } { isAdmin && this.addStudent()}>添加学生 } */} { isAdminOrCreator && this.showChangeAdminModal()}>更换管理员} } secondRowLeft={ isAdminOrTeacher ?
已审批({total_count}) 待审批({apply_size}) {/* */}
: (!!total_count ? : '') } onPressEnter={this.onPressEnter} >
{ course_groups && !!course_groups.length && this.fetchAll(e,this.state.filterKey)} course_groups={course_groups} visible={this.state.groupChooserModalVisible} setVisible={this.setGroupChooserModalVisible} > } {filterKey == '1' &&
{ isAdminOrTeacher && hasGraduationModule && 已选 {checkBoxValues.length} 个 } { filterKey == '1' &&
{ hasGraduationModule && isAdminOrTeacher &&
  • 加入答辩组
      { groupList && groupList.graduation_groups_count>10? (

      {this.setState({graduationGroupSearchValue: e.target.value})}} allowClear/>

      ): (groupList && groupList.graduation_groups_count==0 &&

      暂无数据

      ) } { groupList && groupList.graduation_group_list && groupList.graduation_group_list.filter((item)=> { return (!this.state.graduationGroupSearchValue || item.name.indexOf(this.state.graduationGroupSearchValue) != -1) }).map((item,key)=>{ return(
    • this.joinGraduationGroup(item.id)}>{item.name}
    • ) }) } { groupList && groupList.graduation_groups_count > 0 && }

      this.refs['addGraduationGroupModal'].setVisible(true)} >添加答辩组...

  • } {/*
  • {currentOrderName}
    • this.onSortTypeChange(ORDER_BY_NAME)} >姓名排序
    • this.onSortTypeChange(ORDER_BY_DATE)} style={{width: '125px'}}>加入时间排序
    • {this.hasGraduationModule() &&
    • this.onSortTypeChange(ORDER_BY_GRADUATION_GROUP)} >答辩组排序
    • }
  • */}
    }
    }
    {combineArray.length ? {/* pagination={{ current: page, total: total_count, pageSize:20, onChange: this.onPageChange }} */} 20 && filterKey == '1' ? { //分页 total: page == 1 && this.state.application_list.length ? total_count + total_count / Math.floor(this.state.application_list.length + 20) : total_count , //数据总数量 pageSize: page == 1 && this.state.application_list.length ? this.state.application_list.length + 20 : 20, //显示几条一页 current: page, // onChange: this.onPageChange } : false} >
    : }
    ) } } export default studentsList;