import React, {
	Component
} from 'react';
import {
	inject,
	observer
} from 'mobx-react';
import {
	Spin
} from 'antd';
import {
	WeaAlertPage,
	WeaLocaleProvider,
} from 'ecCom';
import Header from './Header';
const getLabel = WeaLocaleProvider.getLabel;

@inject('orgFieldDisplaySetting')
@observer
export default class OrgFieldDisplaySetting extends Component {
	constructor(props) {
		super(props);
	}

	componentWillReceiveProps(nextProps) {
		if (this.props.location.key !== nextProps.location.key) {
			this.init();
		}
	}

	componentDidMount() {
		this.init();
	}

	init = () => {
		const {
			orgFieldDisplaySetting: store
		} = this.props, {
			callPermissionApi,
			callRightMenuApi,
			callFormApi
		} = store;

		const callback = () => {
			callRightMenuApi();
			callFormApi();
		}
		callPermissionApi(callback);
	}

	render() {
		const {
			orgFieldDisplaySetting: store
		} = this.props, {
			permission,
		} = store, {
			hasRight,
			loading
		} = permission;

		const style = {
			position: 'absolute',
			top: '50%',
			left: '50%',
			marginLeft: -16,
			marginTop: -16,
		}

		if (!hasRight) {
			if (loading) {
				return (
					<div style={style}>
						<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@g5a5ot`} spinning={true} size='large'></Spin>
					</div>
				)
			} else {
				return (
					<div style={{height:'100%'}}>
		                <WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@tgx9b6`}>
		                    <div style={{ color: '#000' }}>
		                        {getLabel(2012, '对不起，您暂时没有权限！')}
		                    </div>
		                </WeaAlertPage>
		            </div>
				)
			}
		}

		return (
			<div>
				<Header ecId={`${this && this.props && this.props.ecId || ''}_Header@m94ags`} store={store}/>
			</div>
		);
	}
}