import React,{ Component } from "react"; import { Input,Checkbox,Table, Pagination, Modal,Menu, Tooltip ,Spin} from "antd"; import {WordsBtn, on, off, trigger } from 'educoder'; import HomeworkModal from "../coursesPublic/HomeworkModal"; import AddcoursesNav from "../coursesPublic/AddcoursesNav"; import ImmediatelyPublish from './pollPublicBtn/ImmediatelyPublish'; import ImmediatelyEnd from './pollPublicBtn/ImmediatelyEnd'; import PollListItem from './PollListItem'; import NoneData from '../coursesPublic/NoneData'; import UseBank from '../busyWork/UseBank'; import _ from 'lodash'; import '../css/members.css'; import '../css/busyWork.css'; import Modals from '../../modals/Modals'; import axios from 'axios'; import moment from 'moment'; const Search = Input.Search; class Poll extends Component{ constructor(props){ super(props); this.state={ modalname:undefined, modaltype:undefined, visible:false, Topval:undefined, Topvalright:undefined, Botvalleft:undefined, Botval:undefined, starttime:undefined, endtime:undefined, Cancelname:undefined, Savesname:undefined, Cancel:undefined, Saves:undefined, StudentList_value:undefined, addname:undefined, addnametype:false, addnametab:undefined, addcanner:undefined, addsave:undefined, course_groups:[], chooseId:undefined, // 列表相关 checkBoxValues:[], checkAllValue:false, pollsList:undefined, course_types:undefined, page:1, pageSize:15, type:0, polls_counts:undefined, //公用提示弹框相关 modalsType:false, modalsTopval:"", modalsBottomval:"", loadtype:false, boxType:"delete", isSpin:false } } inputStudent=(e)=>{ this.setState({ StudentList_value:e.target.value }) } // 题库选用 selectBlank=(type)=>{ if(type===2){ this.setState({ addname:"添加目录", addnametype:true, addnametab:type, addcanner:this.homeworkhide, addsave:undefined }) }else if(type===4){ this.setState({ addname:"移动到目录", addnametype:true, addnametab:type, addcanner:this.homeworkhide, addsave:undefined }) } } // 切换菜单选项 changeType=(e)=>{ this.setState({ type:e.key, checkBoxValues:[], checkAllValue:false }) let{StudentList_value,page}=this.state; this.InitList(e.key,StudentList_value,page); } // 获取列表数据 InitList=(type,search,page)=>{ this.setState({ isSpin:true }) let {pageSize}=this.state let coursesId=this.props.match.params.coursesId; let url='/courses/'+coursesId+'/polls.json?limit='+pageSize+'&page='+page if(type!="0"){ url+="&type="+type } if(search!=""&&search!=undefined){ url+="&search="+search } axios.get(url).then((result)=>{ if(result){ this.setState({ pollsList:result.data.polls, course_types:result.data.course_types, polls_counts:result.data.polls_counts, isSpin:false, checkBoxValues:[] }) } }).catch((error)=>{ console.log(error); }) } // 加载列表 componentDidMount(){ this.setState({ isSpin:true }) let{type,StudentList_value,page}=this.state this.InitList(type,StudentList_value,page); on('updateNavSuccess', this.updateNavSuccess) } updateNavSuccess=()=>{ this.setState({ isSpin:true }) let{type,StudentList_value,page}=this.state this.InitList(type,StudentList_value,page); } //切换分页 changePage=(pageNumber)=>{ this.setState({ page:pageNumber }) let{type,StudentList_value}=this.state this.InitList(type,StudentList_value,pageNumber); } // 搜索 searchInfo=()=>{ this.setState({ page:1 }) let{type,StudentList_value}=this.state; this.InitList(type,StudentList_value,1) } // checkbox 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) } // 全选or反选 onCheckAll = (e) => { this.setState({ checkAllValue: e.target.checked }) const values = this.state.pollsList.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) }) } } onCheckBoxChange = (checkedValues) => { this.setState({ checkBoxValues: checkedValues, checkAllValue: checkedValues.length == this.state.pollsList.length }) } //删除或者设为公开 ActionPoll=(value)=>{ let CourseId=this.props.match.params.coursesId; //判断是否有选中数据 if(this.state.checkBoxValues.length==0){ this.props.showNotification("请先在列表中选择数据"); // this.setState({ // modalsType:true, // modalsTopval:"请先在列表中选择数据", // modalsBottomval:'', // loadtype:true // }) }else{ if(value != "bank"){ this.setState({ modalsType:true, modalsTopval:value=="delete"?"已提交作品将全部被删除,不可恢复":"公开后非课堂成员也可以访问查看", modalsBottomval:value=="delete"?"您确定要删除吗?":"是否确认公开?", loadtype:false, boxType:value }) }else{ //加入题库 let url=`/courses/${CourseId}/polls/join_poll_banks.json`; axios.post((url), { check_ids: this.state.checkBoxValues }) .then((result)=>{ if(result){ this.props.showNotification(`${result.data.message}`); this.setState({ modalsType:false, modalsTopval:"", modalsBottomval:"", loadtype:false, checkBoxValues:[], checkAllValue:false }) let{type,StudentList_value}=this.state this.InitList(type,StudentList_value,1); } }).catch((error)=>{ console.log(error); }) } } } //取消删除或者设为公开 modalCancel=()=>{ this.setState({ modalsType:false, modalsTopval:"", modalsBottomval:"", loadtype:false }) } //确定删除或者设为公开 ModalAction=()=>{ let CourseId=this.props.match.params.coursesId; if(this.state.checkBoxValues.length==0){ this.setState({ modalsType:false, modalsTopval:"", loadtype:false, checkBoxValues:[] }) }else{ if(this.state.boxType=="delete"){ //删除 let url=`/courses/${CourseId}/polls/destroys.json`; axios.post((url), { check_ids: this.state.checkBoxValues }) .then((result)=>{ if(result){ this.props.showNotification(`${result.data.message}`); this.setState({ modalsType:false, modalsTopval:"", modalsBottomval:"", loadtype:false, checkBoxValues:[] }) let{type,StudentList_value}=this.state this.InitList(type,StudentList_value,1); this.props.updataleftNavfun(); } }).catch((error)=>{ console.log(error); }) }else if(this.state.boxType=="public"){ //设为公开 let url=`/courses/${CourseId}/polls/set_public.json`; axios.post((url), { check_ids: this.state.checkBoxValues }) .then((result)=>{ if(result){ this.props.showNotification(`${result.data.message}`); this.setState({ modalsType:false, modalsTopval:"", loadtype:false, checkBoxValues:[] }) let{type,StudentList_value}=this.state this.InitList(type,StudentList_value,1); } }).catch((error)=>{ console.log(error); }) } } } successFun=()=>{ let{type,StudentList_value,page}=this.state this.InitList(type,StudentList_value,page) } // 题库选用成功后,立即发布,刷新页面 useBankSuccess=(checkValue,value)=>{ this.setState({ isSpin:true }) let{type,StudentList_value,page}=this.state this.InitList(type,StudentList_value,page); this.setState({ checkBoxValues:[] }) let coursesId=this.props.match.params.coursesId; let url=`/courses/${coursesId}/polls/publish_modal.json`; axios.get(url,{ params:{ check_ids:value } }).then((response) => { if(response){ let list=[]; if(response.data.course_info){ for(var i=0;i 0 ? 1 : 2, visible:true, Topval:"本操作只对“未发布”的对象生效", Botvalleft:"暂不发布", Botval:"则通过后续手动设置,定时发布", starttime:"发布时间:"+moment(moment(new Date())).format("YYYY-MM-DD HH:mm"), starttimes:this.props.getNowFormatDates(1), endtime:"截止时间:"+this.props.getNowFormatDates(2), Cancelname:"暂不发布", Savesname:"立即发布", Cancel:this.homeworkhide, Saves:this.homeworkstartend, }) } }).catch((error) => { console.log(error) }); } getcourse_groupslist=(id)=>{ this.setState({ chooseId:id }) } // 确定立即发布 homeworkstartend=(value,endtime)=>{ let {checkBoxValues}=this.state; let coursesId=this.props.match.params.coursesId; let url=`/courses/${coursesId}/polls/publish.json` axios.post(url,{ check_ids:checkBoxValues, group_ids:value, end_time:endtime }).then((result)=>{ if(result){ let{type,StudentList_value,page}=this.state this.InitList(type,StudentList_value,page); this.props.showNotification(result.data.message); this.homeworkhide(); } }).catch((error)=>{ console.log(error); }) } //暂不发布 homeworkhide=()=>{ this.setState({ modalname:undefined, modaltype:undefined, visible:false, Topval:undefined, Topvalright:undefined, Botvalleft:undefined, Botval:undefined, starttime:undefined, endtime:undefined, Cancelname:undefined, Savesname:undefined, Cancel:undefined, Saves:undefined, StudentList_value:undefined, addname:undefined, addnametype:false, addnametab:undefined, checkBoxValues:[] }) } render(){ let { modalname, modaltype, visible, Topval, Topvalright, Botvalleft, Botval, starttime, endtime, Cancelname, Savesname, Cancel, Saves, StudentList_value, addname, addnametype, addnametab, addcanner, addsave, course_groups, checkAllValue, checkBoxValues, course_types, pollsList, page, pageSize, polls_counts, modalsType, modalsTopval, modalsBottomval, loadtype }=this.state; // console.log(this.props); let {child}=this.props; let {coursesId,Id}=this.props.match.params const isAdmin = this.props.isAdmin() const isStudent=this.props.isStudent(); // console.log(child) return( {visible===true?this.getcourse_groupslist(id)} />:""} {/*添加目录/选择目录*/} {/* 公用的提示弹框 */}

{polls_counts&&polls_counts.left_banner_name} { isAdmin &&

  • 新建
  • }

    共{polls_counts && polls_counts.polls_total_counts}个问卷 已发布:{polls_counts && polls_counts.polls_published_counts}个 未发布:{polls_counts && polls_counts.polls_unpublish_counts}个

    全部 { course_types && course_types.user_permission == 1 && 未发布 } 提交中 已截止
    { pollsList && pollsList.length > 0 && isAdmin &&
    已选 {checkBoxValues.length} 个
    } { pollsList && pollsList.length > 0 &&
    { pollsList && pollsList.map((item,key)=>{ return( this.onItemClick(item)}>} > ) }) }
    }
    { pollsList && pollsList.length==0 && } { course_types && polls_counts.polls_all_counts > pageSize ?
    : "" }
    ) } } export default Poll;