import React,{ Component } from "react"; import {Checkbox, Menu, Pagination,Spin} from "antd"; import CourseLayoutcomponent from '../../common/CourseLayoutComponent' import Titlesearchsection from '../../common/titleSearch/TitleSearchSection' import DownloadMessageysl from "../../../modals/DownloadMessageysl"; import { WordsBtn } from 'educoder' import NoneData from '../../coursesPublic/NoneData' import Modals from "../../../modals/Modals" import axios from 'axios' import UseBank from '../../busyWork/UseBank' import _ from 'lodash' import GraduateTopicItem from './GraduateTopicItem' import ChooseGraduateTopicModal from './ChooseGraduateTopicModal' import '../../css/members.css' import '../../css/busyWork.css' import '../style.css' class Boards extends Component{ constructor(props){ super(props); this.state = { searchValue: '', checkAllValue: false, checkBoxValues: [], data:[], topicList: undefined, course_public:1, page:1, totalCount:undefined, status:"all", pageSize:15, modalsType:"", modalsTopval:"", modalsBottomval:"", topicId:undefined, index:undefined, flag:true, delType:false, delTopval:"", delLoadType:false, delOrPublic:1, isSpin:true, DownloadType:false, DownloadMessageval:undefined, } } fetchAll = (searchValue,page,status) => { this.setState({ checkAllValue: false, isSpin:true }) let {pageSize}=this.state; const cid = this.props.match.params.coursesId let url = `/courses/${cid}/graduation_topics.json?limit=`+pageSize if(searchValue!=""){ url+="&search="+searchValue } if(page!=""){ url+="&page="+page } if(status!="" && status != "all"){ url+="&status="+status; } axios.get(url).then((response) => { if (response.status == 200 && response.status) { this.setState({ data:response.data, topicList:response.data.graduation_topic, totalCount:response.data.graduation_topic_count, course_public:response.data.course_public, isSpin:false }) } }) .catch(function (error) { console.log(error); }); } componentDidMount = () => { this.setState({ isSpin:true }) let{searchValue,page,status}=this.state this.fetchAll(searchValue,page,status); } //搜索 onPressEnter = (value) => { this.setState({ page:1, searchValue:value, checkBoxValues:[] }) let {status}=this.state; this.fetchAll(value,1,status); } onInputSearchChange = (e) => { this.setState({ searchValue:e.target.value }) } // 全选or反选 onCheckAll = (e) => { this.setState({ checkAllValue: e.target.checked }) const values = this.state.topicList.map(item => { return item.id }) if (e.target.checked) { const concated = this.state.checkBoxValues.concat(values); const uniq=_.uniq(concated) this.setState({ checkBoxValues: uniq }) } else { this.setState({ checkBoxValues: _.difference(this.state.checkBoxValues, values) }) } } onItemClick = (item) => { const checkBoxValues = this.state.checkBoxValues.slice(0); const index = checkBoxValues.indexOf(item.id); if (index != -1) { _.remove(checkBoxValues, (listItem)=> listItem === item.id) } else { checkBoxValues.push(item.id) } this.onCheckBoxChange(checkBoxValues) } onCheckBoxChange = (checkedValues) => { this.setState({ checkBoxValues: checkedValues, checkAllValue: checkedValues.length == this.state.topicList.length }) } // 分页 onChangePage=(pageNum)=>{ this.setState({ page:pageNum }) let {status,searchValue}=this.state; this.fetchAll(searchValue,pageNum,status); console.log(this.state.checkBoxValues); } // 筛选 onChangeStatus =(e)=>{ this.setState({ page:1, status:e.key, checkBoxValues:[], isSpin:true }) let {searchValue}=this.state; this.fetchAll(searchValue,1,e.key==="all"?"":e.key); } // 选题or取消选题 chooseTopic=(topicId,index,flag)=>{ this.setState({ modalsType:true, modalsTopval:flag ==true ? "是否确认取消选题?":"是否确认选题?", modalsBottomval:"", modalCancel:true, topicId:topicId, index:index, flag:flag }) } cancelOperateTopic=()=>{ this.setState({ modalsType:false, modalsTopval:"", modalsBottomval:"", modalCancel:false }) } sureOperateTopic=()=>{ let{topicId,index,flag}=this.state; let courseid=this.props.match.params.coursesId let url="/courses/"+courseid+"/graduation_topics/"+topicId+"/" if(flag){ url+="student_cancel_topic.json" }else{ url+="student_select_topic.json" } axios.post((url)).then((result)=>{ if(result.data.status == 0){ this.props.showNotification(`${result.data.message}`); let {searchValue,page,status} =this.state this.fetchAll(searchValue,page,status); this.cancelOperateTopic(); } }).catch(error=>{ console.log(error); }) } // 删除 onDelete=(index)=>{ let {checkBoxValues}=this.state; if(checkBoxValues.length>0){ if(index<3){ this.setState({ delType:true, delTopval:index==1?"是否确认删除?":"是否设为公开?", delLoadType:false, delOrPublic:index }) }else{ // 加入题库 let courseid=this.props.match.params.coursesId let url=`/courses/${courseid}/graduation_topics/add_to_bank.json`; axios.post((url),{ topic_ids:checkBoxValues }).then((result)=>{ if(result){ this.props.showNotification(`题库更新成功`); let {searchValue,page,status} =this.state this.fetchAll(searchValue,page,status); this.setState({ checkBoxValues:[], checkAllValue:false }) } }).catch((error)=>{ console.log(error) }) } }else{ this.setState({ // delType:true, // delTopval:"请先在列表中选择数据", // delLoadType:true, delOrPublic:index }) this.props.showNotification("请先在列表中选择数据"); } } cancelDelTopic=()=>{ this.setState({ delType:false, delTopval:"", delLoadType:false }) } sureDelTopic=()=>{ let {checkBoxValues,delOrPublic}=this.state; if(checkBoxValues.length>0){ let courseid=this.props.match.params.coursesId; let url=""; // 删除 if(delOrPublic==1){ url="/courses/"+courseid+"/graduation_topics/destroys.json"; axios.delete((url), { data: { graduation_topic_ids: this.state.checkBoxValues }}) .then((result)=>{ if(result.data.status==0){ this.props.showNotification(`${result.data.message}`); this.setState({ delType:false, delTopval:"", checkBoxValues:[] }) let {searchValue,status} =this.state; this.fetchAll(searchValue,1,status); } }).catch((error)=>{ console.log(error); }) }else if(delOrPublic==2){ // 设为公开 url="/courses/"+courseid+"/graduation_topics/set_public.json"; axios.post((url), { graduation_topic_ids: this.state.checkBoxValues }).then((result)=>{ if(result.data.status==0){ this.props.showNotification(`${result.data.message}`); this.setState({ delType:false, delTopval:"", checkBoxValues:[] }) let {searchValue,status} =this.state; this.fetchAll(searchValue,1,status); } }).catch((error)=>{ console.log(error); }) } }else{ this.setState({ delType:false, delTopval:"", delLoadType:false }) } } // 新建 onBoardsNew=()=>{ let courseId=this.props.match.params.coursesId this.props.history.push(`/courses/${courseId}/graduation_topics/new`) } /// 确认是否下载 confirmysl(url){ axios.get(url + '?export=true').then((response) => { 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'); } }).catch((error) => { console.log(error) }); } Downloadcal=()=>{ this.setState({ DownloadType:false, DownloadMessageval:undefined }) } render(){ let { searchValue, topicList, data, course_public, checkBoxValues, checkAllValue, page, totalCount, pageSize, //选题和取消选题 modalsType, modalsTopval, modalsBottomval, // 删除弹框 delType, delTopval, delLoadType } = this.state; // let {course_identity}=this.props.coursedata const isAdmin =this.props.isAdmin(); return( {/* 参考普通作业 - 题库选用 */} {/* this.useFromBank()}>题库选用 正式版没有,先隐藏*/} < a className={"fl color-blue mr30 font-16"} onClick={(url)=>this.confirmysl(`/courses/${this.props.match.params.coursesId}/graduation_topics/export.xlsx`)}>导出

this.onBoardsNew()}>新建
):"" } secondRowLeft={
全部 待选中 待确认 已确认
} onPressEnter={this.onPressEnter} searchPlaceholder={"请输入名称进行搜索"} showSearchInput={topicList&&topicList.length >= pageSize} > { topicList && topicList.length > 0 ? (
{ // 超级管理员、教师、助教 isAdmin ?
已选 {checkBoxValues.length} 个
  • this.onDelete(1)}>删除
  • { course_public && course_public==1 ?
  • this.onDelete(2)}>设为公开
  • :"" }
  • this.onDelete(3)}>加入题库
  • {/*
  • 加入题库
  • */}
    :"" }
    { topicList.map((item, index) => { return (
    this.onItemClick(item)} className="mr15">} onItemClick={this.onItemClick} index={index} chooseTopic={this.chooseTopic} >
    ) }) }
    ):(topicList && topicList.length===0?:
    ) }
    { totalCount && totalCount > pageSize ?
    :
    }
    ) } } export default Boards;