import React from 'react';
import { ItemBox, ConfirmModal, WrapModalContainer } from '@commonComp';
import AddNewInspect from '../AddNewInspect';
import styles from './index.less';
import $ from 'jquery';
import { isIE } from '@utils/tools.js';
import { dragBox } from '@utils/drag';

class NewAdvice extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      val: '',
      visible: false,
      dom: [],
      isIE: isIE(),
      ieVersion: null,
      height: '-1',
      hide: false,
      importLis:false
    }
    this.cancel = this.cancel.bind(this);
    this.onClose = this.onClose.bind(this);
    this.refreshScroller = this.refreshScroller.bind(this);
  }  
  componentDidMount() {
    $(document).click((event) => {
      let searchWrap = $('#importInspectBtn')[0];   // 导入按钮按钮
      let searchOption = $('#importList')[0];   // 下拉列表
      if (searchOption&&$('#importList').css("display")=="block") {
        if(searchWrap != event.target){
          this.setState({ importLis: false });
        }
      }
    });
    this.props.setContext(this.context)
  }
  cancel() {
    this.setState({ visible: false })
  }
  onClose() {
    this.setState({
      hide: false
    })
    dragBox('previewWrapper', 'previewStatic', 'del')
  }
  refreshScroller(){
    //滚动条对象
    return this.context.scrollArea;
    /*this.context.scrollArea.refresh();
    this.context.scrollArea.scrollBottom();*/

  }
  render() {
    const {handleSuiFang,hosId,hideAllDrop,staticData,activeIdx,selectJiType,handleSelectShow,setHighter,labelListBig, fetchPushInfos,getInfomation,labelListSmall, hospitalMsg, inspectVal, windowHeight, windowWidth,setTipValue, handleCloseExcel, handleChangeValue, labelListActive, list, handleSign, labelList, handleLabelSub, handleClear, handleConfirm, fillActive, changeActivePart, getExcelDataList, delPartItem, inspectList,detailClick,handleDelConfirm,checkOnOff ,labelListBlood} = this.props;

    return (
      <div className={styles.wrapper}>
        {/* 导入功能插件，ie8/9权限问题暂未解决，先隐藏 */}
        <div className={styles.top}>
          <span id="inspectResultData" className={styles.newAdviceTitle}> </span>
        </div>
        <ItemBox
          hideAllDrop={hideAllDrop}
          className={styles.title}
          title={'医嘱'}
          editable={false}
          border={true}
          marginTop={'0px'}
        >
          <div style={{ padding: '0px 10px 10px 10px', boxSizing: 'border-box',color:'#000' }} >
            <AddNewInspect
              activeIdx={activeIdx}
              hosId={hosId}
              handleSuiFang={handleSuiFang}
              handleSelectShow={handleSelectShow}
              selectJiType={selectJiType}
              checkOnOff={checkOnOff}
              staticData={staticData}
              handleDelConfirm={handleDelConfirm}
              labelListBig={labelListBig}
              labelListSmall={labelListSmall}
              labelListBlood={labelListBlood}
              handleSign={handleSign}
              setHighter={setHighter}
              refreshScroller={this.refreshScroller}
              handleChangeValue={handleChangeValue}
              list={list}
              handlePush={fetchPushInfos}
              detailClick={detailClick}
              labelList={labelList}
              handleLabelSub={handleLabelSub}
              fillActive={fillActive}
              handleClear={handleClear}
              handleConfirm={handleConfirm}
              changeActivePart={changeActivePart}
              getExcelDataList={getExcelDataList}
              handleCloseExcel={handleCloseExcel}
              labelListActive={labelListActive}
              delPartItem={delPartItem}
              inspectList={inspectList}
              getInfomation={getInfomation}
              inspectVal={inspectVal}
              windowHeight={windowHeight}
              windowWidth={windowWidth}
              setTipValue={setTipValue}
            >
            </AddNewInspect>
          </div>
        </ItemBox>
        <ConfirmModal visible={this.state.visible}
          okText='删除'
          cancelText='确定'
          width="450"
          height={(this.state.height > 2 && this.state.height < 8) ? ((this.state.height * 30 + 120) + 'px') : this.state.height > 8 ? '350px' : '200px'}
          noFooter={true}
          close={this.cancel}>
          <ul className={styles.excelList}>
            {
              this.state.dom.length > 0 && this.state.dom.map((val) => {
                return <li className={styles.excelListWaring}>
                  {val}
                </li>
              })
            }
          </ul>
          <div onClick={this.cancel} className={styles.confirmBtn}>确定</div>
        </ConfirmModal>
      </div>
    )
  }
}

NewAdvice.contextTypes = {
  scrollArea: React.PropTypes.object
};
export default NewAdvice;