import React from 'react';
import AddAssistCheck from '../AddAssistCheck';
import { ItemBox, ConfirmModal, WrapModalContainer } from '@commonComp';
import styles from './index.less';
import Notify from '@commonComp/Notify';
import $ from 'jquery';
import { isIE, getUrlArgObject } from '@utils/tools.js';
import { dragBox } from '@utils/drag';
import WrapModalBodyPac from '@containers/WrapModalBodyPac';
import { getExcelList } from '@store/actions/inspect';
import { host, prefix } from '@utils/config.js';


class AssistCheck extends React.Component {
  constructor(props){
        super(props);
        this.state={
          val: '',
          visible: false,
          dom: [],
          isIE: isIE(),
          ieVersion: null,
          height: '-1',
          hide: false,
          importLis:false
        }
        this.showSlideImport=this.showSlideImport.bind(this)
        // this.handleBindFileApi=this.handleBindFileApi.bind(this)
        this.checkSystemIpt=this.checkSystemIpt.bind(this)
        this.closeInIcss=this.closeInIcss.bind(this)
        this.onClose=this.onClose.bind(this)
        this.handleImportExcel=this.handleImportExcel.bind(this)
    this.refreshScroller = this.refreshScroller.bind(this);
    }
    handleImportExcel() {
      this.inputRef.click();
    }
    showSlideImport(){
      let flg = this.state.importLis
      this.setState({
        importLis:!flg
      })
    }

    onClose() {
      this.setState({
        hide: false
      })
      dragBox('previewWrapper', 'previewStatic', 'del')
    }
    checkSystemIpt() {
      this.setState({
        hide: true
      })
    }
    closeInIcss(){
      this.setState({
        hide: false
      })
    }
  refreshScroller(){
    //更新滚动条状态，解决容器变大滚动条不更新bug
    return this.context.scrollArea;
    //this.context.scrollArea.scrollBottom();

  }
    render(){
        const {setHighter,checkedListImport,list,getInfomation,windowHeight,hospitalMsg,assistLabel,assistVal,handleChangeValue,handleSign,fetchPushInfos,handleDelAssist,handleChangeAssistValue,handleChangeDate,isRead,winWidth,assistList} = this.props;
        const {showSlideImport,checkSystemIpt,onClose,closeInIcss} = this;
        const {importLis,ieVersion,hide} = this.state;
        // if(JSON.stringify(hospitalMsg) != {} && document.getElementById("choose")){//动态绑定只绑定一次
        //   ++numFlg
        //   numFlg == 1?handleBindFileApi():null
        // }
        return (
            <div className={styles.wrapper}>
                <div className={styles.top}>
                    <span id="assistResultData">辅检结果数据</span>
                    {/* <div className={styles.pushButton} disabled={ieVersion && ieVersion > 9 ? true : false} onClick={checkSystemIpt}>
                        <p id="importPacBtn" className={styles.importInspectBtn}>导入辅检结果</p>
                    </div> */}
                    {
                      hospitalMsg.import_way_pacs == 1 ? <div className={styles.pushButton} disabled={ieVersion && ieVersion > 9 ? true : false} onClick={ieVersion && ieVersion <= 9 ? null : this.handleImportExcel}>
                        <p className={styles.importInspectBtn}>导入辅检结果</p>
                        <input type="file" name="uploadfile" id="choose" style={{ display: 'none' }} ref={(DOM) => this.inputRef = DOM} />
                      </div> : hospitalMsg.import_way_pacs == 2 ? <div className={styles.pushButton} disabled={ieVersion && ieVersion > 9 ? true : false} onClick={checkSystemIpt}>
                        <p className={styles.importInspectBtn}>导入辅检结果</p>
                      </div> : hospitalMsg.import_way_pacs == 3 ? <div className={`${styles.pushButton} ${styles.importInspect}`} onClick={showSlideImport}>
                        <p id="importExcelBtns" className={styles.importInspectBtn}>导入辅检结果</p>
                        {
                          importLis?<ul className={styles.importSelect} id="importExcelLists">
                            <li className={styles.excelIpt}>
                              <div onClick={ieVersion && ieVersion <= 9 ? null : this.handleImportExcel}>本地导入</div>
                              <input type="file" name="uploadfile" id="choose" style={{ display: 'none' }} ref={(DOM) => this.inputRef = DOM} />
                            </li>
                            <li className={`${styles.excelIpt} ${styles.systemIpt}`} onClick={checkSystemIpt}>从设备导入</li>
                          </ul>:null
                        }
                          </div> : null
                      }
                    {
                      hide ? <WrapModalContainer hide={hide} title={'导入辅检数据'} width={1000} height={580} onClose={onClose}>
                        <WrapModalBodyPac
                          closeInIcss={closeInIcss}
                          height={580}
                        ></WrapModalBodyPac>
                      </WrapModalContainer> : null
                    }
                </div>
                <ItemBox 
                    className={styles.title}
                    title={'辅检'}
                    editable={false}
                    border={true}
                    marginTop={'20px'}
                >
                    <div style={{padding:'10px',boxSizing:'border-box'}} >
                        <AddAssistCheck 
                            handleChangeValue={handleChangeValue}
                            refreshScroller={this.refreshScroller}
                            list={list}
                            handleSign={handleSign}
                            assistLabel={assistLabel}
                            handleDelAssist={handleDelAssist}
                            handlePush={fetchPushInfos}
                            handleChangeAssistValue={handleChangeAssistValue}
                            handleChangeDate={handleChangeDate}
                            isRead={isRead}
                            winWidth={winWidth}
                            getInfomation={getInfomation}
                            assistList={assistList}
                            assistVal={assistVal}
                            windowHeight={windowHeight}
                            checkedListImport={checkedListImport}
                            setHighter={setHighter}
                        >
                        </AddAssistCheck>
                    </div>
                </ItemBox>
            </div>
        )
    }
}

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