import React,{Component} from 'react'; import { Modal,Checkbox,Select,Input,Tooltip,Spin,Icon,Drawer,Dropdown,Menu,Breadcrumb,Pagination,Button,notification} from "antd"; import axios from'axios'; import NoneData from "../coursesPublic/NoneData"; import './Newshixunmodel.css'; const Search = Input.Search; class NewShixunModel extends Component{ constructor(props){ super(props) this.state={ shixun_list:undefined, shixuns_count:undefined, Grouplist:[], allGrouplist:[{page:1,list:[]}], page:1, type:'all', status:'all', keyword:undefined, order:'desc', diff:0, limit:20, sort:"myshixuns_count", belongtoindex:0, } } componentDidMount() { let{page,type,keyword,order,diff,limit,status,sort}=this.state; if(this.props.type==='shixuns'){ this.getdatalist(page,type,status,keyword,order,diff,limit,undefined,sort); }else{ this.getdatalist(page,type,undefined,keyword,order,undefined,limit,undefined,sort); } } getdatalist=(page,type,newstatus,keyword,order,diff,limit,pagetype,sorts)=>{ let newsort=sorts; let no_jupyter=undefined; if(this.props.type==="shixuns"&&type==="mine"){ if(this.props&&this.props.user.course_name===undefined){ newsort="created_at"; }else{ newsort="publish_time"; } } if(this.props.type==="shixuns"){ if(this.props&&this.props.user.course_name===undefined){ }else{ no_jupyter=1; } } this.setState({ isspinning:true }) let status=this.props.statustype===undefined?newstatus:'published'; let url; if(this.props.type==='shixuns'){ url="/shixun_lists.json"; }else{ url="/subject_lists.json"; } axios.get(url,{params:{ page:page, type:type, status:status, keyword:keyword, order:order, diff:diff, limit:limit, sort:newsort, no_jupyter:no_jupyter }}).then((response) => { if(response.data){ if(pagetype===undefined){ this.setState({ shixun_list:response.data.shixun_list===undefined?response.data.subject_list:response.data.shixun_list, shixuns_count:response.data.shixuns_count===undefined?response.data.subjects_count:response.data.shixuns_count, Grouplist:[], isspinning:false }) }else if(pagetype==="pagetype"){ this.setState({ shixun_list:response.data.shixun_list===undefined?response.data.subject_list:response.data.shixun_list, shixuns_count:response.data.shixuns_count===undefined?response.data.subjects_count:response.data.shixuns_count, isspinning:false }) } } }).catch((error) => { this.setState({ isspinning:false }) }) } DropdownClick=(diff)=>{ this.setState({ diff:diff }) let{page,type,status,keyword,order,limit}=this.state; this.getdatalist(page,type,status,keyword,order,diff,limit) } ItsCourse=(item)=>{ return {item.map((list,key)=>{ return( {list.name} ) })} } getGrouplist=(Grouplist)=>{ let {page,allGrouplist}=this.state; let newallGrouplist=allGrouplist; var a=newallGrouplist.find((value,index,arr)=>{ return value.page==page }); if(a!=undefined){ newallGrouplist.map((item,key)=>{ if(item.page===page){ item.list=Grouplist } }) } let newGrouplist=[]; newallGrouplist.map((item,key)=>{ item.list.map((items,ke)=>{ newGrouplist.push(items) }) }) this.setState({ Grouplist: newGrouplist, allGrouplist:newallGrouplist }) } PaginationCourse=(pageNumber)=>{ let {allGrouplist}=this.state; let newallGrouplist=allGrouplist; var v=newallGrouplist.find((value,index,arr)=>{ return value.page==pageNumber }); if(v===undefined){ newallGrouplist.push({page:pageNumber,list:[]}) } let{type,status,keyword,order,diff,limit,sort}=this.state; if(this.props.type==='shixuns'){ this.getdatalist(pageNumber,type,status,keyword,order,diff,limit,"pagetype") }else{ this.getdatalist(pageNumber,type,undefined,keyword,order,undefined,limit,"pagetype",sort); } this.setState({ page:pageNumber, allGrouplist:newallGrouplist }) } belongto=(value)=>{ this.setState({ type:value, keyword:undefined, page:1 }) let{status,order,diff,limit,sort}=this.state; if(this.props.type==='shixuns'){ this.getdatalist(1,value,status,undefined,order,diff,limit); if(value==="all"){ this.setState({ belongtoindex:0 }) }else{ this.setState({ belongtoindex:1 }) } }else{ this.getdatalist(1,value,undefined,undefined,order,undefined,limit,undefined,sort) } } updatedlist=(order)=>{ if(order==="desc"){ this.setState({ order:"asc" }) let{type,page,status,keyword,diff,limit}=this.state; this.getdatalist(page,type,status,keyword,"asc",diff,limit) }else{ this.setState({ order:"desc" }) let{type,page,status,keyword,diff,limit}=this.state; this.getdatalist(page,type,status,keyword,"desc",diff,limit) } } setdatafunsval=(e)=>{ this.setState({ keyword:e.target.value }) } setdatafuns=(value)=>{ this.setState({ keyword:value, type:undefined, page:1, status:'all', order:'desc', diff:0, limit:20, }) this.getdatalist(1,undefined,'all',value,'desc',0,20) } savecouseShixunModal=()=>{ this.setState({ hometypepvisible:true }) let {coursesId}=this.props; let{Grouplist}=this.state; if(Grouplist.length===0){ this.setState({ hometypepvisible:false }) this.props.showNotification(this.props.type==='shixuns'?"请先选择实训":"请先选择课程") return } if (this.props.chooseShixun) { if(Grouplist.length>1){ this.setState({ hometypepvisible:false }) this.props.showNotification("试卷选择的实训数不能大于1") return } this.props.chooseShixun(Grouplist) this.setState({ hometypepvisible:false }) return; } if (this.props.pathShixun) { this.setState({ hometypepvisible:false }) this.props.pathShixun(Grouplist) return; } if(this.props.type==='shixuns'){ let url="/courses/"+coursesId+"/homework_commons/create_shixun_homework.json"; axios.post(url, { category_id:this.props.category_id===null||this.props.category_id===undefined?undefined:parseInt(this.props.category_id), shixun_ids:Grouplist, } ).then((response) => { if(response.data.status===-1){ // this.props.showNotification(response.data.message) }else{ // this.props.courseshomeworkstart(response.data.category_id,response.data.homework_ids) this.props.showNotification("操作成功") this.props.homeworkupdatalists(this.props.Coursename,this.props.page,this.props.order); this.props.hideNewShixunModelType() this.props.updataleftNavfun() } this.setState({ hometypepvisible:false }) // category_id: 3 // homework_ids: (5) [9171, 9172, 9173, 9174, 9175] }).catch((error) => { console.log(error) this.setState({ hometypepvisible:false }) }) }else{ let url="/courses/"+coursesId+"/homework_commons/create_subject_homework.json"; axios.post(url, { category_id:this.props.category_id===null||this.props.category_id===undefined?undefined:parseInt(this.props.category_id), subject_ids:Grouplist, } ).then((response) => { if(response.data.status===-1){ // this.props.showNotification(response.data.message) }else{ // this.props.courseshomeworkstart(response.data.category_id,response.data.homework_ids) this.props.showNotification("操作成功") this.props.homeworkupdatalists(this.props.Coursename,this.props.page,this.props.order); this.props.hideNewShixunModelType() this.props.updataleftNavfun() } this.setState({ hometypepvisible:false }) // category_id: 3 // homework_ids: (5) [9171, 9172, 9173, 9174, 9175] }).catch((error) => { console.log(error) this.setState({ hometypepvisible:false }) }) } } poststatus=(status)=>{ this.setState({ status:status }) let{page,type,keyword,order,diff,limit}=this.state; this.getdatalist(page,type,status,keyword,order,diff,limit) } updatepathlist=(sorts,orders)=>{ let{page,type,keyword,order,diff,limit,status,sort}=this.state; let seartorders; if(sort===sorts){ if(orders==="desc"){ this.setState({ sort:sorts, order:"asc" }) seartorders="asc" }else{ this.setState({ sort:sorts, order:"desc" }) seartorders="desc" } }else{ this.setState({ sort:sorts, order:"desc" }) seartorders=orders } this.getdatalist(page,type,undefined,keyword,seartorders,undefined,limit,undefined,sorts) } render() { let {diff,Grouplist,status,shixun_list,shixuns_count,page,type,order,sort,belongtoindex}=this.state; // let {visible,patheditarry}=this.props; // console.log(Grouplist) // console.log(allGrouplist) const statusmenus=( this.poststatus("all")}> 所有 this.poststatus("published")} > 已发布 this.poststatus("unpublished")}> 未发布 ); const menus = ( this.DropdownClick(0)}> 所有 this.DropdownClick(1)} > 初级 this.DropdownClick(2)}> 中级 this.DropdownClick(3)}> 高级 this.DropdownClick(4)}> 顶级 ); return(
this.props.hideNewShixunModelType()} visible={this.props.type==='shixuns'?this.props.NewShixunModelType:this.props.shixunpath} height={'100%'} >
搜索} onInput={(e)=>this.setdatafunsval(e)} onSearch={ (value)=>this.setdatafuns(value)} />
{this.props.type==='shixuns'?

筛选:

this.belongto("all")}>全部实训

this.belongto("mine")}>我的实训

:"" } {/*{this.props.type==='shixuns'? */} {/* */} {/* {diff===0?"难度":diff===1?"初级":diff===2?"中级":diff===3?"高级":diff===4?"顶级":""}*/} {/* */} {/*:""}*/} {this.props.type==='shixuns'?

难度:

this.DropdownClick(0)}>全部

this.DropdownClick(1)}>初级

this.DropdownClick(2)}>中级

