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


class Content extends Component {
    constructor() {
        super();
        this.state = {
            loading: false,
            component: <div></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 'myService':
                require.ensure([], () => {
                    const MyService = require('./myOrder/servicesOrder/myService').default;
                    this.setState({
                        component: <MyService />
                    });
                });
                break;
            case 'orderStatistics':
                require.ensure([], () => {
                    const OrderStatistics = require('./orderStatistics/orderStatistics').default;
                    this.setState({
                        component: <OrderStatistics />
                    });
                });
                break;
            case 'serviceManage':
                require.ensure([], () => {
                    const ServiceManage = require('./departmentOrder/servicesOrder/serviceManage').default;
                    this.setState({
                        component: <ServiceManage />
                    });
                });
                break;
            case 'public':
                require.ensure([], () => {
                    const PublicOrder = require('./orderManagement/publicOrder/publicOrder').default;
                    this.setState({
                        component: <PublicOrder />
                    });
                });
                break;
            case 'approved':
                require.ensure([], () => {
                    const ApproveOrder = require('./orderManagement/approveOrder/approveOrder').default;
                    this.setState({
                        component: <ApproveOrder />
                    });
                });
                break;
            case 'mySettlement':
                require.ensure([], () => {
                    const MySettlement = require('./settlementOrder/mySettlement/mySettlement').default;
                    this.setState({
                        component: <MySettlement />
                    });
                });
                break;    
           	case 'settlementManage':
                require.ensure([], () => {
                    const SettlementManage = require('./settlementOrder/settlementManage/settlementManagement').default;
                    this.setState({
                        component: <SettlementManage />
                    });
                });
                break;
            case 'myBill':
                require.ensure([], () => {
                    const MyBill = require('./flowSettlement/myBill/myBill.jsx').default;
                    this.setState({
                        component: <MyBill />
                    });
                });
                break;    
            case 'billManage':
                require.ensure([], () => {
                    const MyBill = require('./flowSettlement/billManage/myBill.jsx').default;
                    this.setState({
                        component: <MyBill />
                    });
                });
                break; 
            case 'billQuery':
                require.ensure([], () => {
                    const MyBill = require('./flowSettlement/billQuery/myBill.jsx').default;
                    this.setState({
                        component: <MyBill />
                    });
                });
                break; 
            case 'billManagement':
                require.ensure([], () => {
                    const MyBill = require('./flowSettlement/billManagement/myBill.jsx').default;
                    this.setState({
                        component: <MyBill />
                    });
                });
                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}
                </div>
            </div>
        )
    }
}

export default Content;
