import React from 'react';
import { connect } from 'dva';
import {  Modal } from 'antd';


class EditRowShowModal extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      visible:false,
      showData:{},
    };
  };
  componentDidMount() {

  }

  handleClick=()=>{
    let obj=null;
    const click = this.props.data.click;
    if (typeof click === 'function') {
      obj=click();
    }
    if(obj&&obj.isReturn)return;
    this.handleShowModal();
  }

  handleShowModal = () => {
    this.setState({
      visible: true
    });
  };
  handleCloseModal = (p) => {
    let obj=null;
    const close = p?.content?.props?.data?.close;
    if (typeof close === 'function') {
      obj=close();
    }
    if(obj&&obj.isReturn)return;
    this.setState({
      visible: false
    });
  };
  showContent = () => {
    let showData = this.props.data;
    if (showData && showData.content) {
      if (typeof showData.content === 'function') {
        return showData.content();
      }
      return showData.content;
    }
  };
  render() {
    return (
      <div style={{ display: "inline-block" }}>
        <span onClick={this.handleClick}>{this.props.children}</span>
        <Modal
          title={this.props.title ==="新增" ? this.props.title +"-"+this.props.login.currActivatedMenu.NAME+"["+this.props.login.currActivatedMenu.Nav_MenuForm.CODE+"]" : this.props.title}
          visible={this.state.visible}
          onCancel={()=>this.handleCloseModal(this.props.data)}
          maskClosable={false}
          footer={null}
          className='antd-modal-fullscreen'
        >
          {this.showContent()}
        </Modal>
      </div>
    );
  }
}


export default connect()(EditRowShowModal);
