import styles from './index.less'
import small from '../img/small.png'
import EmergencyPart from '../EmergencyPart'
import ImgView from '../ImgView'
import pic from '../img/pic.png'
import pic1 from '../img/pic1.png'
import pic2 from '../img/pic2.png'
import pic3 from '../img/pic3.png'
import pic4 from '../img/pic4.png'
import pic5 from '../img/pic5.png'
import $ from 'jquery'
import { dragBox } from '@utils/drag';
import close from '@common/images/icon_close.png';
import {windowEventHandler} from '@utils/tools';
let a = 0
class EmergencyModal extends React.Component{
  constructor(props){
    super(props)
    this.state={
      show:false,
      imgShow:false,
      diseaseName:[
        '','心包积液','气胸','肺栓塞','急性冠脉综合征','主动脉夹层'
      ]
    }
    this.handleImgShow=this.handleImgShow.bind(this)
  }
  componentDidMount() {
    $(document).click((event) => {
      let modalTopR = document.getElementById("modalTopR")
      let nameLis = document.getElementById("nameLis")
      if (nameLis) {
        if (modalTopR != event.target && !nameLis.contains(event.target)) {
          this.setState({ show: false });
        }
      }
    });
    // const {windowHeight} = this.props;
    // windowEventHandler('resize', ()=>{
    //   $("#preImg").css("height",(windowHeight-120)+'px')
    // });
  }
  handleSlideShow(){
    let flg = this.state.show
    this.setState({show:!flg})
  }
  setDataIdx(num,flg){
    this.setState({show:flg})
    this.props.setDataIdx(num)
  }
  handleImgShow(flg){
    this.setState({imgShow:flg},()=>{
      if(flg){
        dragBox('dragModalWrap','dragModalTitle','add',false,true)
      }else{
        dragBox('dragModalWrap','dragModalTitle','del',false,false)
      }
    })
  }
  render(){
    const {data,handleShow,setDataIdx,idx,show} = this.props;
    return <div className={styles.emergencyProdure} style={{display:show?'block':'none'}}>
      <div className={`${styles.modalTop} clearfix`}>
          <div className={styles.modalTopL}>
            <img className={styles.imgs} onClick={()=>handleShow(false)} src={small} alt=""/>
            <p className="ellipsOver">{data.emergencyname}</p>
            {
              idx == 0?null:<img className={styles.imgs} src={pic} onClick={()=>{this.handleImgShow(true)}} alt=""/>
            }
            {
              this.state.imgShow?<ImgView name={data.emergencyname} idx={idx} handleImgShow={this.handleImgShow}></ImgView>:null
            }
          </div>
          <div className={styles.modalTopR} onClick={()=>{this.handleSlideShow()}} id="modalTopR">其他危重症状</div>
          {
            this.state.show?<ul className={styles.nameLis} id="nameLis">
              <i></i>
              {
                this.state.diseaseName.map((item,index)=>{
                  return <li className={idx == index?styles.selectColor:null} style={{display:item?'inline-block':'none'}} onClick={()=>{this.setDataIdx(index,false)}}>
                    {item}
                  </li>
                })
              }
            </ul>:null
          }
      </div>
      <div className={styles.modalMain}>
        <div className={styles.part}>
          <EmergencyPart idx={idx} setDataIdx={setDataIdx} data={data}></EmergencyPart>
        </div>
      </div>
    </div>
  }
}

export default EmergencyModal;