import React, { Component } from 'react';
import '../content.less';
import LeftTab from '../leftTab';
import TechDemand from './techDemand';
import {getMenu} from '../publicMenu.js'

class Content extends Component {
    constructor() {
        super();
        this.state = {
            loading: false,
            component: 'div',
        };
    }
    componentWillMount() {
        var ids=window.location.href.indexOf('rid=');
        var idk=window.location.href.substr(ids+4);
        var rid=idk.split('#');
        let menu=getMenu(rid);
        let curry;
		if(menu[0].subMenus.length>0){
        	curry=menu[0].subMenus[0].url.split('#');
        }else{
        	curry=menu[0].url.split('#');
        };
        if (window.location.hash) {
            this.getKey(window.location.hash.substr(1));
        } else {
         this.getKey(curry[1]);
        };
    }
    getKey(key) {
        switch (key) {
        	//管理
            case 'techDemandManage':
                require.ensure([], () => {
                    const TechDemand = require('./techDemand').default;
                    this.setState({
                        component: TechDemand,
                        listApiUrl: '/api/admin/demand/manageList',
                        detailApiUrl: '/api/admin/demand/orgDemandDetail'
                    });
                });
                break;
            //我的
            case 'myTechDemand':
                require.ensure([], () => {
                    const MyTechDemand = require('./myTechDemand').default;
                    this.setState({
                        component: MyTechDemand,
                        listApiUrl: '/api/admin/demand/myList',
                        detailApiUrl: '/api/admin/demand/orgDemandDetail'
                    });
                });
                break;
            //查询
             case 'techDemandQuery':
                require.ensure([], () => {
                    const TechDemandQuery = require('./techDemandQuery').default;
                    this.setState({
                        component: TechDemandQuery,
                        listApiUrl: '/api/admin/demand/orgList',
                        detailApiUrl: '/api/admin/demand/orgDemandDetail'
                    });
                });
                break;
             //四川
            case 'siChuan':
                require.ensure([], () => {
                    const SiChuan = require('./sichuan/sichuan').default;
                    this.setState({
                        component: SiChuan,
                        listApiUrl: '/api/admin/achievement/myList',
                        detailApiUrl: '/api/admin/achievement/orgDetail'
                    });
                });
                break;
             //四川
            case 'siChuanMan':
                require.ensure([], () => {
                    const siChuanMan = require('./sichuan/sichuanman').default;
                    this.setState({
                        component: siChuanMan,
                        listApiUrl: '/api/admin/achievement/myList',
                        detailApiUrl: '/api/admin/achievement/orgDetail'
                    });
                });
                break;
//          case 'userTechDemand':
//              require.ensure([], () => {
//                  const TechDemand = require('./techDemand').default;
//                  this.setState({
//                      component: TechDemand,
//                      listApiUrl: '/api/admin/demand/userList',
//                      detailApiUrl: '/api/admin/demand/userDemandDetail'
//                  });
//              });
//              break;
//          case 'orgDemandOrder':
//              require.ensure([], () => {
//                  const DemandOrder = require('./demandOrder').default;
//                  this.setState({
//                      component: DemandOrder,
//                      listApiUrl: '/api/admin/portal/order/orgDemandOrderList',
//                      detailApiUrl: '/api/admin/demand/orgDemandDetail'
//                  });
//              });
//              break;
//          case 'userDemandOrder':
//              require.ensure([], () => {
//                  const DemandOrder = require('./demandOrder').default;
//                  this.setState({
//                      component: DemandOrder,
//                      listApiUrl: '/api/admin/portal/order/userDemandOrderList',
//                      detailApiUrl: '/api/admin/demand/userDemandDetail'
//                  });
//              });
//              break;
            //需求审核  
            case 'techDemandAudit':
                require.ensure([], () => {
                    const TechDemandPublish = require('./demandAudit/techDemandAudit.jsx').default;
                    this.setState({
                        component: TechDemandPublish,
                        listApiUrl: '/api/admin/portal/order/userDemandOrderList',
                        detailApiUrl: '/api/admin/demand/userDemandDetail'
                    });
                });
                break;
            //需求发布  
            case 'techDemandPublish':
                require.ensure([], () => {
                    const TechDemandPublish = require('./demandRelease/techDemandRelease.jsx').default;
                    this.setState({
                        component: TechDemandPublish,
                        listApiUrl: '/api/admin/portal/order/userDemandOrderList',
                        detailApiUrl: '/api/admin/demand/userDemandDetail'
                    });
                });
                break;
            //需求发布新  
            case 'releaseDemand':
                require.ensure([], () => {
                    const ReleaseDemand = require('./releaseDemand.jsx').default;
                    this.setState({
                        component: ReleaseDemand,
                        listApiUrl: '/api/admin/portal/order/userDemandOrderList',
                        detailApiUrl: '/api/admin/demand/userDemandDetail'
                    });
                });
                break;  
            default:
            require.ensure([], () => {
                const Module = require('../module').default;
                this.setState({
                    component:Module	    
                	});
                });
                
        };
        window.location.hash = key;
    }
    render() {
        return (
            <div className="manage-content">
                <LeftTab handlekey={this.getKey.bind(this)} />
                <div className="content-right">
                    <this.state.component
                        data-listApiUrl={this.state.listApiUrl}
                        data-detailApiUrl={this.state.detailApiUrl} />
                </div>
            </div>
        )
    }
}

export default Content;
