/**
 * 公共组件弹框
 */
import React from 'react';
import { Modal } from 'antd';
import { Util } from 'tools/index';
import asyncComponent from '../../../routers/AsyncComponent.js';
import '../style/index.less';

class ShowComponentModal extends React.Component {
  constructor(props) {
    super(props);
    var userData = JSON.parse(sessionStorage.getItem('userData'));
    this.state = {
      userData: userData,
    }
  }

  componentWillReceiveProps(nextProp) {
    if (nextProp.isShow === true) {
      this.setState({
        component: nextProp.dataSource.component
      })
    } else if (this.props.isShow === false) {

    }
  }

  closeModal = () => {
    this.props.onHide && this.props.onHide();
  }

  // OperationApply - 手术申请样式特殊处理
  render() {
    var { dataSource } = this.props;
    const { component } = this.state;
    const Component = asyncComponent(() => import('../../../' + component));
    return (
      <div>
        <Modal
          width={component && component.indexOf('nurse/operation/OperationApply') > -1 ? '96vw' : '1500px'}
          bodyStyle={{
            height: component && component.indexOf('nurse/operation/OperationApply') > -1 ? '82vh' : 'auto',
            padding: 0
          }}
          style={{ top: component && component.indexOf('nurse/operation/OperationApply') > -1 ? '76px' : '100px' }}
          className={component && component.indexOf('nurse/operation/OperationApply') > -1 ? '' : 'out-component-modal'}
          title={this.state.userData.language == 'EN' ? (!Util.isEmpty(dataSource) && dataSource.ENDesc ? dataSource.ENDesc : (!Util.isEmpty(dataSource) ? dataSource.title : '')) : !Util.isEmpty(dataSource) ? dataSource.title : ''}
          maskClosable={false}
          visible={this.props.isShow}
          onCancel={this.closeModal}
          footer={null}
        >
          <Component modal="1" isDoctorAdviceGrap="N" handleClose={this.closeModal} />
        </Modal>
      </div>
    )
  }
}

export default ShowComponentModal;