import React from 'react'
import {
    inject,
    observer
} from 'mobx-react'
import {
    WeaAlertPage,
    WeaLocaleProvider
} from 'ecCom'
import {
    Spin
} from 'antd'

import Top from './Top';
import MainDialog from './MainDialog';
const getLabel = WeaLocaleProvider.getLabel;

@inject('hrmStaffPayrollSummary')
@observer
export default class StaffPayrollSummary extends React.Component {
    constructor(props) {
        super(props);
    }

    componentWillMount() {
        if (window.location.href.indexOf('/spa/hrm/engine.html') > -1) {
            document.title = getLabel('391167', "人员工资汇总");
        }
    }

    componentWillReceiveProps(nextProps) {
        if (this.props.location && (this.props.location.key !== nextProps.location.key)) {
            this.props.hrmStaffPayrollSummary.refresh();
        }
    }

    componentDidMount() {
        this.init();
    }

    init() {
        const {
            hrmStaffPayrollSummary
        } = this.props, {
            getAuth,
        } = hrmStaffPayrollSummary;

        getAuth();
    }

    render() {
        const {
            hrmStaffPayrollSummary
        } = this.props, {
            main,
        } = hrmStaffPayrollSummary, {
            loading,
            authorized
        } = main;

        if (!authorized) {
            return (
                <div style={{height: '100%'}}>
                    {loading ?  <div className='hrm-loading-center'>
                                    <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@61j27d`} spinning={loading} size='large'></Spin>
                                </div>
                             :  <div className="hrm-wea-alert-page">
                                    <WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@vsi7k9`}>
                                        <div style={{ color: '#000' }}>
                                            {getLabel(2012, '对不起，您暂时没有权限！')}
                                        </div>
                                      </WeaAlertPage>
                                </div>
                    }    
                </div>
            )
        } else {
            return (
                <div>
                    <Top ecId={`${this && this.props && this.props.ecId || ''}_Top@35ae65`} />
                    <MainDialog ecId={`${this && this.props && this.props.ecId || ''}_MainDialog@9q0g5t`} />
                </div>
            )
        }
    }
}