import React, { Component } from "react";
import style from "./index.less";
import { getStatusImg,getDomUpDown, filterDataArr, filterOtherDataArr,timestampToTime } from '@utils/tools';
import Notify from '@commonComp/Notify';
import Information from '../Information';
import MedicalAdvice from './MedicalAdvice';
import PreviewInspect from './Inspect';
import ItemPart from './ItemPart';
import $ from "jquery";
import AssessResultHis from '@containers/AssessResultHis';
import { dragBox } from '@utils/drag';
import ScrollArea from 'react-scrollbar';
class PreviewBody extends Component {
  constructor(props) {
    super(props)
    this.state = {
      dateTime: "",
    }
    this.getCurrentDate = this.getCurrentDate.bind(this);
    this.onPrint = this.onPrint.bind(this);
    this.$scrollRef = React.createRef();
  }
  componentDidMount() {
    this.getCurrentDate();
    // this.$scrollRef.current.scrollTop = -40
  }
  onPrint() {
    $("#content").jqprint({
      debug: false,
      importCSS: true,
      printContainer: true,
      operaSupport: false,
    });
    this.props.onClose()
  }

  surePrint(jsonStr) {
    // if (filterDataArr(JSON.parse(jsonStr.chief)) == '') {
    //   Notify.info('主诉不能为空');
    //   return false;
    // } else if (!jsonStr.diag || jsonStr.diag.trim().length < 1) {
    //   Notify.info('诊断不能为空');
    //   return false;
    // } else {
    //   this.onPrint();
    //   dragBox('previewPrintWrapper','previewPrintStatic','del')
    //   this.props.save(true)
    // }
  }
  getCurrentDate() {
    let myDate = new Date();
    let year = myDate.getFullYear();       //获取完整的年份(4位,1970-????)
    let mon = myDate.getMonth() - 0 + 1;       //获取当前月份(0-11,0代表1月)
    let day = myDate.getDate();            //获取当前日(1-31)
    let date = year + '-' + (mon < 10 ? '0' + mon : mon) + '-' + (day < 10 ? '0' + day : day);
    this.setState({ dateTime: date })
  }
  showDetails(val) {
    let min = val.minValue, max = val.maxValue, value = val.value, dom = '';
    dom = getDomUpDown(min,max,value)
    if (val.questionDetailList && val.questionDetailList.length > 0) {
      return val.questionDetailList.map((item) => {
        if (val.value == item.name) {
          return <td className={style.assistTableTdSec}><span style={{ color: item.abnormal != '0' ? "red" : null }}>{val.value}</span> {val.labelSuffix}</td>
        }
      })
    } else {
      return <td className={style.assistTableTdSec}>{dom} {val.labelSuffix}</td>
    }
  }

  toTime(time){
    let tmpTim = time.split(',').join('')-0
    if(time && tmpTim.toString() != 'NaN'){
      let date = new Date('1900-01-01');
      let dateTim = date.getTime();
      let times = (tmpTim-2)*24*60*60*1000;
      let result = timestampToTime(dateTim+times).split(' ')[0]
      return result;
    }else{
      return time;
    }
  }
  render() {
    const { show, preInfo, dataJson, dataStr, baseObj, flg ,come,showAssessBtn,showHistoryCases} = this.props;console.log(3,dataStr)
    let other_data={},lis_data={},pas_data={},other_yjs='',access='',adviceData={};
    let isShowSex = baseObj.sex !== 2 ? false : true
    const contStyle = {
      opacity: '0.4',
      right: '0',
      top: '1px',
      zIndex: '15',
      width: '14px',
      background: '#f1f1f1'
    };
    const barStyle = { background: '#777', width: '100%' };
    // if(!come){
    //   other_data = JSON.parse(baseObj.detailList[2].contentJson)
    //   lis_data = JSON.parse(baseObj.detailList[4].contentJson)
    //   pas_data = JSON.parse(baseObj.detailList[5].contentJson)
    //   adviceData = JSON.parse(baseObj.detailList[7].contentJson)
    //   other_yjs = other_data&&other_data.pfix;
    //   access = other_data&&other_data.haveAssess
    // }else{
    //   other_yjs = dataStr.other?filterOtherDataArr(JSON.parse(dataStr.other),dataJson.other):'';
    //   access = dataJson.haveAssess
    //   adviceData=dataJson.advice
    // }
    // const noData = JSON.stringify(preInfo) == '{}';
    return <div className={style['content']} style={{ width: '700px'}} ref={this.$scrollRef}>
      <ScrollArea speed={0.8}
        horizontal={false}
        // stopScrollPropagation={items.length > 6 ? true : false}
        style={{ height: '100%' }}
        onScroll={(value) => { }}
        // className={styles["area"]}
        verticalContainerStyle={contStyle}
        verticalScrollbarStyle={barStyle}
        contentClassName="content">
      <div className={style['contents']} id="content" style={{ margin: "0 auto", maxWidth: "620px" }}>
        {/* <div style={{height:'40px', backgroundColor: 'red', width:'100%'}}></div> */}
        <Information baseObj={baseObj} preInfo={preInfo}></Information>
        <table className={style['infos']}>
          <ItemPart dataStr={dataStr.chief} title={'主诉：'} type={1}></ItemPart>
          <ItemPart dataStr={dataStr.present} title={'现病史：'} type={1}></ItemPart>
          <ItemPart dataStr={dataStr.pastHistory} title={'既往史：'} type={1}></ItemPart>
          <ItemPart dataStr={dataStr.personalHistory} title={'个人史：'} type={1}></ItemPart>
          <ItemPart dataStr={dataStr.familyHistory} title={'家族史：'} type={1}></ItemPart>
          <ItemPart dataStr={dataStr.marriageHistory} title={'婚育史：'} type={1}></ItemPart>
          {isShowSex && <ItemPart dataStr={dataStr.menstruationHistory} title={'月经史：'} type={1}></ItemPart>}          
          <ItemPart dataStr={dataStr.vital} title={'查体：'} type={1}></ItemPart>          
          <PreviewInspect dataJson={dataStr.lis} toTime={this.toTime} dateTime={this.state.dateTime} showDetails={this.showDetailsCopy}></PreviewInspect>
          <ItemPart dataStr={dataStr.pacs} title={'检查：'} type={2}></ItemPart>
          <ItemPart dataStr={dataStr.diag} title={'西医诊断：'} type={2} lastDot={true}></ItemPart>
          <ItemPart dataStr={dataStr.tcmDiag} title={'中医诊断：'} type={2} lastDot={true}></ItemPart>
          <MedicalAdvice advice={dataStr.advice}></MedicalAdvice>
         
        </table>
        <p className={style.docName}>医生签名：<span>{baseObj ? baseObj.doctorName : (noData ? '' : preInfo.doctorName)}</span></p>
        {showAssessBtn&&access?<AssessResultHis showHistoryCases={showHistoryCases} inquiryId={baseObj&&baseObj.id} inquiryDate={baseObj&&baseObj.inquiryDate}></AssessResultHis>:""}
        <div onClick={() => { this.surePrint(dataStr) }} className={style.printBtn} style={{
          display: show ? 'inline-block' : 'none',
        }}>打印</div>
      </div>
      </ScrollArea>
    </div>
  }
}

export default PreviewBody;
