import '../../../style/annual.less';
import React, {
	Component
} from 'react';
import {
	inject,
	observer
} from 'mobx-react';
import {
	WeaTop,
	WeaAlertPage,
	WeaRightMenu,
	WeaLeftRightLayout
} from 'ecCom';
import OrganizationTree from '../../../coms/OrganizationTree';
import DataList from './DataList';
import {
	i18n
} from '../../../public/i18n';

@inject('hrmAnnualRule')

@observer
export default class AnnualRule extends Component {
	constructor(props) {
		super(props);
	}

	componentDidMount() {
		this.init();
	}

	componentWillReceiveProps(nextProps) {
		if (this.props.location.key !== nextProps.location.key) {
			this.init();
			this.refs.orgTree && this.refs.orgTree.refs.tree.fetchData();
		}
	}

	init = () => {
		const {
			hrmAnnualRule: store
		} = this.props;
		const {
			checkAuthorized,
			initData
		} = store;
		checkAuthorized('annualmanager', {
			type: 'AnnualBatch'
		}, initData);
	}

	render() {
		const {
			hrmAnnualRule: store
		} = this.props;
		const {
			containerInitFinished,
			topBtnAndMenu,
			orgTreeProps,
			selectedSubCompany
		} = store;
		const {
			btns,
			menus
		} = topBtnAndMenu();
		let title = i18n.module.annualRule();
		if (selectedSubCompany != null && selectedSubCompany.name)
			title = `${title} - ${selectedSubCompany.name}`;
		const topProps = {
			title,
			icon: <i className='icon-coms-hrm'/>,
			iconBgcolor: '#217346',
			showDropIcon: true,
			buttons: btns,
			dropMenuDatas: menus
		}
		return (
			<div className="hrm_module_container">
			{
				containerInitFinished.init && containerInitFinished.authorized &&
				<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@ipdeyf`} {...topProps}>
					<WeaLeftRightLayout ecId={`${this && this.props && this.props.ecId || ''}_WeaLeftRightLayout@1kkdnp`} leftCom={<OrganizationTree ecId={`${this && this.props && this.props.ecId || ''}_OrganizationTree@y126t0`} {...orgTreeProps} ref='orgTree'/>}>
						<DataList ecId={`${this && this.props && this.props.ecId || ''}_DataList@m16ni1`} store={store} rightMenu={menus}/>
					</WeaLeftRightLayout>
				</WeaTop>
			}
			{
				containerInitFinished.init && !containerInitFinished.authorized && 
              	<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@pf1f3x`}>
                  	<div style={{ color: '#000' }}>{i18n.message.authFailed()}</div>
              	</WeaAlertPage>
			}
			</div>
		)
	}
}