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 'paiDan': //派单管理
                require.ensure([], () => {
                    let Module = require('./distribute/paiDan').default;
                    this.setState({
                        component: <Module />,
                    });
                });
                break;
			case 'invoiceApplyList': //省内开票管理
			    require.ensure([], () => {
			        let Module = require('./distribute/invoiceApplyList').default;
			        this.setState({
			            component: <Module />,
			        });
			    });
			    break;
			case 'invoiceApplyListWai': //省外开票管理
			    require.ensure([], () => {
			        let Module = require('./distribute/invoiceApplyListWai').default;
			        this.setState({
			            component: <Module />,
			        });
			    });
			    break;	
			case 'inSpecial': //省内特批
			    require.ensure([], () => {
			        let Module = require('./distribute/inSpecial').default;
			        this.setState({
			            component: <Module />,
			        });
			    });
			    break;
			case 'outSpecial': //省外特批
			    require.ensure([], () => {
			        let Module = require('./distribute/outSpecial').default;
			        this.setState({
			            component: <Module />,
			        });
			    });
			    break;	
            case 'shouKuang': //收款管理
                require.ensure([], () => {
                    let Module = require('./distribute/shouKuang').default;
                    this.setState({
                        component: <Module />,
                    });
                });
                break;
            case 'tuiDan': //退单管理
                require.ensure([], () => {
                    let Module = require('./distribute/tuiDan').default;
                    this.setState({
                        component: <Module />,
                    });
                });
                break;    
            case 'myWater': //我的订单流水
                require.ensure([], () => {
                    let Module = require('./flowWater/myWater').default;
                    this.setState({
                        component: <Module />,
                    });
                });
                break;   
            case 'departWater': //部门订单流水
                require.ensure([], () => {
                    let Module = require('./flowWater/departWater').default;
                    this.setState({
                        component: <Module />,
                    });
                });
                break;     
            case 'yxBonus': //营销员奖金
                require.ensure([], () => {
                    let Module = require('./bonus/yxBonus').default;
                    this.setState({
                        component: <Module />,
                    });
                });
                break;   
            case 'jsBonus': //技术员奖金
                require.ensure([], () => {
                    let Module = require('./bonus/jsBonus').default;
                    this.setState({
                        component: <Module />,
                    });
                });
                break;          
            case 'order': //技术员奖金
                require.ensure([], () => {
                    let Module = require('../statistics/order/index').default;
                    this.setState({
                        component: <Module />,
                    });
                });
                break;          
            default:
            require.ensure([], () => {
                let 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;
