import React, { Component } from 'react'; import { Breadcrumb,Layout,Table, Divider, Tag,Badge,Row, Col,Button, Menu, Icon} from 'antd'; import { Link } from 'react-router-dom'; import axios from 'axios'; import {markdownToHTML,getImageUrl} from 'educoder'; import CompetitionContents from './CompetitionContents'; import CompetitionContentsChart from './CompetitionContentsChart'; import NoneData from "../../courses/shixunHomework/shixunHomework"; import './CompetitionCommon.css'; const { Header, Footer, Sider, Content } = Layout; class CompetitionCommon extends Component{ constructor(props) { super(props) this.state={ data:undefined, bannerdata:undefined, module_type:undefined, mdContentdata:undefined } } componentDidMount(){ window.document.title = '竞赛'; if(this.props.match.params.identifier!=null){ this.getbannerdata(); let url=`/competitions/${this.props.match.params.identifier}.json`; axios.get(url).then((response) => { if(response.status===200){ this.setState({ bannerdata:response.data }) } }).catch((error) => { console.log(error) }) } } getbannerdata=()=>{ let url=`/competitions/${this.props.match.params.identifier}/common_header.json`; axios.get(url).then((response) => { if(response.status===200){ this.setState({ data:response.data, }) this.getrightdata( response.data.competition_modules[0].id, response.data.competition_modules[0].module_type, response.data.competition_modules[0].module_url, response.data.competition_modules[0].has_url ) } }).catch((error) => { console.log(error) }) } getrightdata=(id,typeid,module_url,has_url)=>{ console.log(id,typeid,module_url,has_url) this.setState({ module_id:id, module_type:typeid }) if(has_url===false){ let url=`${module_url}`; axios.get(url).then((response) => { if(response.status===200){ this.setState({ mdContentdata:response.data }) } }).catch((error) => { console.log(error) }) } } render() { let {data,bannerdata,module_type,module_id,mdContentdata}=this.state; console.log(module_type) return ( data===undefined?"":
在线竞赛 {data&&data.name}
{data.competition_status==="nearly_published"? this.props.current_user&&this.props.current_user.admin===true?"":this.props.current_user&&this.props.current_user.business===true?"":
即将发布 敬请期待
:""} {data&&data.name} 竞赛时间: {data&&data.start_time}~{data&&data.end_time}
奖金
浏览数
报名数
¥{data&&data.bonus}
{data.competition_status==="nearly_published"?"--":data&&data.visits_count}
{data.competition_status==="nearly_published"?"--":data&&data.member_count}
{data.competition_status==="ended"?:} {data.competition_status==="ended"? : } {data&&data.enroll_end_time===null?"":`报名截止时间:${data&&data.enroll_end_time}`}
{data&&data.competition_modules.map((item,key)=>{ return( {item.has_url===false?this.getrightdata(item.id,item.module_type,item.module_url,item.has_url)}>{item.name}:this.getrightdata(item.id,item.module_type)} >{item.name}} ) })} {this.state.module_type==="chart"?:} {/**/}
) } } export default CompetitionCommon;