import React, { Component } from "react";
import PatInfoContainer from '@containers/PatInfoContainer.js';
import style from "./index.less";
import { connect } from 'react-redux';
import historyCase from '@common/images/history.png';
import health from '@common/images/health.png'
import store from '@store';
import { showHistory } from '@store/actions/historyTemplates';
import { initItemList } from '@store/async-actions/historyTemplates';
import HistoryCases from '@containers/HistoryCases';
import $ from 'jquery';

class InfoTitle extends Component {
    constructor(props){
        super(props);
        this.state={
            le:''
        }
        this.showHistoryBox = this.showHistoryBox.bind(this)
    }
    showHistoryBox(){
        store.dispatch(initItemList());
        store.dispatch(showHistory(true))
    }
    componentWillReceiveProps(next){
        const that = this;
        if(next.winWidth <= 1024){
          $(window).scroll(function(){
            let scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft;
            let left = -(scrollLeft - 10) +'px';
            that.setState({
              le:left
            })
          })
        }
    }
    render() {
        const {disVisible,copyVisible,winWidth} = this.props;
        const {le} = this.state;
        return <div className={style['title-wrapper']} style={{zIndex:disVisible||copyVisible?40:204,left:le}}>
            <PatInfoContainer sizeFlag={winWidth <= 1065?true:false}/>
            <div className={style["operations"]} onClick={this.showHistoryBox}>
                <span><img src={historyCase} />&nbsp;历史病历</span>
            </div>
            <div className={style["health"]} >
                <span><img src={health} />&nbsp;健康档案</span>
            </div>
            <HistoryCases></HistoryCases>
        </div>;
    }
}
function mapStateToProps(state) {
  return {
    disVisible: state.copyRight.disVisible,
    copyVisible:state.copyRight.copyVisible,
    winWidth:state.homePage.windowWidth
  }
}

const InfoTitleCont = connect(
  mapStateToProps,
  null
)(InfoTitle);



export default InfoTitleCont;
