import React, {Component} from 'react'; import axios from 'axios'; import {SnackbarHOC, WordsBtn,getImageUrl,markdownToHTML} from 'educoder'; import {Row, Col,Input,Divider,Card,Button,Pagination,Breadcrumb,Icon,Spin} from 'antd'; import { TPMIndexHOC } from '../tpm/TPMIndexHOC'; import { CNotificationHOC } from '../courses/common/CNotificationHOC'; import Osshackathonmd from './Osshackathonmd'; import './Osshackathon.css'; import Osshackathonmodel from "./Osshackathonmodel"; const { Search } = Input; class Osshackathon extends Component { constructor(props) { super(props) this.state = { page:1, limit:10, search:undefined, data:undefined, hackathonedit:false, Osshackathonmodeltype:false, spinning:false, opentitletype:true, boxoffsetHeigh:0 } } componentDidMount() { this.getosshackathonlist(); window.document.title = '竞赛报名'; } getosshackathon=(page,limit,search)=>{ this.setState({ spinning:true }) let url=`/osshackathon.json`; axios.get(url,{params:{ page:page, limit:limit, search:search, }}).then((result)=>{ if(result.status==200){ this.setState({ data:result.data, spinning:false }) }else{ this.setState({ spinning:false }) } }).catch((error)=>{ this.setState({ spinning:true }) }) } getosshackathonlist=()=>{ let {page,limit,search}=this.state; this.setState({ page:1, search:undefined }) this.getosshackathon(1,limit,undefined) } componentDidUpdate = (prevProps,prevState) => { if(prevState.data!=this.state.data){ //防止陷入无限循环 let box=document.getElementById("Osshackathonfontlists"); if(box){ this.setState({ boxoffsetHeigh:box.offsetHeight }) } } } PaginationTask=(pageNumber)=>{ let {hackathonedit}=this.state; if(hackathonedit===true){ this.props.showNotification(`请先保存或者关闭编辑状态`); }else { this.setState({ page: pageNumber }) let {page, limit, search} = this.state; this.getosshackathon(pageNumber, limit, search) } } hackathonedit=(id)=>{ //管理员编辑title this.setState({ hackathonedit:true }) } hidehackathonedit=()=>{ this.setState({ hackathonedit:false }) } Signupentry=(id)=>{ // 用户报名 if(this.props.checkIfLogin()===false){ this.props.showLoginDialog() return } if(this.props.checkIfProfileCompleted()===false){ this.props.showProfileCompleteDialog() return } //判断是否绑定邮箱 if(this.props.user.email===null&&this.props.user.phone===null){ this.props.showhideAccountPhoneemailDialog() return } this.props.confirm({ content: `是否确认报名?`, onOk: () => { this.Signupentrys(id) } }) } Signupentrys=(id)=>{ let url=`/osshackathon/${id}/entry.json`; axios.post(url ).then((response) => { if(response.data.status===0){ this.getosshackathonlist() this.props.showNotification(`报名成功,预祝您夺得桂冠`); } }).catch((error) => { console.log(error) }) } editSignupentry=(id,name,description)=>{ let {hackathonedit}=this.state; if(hackathonedit===true){ this.props.showNotification(`请先保存或者关闭编辑状态`); }else{ // 管理员编辑项目 this.setState({ Osshackathonmodeltype:true }) if(id===undefined){ this.setState({ modelid:undefined, modelname:undefined, modeldescription:undefined }) }else{ this.setState({ modelid:id, modelname:name, modeldescription:description }) } } } hideeditSignupentry=(id)=>{ // 管理员取消项目 this.setState({ Osshackathonmodeltype:false }) } delSignupentry=(id)=>{ // 管理员删除项目 let {hackathonedit}=this.state; if(hackathonedit===true){ this.props.showNotification(`请先保存或者关闭编辑状态`); }else { this.props.confirm({ content: `是否确认删除该项目?`, onOk: () => { this.delSignupentrys(id) } }) } } delSignupentrys=(id)=>{ let url=`/osshackathon/${id}.json`; axios.delete(url) .then((response) => { if (response.data.status == 0) { // {"status":1,"message":"删除成功"} this.getosshackathonlist(); this.props.showNotification(`删除成功`); } }) .catch(function (error) { console.log(error); }); } onsearchvalue=(value)=>{ let {hackathonedit}=this.state; if(hackathonedit===true){ this.props.showNotification(`请先保存或者关闭编辑状态`); }else { this.setState({ search:value }) if(value.length>300){ this.props.showNotification(`搜索字数大于300个字`); } let {page,limit,search}=this.state; this.getosshackathon(page,limit,value) } } onsetsearchvalue=(e)=>{ this.setState({ search:e.target.value }) } opentitle=()=>{ this.setState({ opentitletype:false }) } render() { let {page,data,hackathonedit,opentitletype}=this.state; return (
{this.props.user&&this.props.user.admin===true? this.onsetsearchvalue(e)} onSearch={value => this.onsearchvalue(value)} />
报名总数:{data&&data.hackathon.hackathon_users_count}
:""} {hackathonedit===true?"": {data&&data.hackathon.name} {this.props.user&&this.props.user.admin===true? :""} } {hackathonedit===true?"": } {hackathonedit===true?"":} {opentitletype===true?:""} {hackathonedit===true?"":

{data&&data.hackathon.description===null?"":

}

} {opentitletype===true&&this.state.boxoffsetHeigh===180?this.opentitle()} className={"pointer Breadcrumbfont"}>展开阅读全文:""} {hackathonedit===true?this.getosshackathonlist()} hidehackathonedit={()=>this.hidehackathonedit()} {...this.props} {...this.state} />:""} {this.state.Osshackathonmodeltype===true?this.getosshackathonlist()} hideeditSignupentry={()=>this.hideeditSignupentry()} {...this.props} {...this.state} />:""} {this.props.user&&this.props.user.admin===true? :""} {/*学生身份*/} { this.props.user&&this.props.user.admin===false?data&&data.hacks.length==0?"":data&&data.hacks.map((item,key)=>{ return( {item.name} 报名人数:{item.hack_users_count} {item.entry_info===true?:}

{item.description}

) }):"" } {/*教师身份*/} {this.props.user&&this.props.user.admin===true?:""} { this.props.user&&this.props.user.admin===true?data&&data.hacks.length==0?"":data&&data.hacks.map((item,key)=>{ return( {item.name} this.editSignupentry(item.id,item.name,item.description)}>编辑 this.delSignupentry(item.id)}>删除
{item.hack_users_count}
报名数
{item.description}
)}):"" } {data&&data.hacks_count>10?data&&data.hacks.length===0?"":
:""}
) } } export default CNotificationHOC() (TPMIndexHOC (Osshackathon)) ;