import React, { Component } from "react"; import { Modal, Checkbox, Input, Spin, Select, Divider } from "antd"; import axios from 'axios' import ModalWrapper from "../../common/ModalWrapper" import InfiniteScroll from 'react-infinite-scroller'; import { ROLE_TEACHER_NUM, ROLE_ASSISTANT_NUM } from '../common' import NoneData from '../../coursesPublic/NoneData' import { ConditionToolTip, ThemeContext } from 'educoder' import SchoolSelect from '../../coursesPublic/form/SchoolSelect' const Option = Select.Option; const pageCount = 15; class AddStudentModal extends Component{ constructor(props){ super(props); this.state={ checkBoxValues: [], users: [], hasMore: true, loading: false, courseGroup: '', page: 1, isSpin:false } } fetchMemberList = (arg_page) => { const courseId = this.props.match.params.coursesId const page = arg_page || this.state.page; const { name, school_name } = this.state let url = `/courses/${courseId}/search_users.json?page=${page}&limit=${pageCount}&school_name=${school_name || ''}&name=${name || ''}` this.setState({ loading: true }) axios.get(encodeURI(url)) .then((response) => { if (!response.data.users || response.data.users.length == 0) { this.setState({ users: page == 1 ? response.data.users : this.state.users, page, loading: false, hasMore: false, }) } else { this.setState({ users: page == 1 ? response.data.users : this.state.users.concat(response.data.users), page, loading: false, hasMore: response.data.users.length == pageCount }) } }) .catch(function (error) { console.log(error); }); } componentDidMount() { } fetchOptions = () => { // add_teacher_popup 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, courseGroup: response.data.course_groups[0].id }) } else { // showNotification('') } }) .catch(function (error) { console.log(error); }); } setVisible = (visible) => { if (visible) { this.setState({school_name: this.props.user.user_school}) this.fetchMemberList() this.fetchOptions() } this.refs.modalWrapper.setVisible(visible) if (visible == false) { this.setState({ checkBoxValues: [] }) } } onSendOk = () => { if(!this.state.checkBoxValues || this.state.checkBoxValues.length == 0) { this.props.showNotification('请从列表中先选择用户。') return; } this.setState({ isSpin:true }) const courseId = this.props.match.params.coursesId const url = `/courses/${courseId}/add_students_by_search.json` const params = { "user_ids": this.state.checkBoxValues } const { courseGroup } = this.state if (courseGroup) { params.course_group_id = courseGroup } axios.post(url, params) .then((response) => { if (response.data.status == 0) { this.setVisible(false) this.props.showNotification('添加成功') this.props.addStudentSuccess && this.props.addStudentSuccess(params) this.setState({ isSpin:false }) } }) .catch(function (error) { console.log(error); }); } onOk = () => { this.onSendOk() } onCheckBoxChange = (checkBoxValues) => { this.setState({ checkBoxValues: checkBoxValues }) } handleInfiniteOnLoad = () => { this.fetchMemberList(this.state.page + 1) } onSearch = () => { this.fetchMemberList(1) } handleCourseGroupChange = (value) => { this.setState({ courseGroup: value }) } render(){ const { users, checkBoxValues, loading, hasMore, name, school_name , courseGroup, course_groups,isSpin } = this.state const { moduleName } = this.props let theme = this.context; return(
姓名: {this.setState({name: e.target.value})}} style={{ width: '221px'}} > 单位: {/* {this.setState({school_name: e.target.value})}} style={{ width: '200px'}}> */} {this.setState({school_name: value})}} > this.fetchMemberList(1)} style={{ height: '30px', lineHeight: '30px', marginLeft: '10px', width: '70px'}} >搜索
{/* */}

{ loading || users.length ?
{/* https://github.com/CassetteRocks/react-infinite-scroller/issues/70 */}
{ users.map( candidate => { return (

12 }> 12 }>

) }) }
{loading && hasMore && (
)}
{course_groups && course_groups.length &&
所选学生分班至(选填):
}
: }
) } } AddStudentModal.contextType = ThemeContext; export default AddStudentModal;