/**
 * 徐立
 * 2019年9月16日
 * Modal定制样式
 */
import React, {Component} from 'react';
import {Modal, Button} from 'antd';

import styles from './index.less';
import {getContainer} from "@/webPublic/one_stop_public/utils/utils";

export default class WebModal extends Component {
  constructor(props) {
    super(props);
    this.state = {
      top: 0,
    };
  }

  /**
   * 钟是志
   * 2020年4月22日 17:07:53
   * 修改Iframe打开弹窗的时候 弹窗定位错误的bug
   * */
  componentDidMount() {
    setTimeout(() => {
      let dom = document.getElementById('detailInfoDiv');
      if (dom && dom.offsetHeight) {
        let height = dom.offsetHeight;
        if (height > 700) {
          this.setState({
            top: height - 700,
          });
        }
        //  console.log(height, 'Iframe页面的高度');
      }
    }, 1500);
  }

  render() {
    let {visible, handleCancel, title, width} = this.props;
    const {top} = this.state;
    const style = {
      borderRadius: 4,
    };
    if (top) {
      style.top = top;
    }
    let dom = document.getElementsByClassName('antd-pro-web-public-one_stop_public-affair-button-audit-button-user-table-styles-btn_page');
    if(dom && dom.length){
      dom = dom[0];
    }
    return (
        <Modal
          closable={false}
          visible={visible}
          footer={null}
          getContainer={() => {
            return getContainer(dom);
          }}
          destroyOnClose={true}
          width={!!width ? width : 800}
          handleCancel={handleCancel}
          style={style}>
          <div className={styles.content_div}>
            <div className={styles.title}>
              {title}
              <Button className={styles.button} onClick={handleCancel}>
                X
              </Button>
            </div>
            {this.props.children}
          </div>
        </Modal>
    );
  }
}
