import React from 'react';
import { Button, Radio } from 'antd';
import './content.less';
import { getTime, getProportion } from '../../../../tools';
import CompanyDetail from './companyDetail';



const Content = React.createClass({
    getInitialState() {
        return {
            loading: false,
            component: CompanyDetail
        };
    },
    returnFoster() {
        this.props.returnBtn();
    },
    onChange(e) {
        switch (e.target.value) {
            case 'companyDetail':
                this.setState({
                    component: CompanyDetail,
                    radioValue: 'companyDetail'
                });
                break;
            case 'orgTechCenter':
                require.ensure([], () => {
                    const OrgTechCenter = require('./orgTechCenter').default;
                    this.setState({
                        component: OrgTechCenter,
                        radioValue: 'orgTechCenter'
                    });
                });
                break;
            case 'activity':
                require.ensure([], () => {
                    const Activity = require('./activity').default;
                    this.setState({
                        component: Activity,
                        radioValue: 'activity'
                    });
                });
                break;
            case 'activityCostList':
                require.ensure([], () => {
                    const ActivityCostList = require('./activityCostList').default;
                    this.setState({
                        component: ActivityCostList,
                        radioValue: 'activityCostList'
                    });
                });
                break;
            case 'techProduct':
                require.ensure([], () => {
                    const TechProduct = require('./techProduct').default;
                    this.setState({
                        component: TechProduct,
                        radioValue: 'techProduct'
                    });
                });
                break;
            case 'intellectual':
                require.ensure([], () => {
                    const Intellectual = require('./intellectual').default;
                    this.setState({
                        component: Intellectual,
                        radioValue: 'intellectual'
                    });
                });
                break;
            case 'achievement':
                require.ensure([], () => {
                    const Achievement = require('./achievement').default;
                    this.setState({
                        component: Achievement,
                        radioValue: 'achievement'
                    });
                });
                break;
            case 'ratepay':
                require.ensure([], () => {
                    const Ratepay = require('./ratepay').default;
                    this.setState({
                        component: Ratepay,
                        radioValue: 'ratepay'
                    });
                });
                break;
            case 'finance':
                require.ensure([], () => {
                    const Finance = require('./finance').default;
                    this.setState({
                        component: Finance,
                        radioValue: 'finance'
                    });
                });
                break;
            case 'hrSituation':
                require.ensure([], () => {
                    const HrSituation = require('./hrSituation').default;
                    this.setState({
                        component: HrSituation,
                        radioValue: 'hrSituation'
                    });
                });
                break;
            case 'honorList':
                require.ensure([], () => {
                    const HonorList = require('./honorList').default;
                    this.setState({
                        component: HonorList,
                        radioValue: 'honorList'
                    });
                });
                break;
            case 'standard':
                require.ensure([], () => {
                    const Standard = require('./standard').default;
                    this.setState({
                        component: Standard,
                        radioValue: 'standard'
                    });
                });
                break;
            case 'innovationAbility':
                require.ensure([], () => {
                    const InnovationAbility = require('./innovationAbility').default;
                    this.setState({
                        component: InnovationAbility,
                        radioValue: 'innovationAbility'
                    });
                });
                break;
            case 'annualReport':
                require.ensure([], () => {
                    const AnnualReport = require('./annualReport').default;
                    this.setState({
                        component: AnnualReport,
                        radioValue: 'annualReport'
                    });
                });
                break;
        };
    },
    componentWillReceiveProps(nextProps) {
        if (nextProps.style === "block") {
            let e = { target: { value: "companyDetail" } }
            this.onChange(e);
        };
        if (nextProps.data) {
            let _me = this;
            getProportion(nextProps.data.uid, function (data) {
                let s = 0;
                s = (
                    (data.institution ? 5 : 0)
                    + (data.activity ? 15 : 0)
                    + (data.activityCost ? 15 : 0)
                    + (data.techProject ? 10 : 0)
                    + (data.intellectualProperty ? 15 : 0)
                    + (data.achievement ? 10 : 0)
                    + (data.ratepay ? 5 : 0)
                    + (data.finance ? 5 : 0)
                    + (data.humanResource ? 5 : 0)
                    + (data.honorDatum ? 5 : 0)
                    + (data.ability ? 5 : 0)
                    + (data.standard ? 5 : 0))
                _me.setState({
                    progressNumber: s
                });
            });
        };
    },
    render() {
        if (this.props.data) {
            return (
                <div className="foster-desc" style={{ display: this.props.style }}>
                    <div className="content-tabs">
                        <div className="foster-title">
                            <span className="company-name">{this.props.data.unitName}</span>
                            <span className="company-number">{this.props.data.certificateNumber || ''}</span>
                            {this.props.data.issuingDate ?
                                <span className="company-time"> 有效期 {getTime(this.props.data.issuingDate)} 至 {getTime(this.props.data.issuingDate, 36)} </span> : ''
                            }
                            <span className="company-number">当前进度: </span>
                            <span className="progress-bar">
                                <i style={{ width: this.state.progressNumber + '%' }}></i>
                            </span>
                            <span className="progress-num">{this.state.progressNumber}%</span>
                            <Button className="foster-return" type="primary" onClick={this.returnFoster}>返回高企培育列表</Button>
                        </div>
                        <div className="clearfix foster-component">
                            <Radio.Group onChange={this.onChange} value={this.state.radioValue}>
                                <Radio.Button value="companyDetail">企业基本信息</Radio.Button>
                                <Radio.Button value="orgTechCenter">企业研发机构</Radio.Button>
                                <Radio.Button value="activity">研发活动</Radio.Button>
                                <Radio.Button value="activityCostList">研发活动费用详情</Radio.Button>
                                <Radio.Button value="techProduct">高新技术产品</Radio.Button>
                                <Radio.Button value="intellectual">知识产权</Radio.Button>
                                <Radio.Button value="achievement">科技成果转化</Radio.Button>
                                <Radio.Button value="ratepay">企业所得税纳税申报表</Radio.Button>
                                <Radio.Button value="finance">财务报表</Radio.Button>
                                <Radio.Button value="hrSituation">企业人员情况</Radio.Button>
                                <Radio.Button value="honorList">企业荣誉及其他证明材料</Radio.Button>
                                <Radio.Button value="standard">标准制定情况</Radio.Button>
                                <Radio.Button value="innovationAbility">企业创新能力</Radio.Button>
                                <Radio.Button value="annualReport">年报</Radio.Button>
                                <Radio.Button><a href={globalConfig.context + "/admin/servicesManage/highTechInfo.html?uid=" + this.props.data.uid} target="_blank">高企信息导出</a></Radio.Button>
                            </Radio.Group>
                        </div>
                    </div>
                    <div className="content-desc">
                        <this.state.component data={this.props.data} />
                    </div>
                </div>
            )
        } else {
            return (
                <div></div>
            )
        }
    }
});

export default Content;