this.DropdownClick(3)}>高级

this.DropdownClick(4)}>顶级

:"" }
已选 {Grouplist.length} 个{this.props.type==='shixuns'?'实训':'课程'} {shixuns_count===undefined?"":shixuns_count} 个{this.props.type==='shixuns'?'实训':'课程'} {this.props.type==='shixuns'?"": this.updatepathlist("shixuns_count",order)}>实训数 } {this.props.type==='shixuns'?"": this.updatepathlist("myshixuns_count",order)}>学习人数 } {this.props.type==='shixuns'? this.updatedlist(order)}>学习人数 :""} {this.props.type==='shixuns'?this.props.statustype===undefined? {status==='all'?"发布状态":status==='published'?"已发布":status==="unpublished"?"未发布":""} :"":""}
{this.props.type==='shixuns'?"": this.belongto("mine")}>我的课程 } {this.props.type==='shixuns'?"": this.belongto("all")}>全部课程 }
{shixun_list===undefined?"":shixun_list.length===0?"":shixun_list.map((item,key)=>{ return(
{ this.props.type==='shixuns'? ( item.is_jupyter===true?

Jupyter

:"" ) :"" }
{JSON.stringify(item.description) == "{}"?"":
} {item.challenge_names===undefined?"":item.challenge_names.length===0?"":
{item.challenge_names.map((item,key)=>{ return( 第{key+1}关:{item} ) })}
}
{this.props.type==='shixuns'? {item.author_name} {item.author_school_name} 难度系数:{item.level} 学习人数:{item.study_count} : {item.author_name} {item.author_school_name} 学习人数:{item.myshixuns_count} 章节:{item.stage_count} 实训:{item.shixuns_count} }
{item.subjects===undefined?"":item.subjects.length===0?"":this.ItsCourse(item.subjects)}> 所属课程 }
)}) }
{shixun_list===undefined||shixuns_count===undefined?"":shixun_list.length===0||shixuns_count===0?"":shixuns_count>20?
:""} { shixun_list===undefined?
:shixun_list.length===0? :"" }
{ shixun_list===undefined?"":shixun_list.length===0?"":
}
) } } export default NewShixunModel; // {JSON.stringify(item.content) == "{}"?
//
:
// {item.content.description === undefined || item.content.description===0?"":item.content.description.map((item,key)=>{ // return( // {} // ) // })} //
} // // {JSON.stringify(item.content) == "{}"?item.challenge_names.length===0?"":
// {item.challenge_names.map((item,key)=>{ // return( // 第{key+1}关:{item} // ) // })} //
:
// {item.content.challenge_names === undefined || item.content.challenge_names===0?"":item.content.challenge_names.map((item,key)=>{ // return( // {} // ) // })} //
}