import React,{Component} from 'react';
import style from './index.less';
import {ItemBox} from '@commonComp';
import Textarea from './Textarea';
import FollowUp from '@components/Treat/FollowUp'

class Advice extends Component{
  constructor(props){
    super(props);

    this.treatInput = React.createRef();
    this.assayRef = React.createRef();
    this.checkRef = React.createRef();
    this.adviceInputRef = React.createRef();
    this.handleTreatInput = this.handleTreatInput.bind(this);
    this.handleAssayInput = this.handleAssayInput.bind(this);
    this.handleCheckInput = this.handleCheckInput.bind(this);
    this.handleComTreatInput = this.handleComTreatInput.bind(this);
    this.handleAdviceInput = this.handleAdviceInput.bind(this);
  }

  shouldComponentUpdate(next){
    if(JSON.stringify(next) == JSON.stringify(this.props)){
      return false;
    }
    return true;
  }
  componentWillReceiveProps(next){
    const isRead = this.props.isRead;
    // if(next.isRead != isRead||next.value!=this.props.value){      //value对比解决复诊不显示bug
    //   this.adviceInputRef.current.innerText?(this.adviceInputRef.current.innerText = next.value||''):(this.adviceInputRef.current.innerHTML = next.value||'');
    // }
  }
  handleTreatInput(e, index, ii) {
    const {advice} = this.props.pushMessage;
    const changeInput = e.target.value //改变的同类药的值
    const { setChangeAdviceTreatment } = this.props;
    setChangeAdviceTreatment && setChangeAdviceTreatment(index, ii, changeInput)
  }

  handleAssayInput(e) {
    const changeInput = e.target.value
    const { setChangeAdviceAssay } = this.props;
    setChangeAdviceAssay && setChangeAdviceAssay(changeInput)
  }
  handleCheckInput(e) {
    const changeInput = e.target.value
    const { setChangeAdviceCheck } = this.props;
    setChangeAdviceCheck && setChangeAdviceCheck(changeInput)
  }
  handleComTreatInput(text) {
    const { comTreatChange } = this.props;
    comTreatChange && comTreatChange(text)

  }
  handleAdviceInput(text) {
    const { adviceInputChange } = this.props;
    adviceInputChange && adviceInputChange(text)

  }
  componentDidMount(){
  //   this.$dom.current.nextSibling.innerText?(this.$dom.current.nextSibling.innerText = ''):(this.$dom.current.nextSibling.innerHTML = '')
  // const {advice} = this.props.pushMessage.advice
  
}

  render(){
    const {advice} = this.props.pushMessage;
    const {isRead, isFirstMainDiag, followUp, hasFollowUp, saveFollowUp} = this.props
    let scheme = advice.scheme && advice.scheme.map((item, index) => {
      return <p>{item.treatment.map((it,ii) =>{
        return(it.treatmentStr && it.treatmentStr.length > 0 ? 
          <div>
            { it.treatmentStr }
            {/* <input className={style['treat-input']} ref={this.treatInput} onInput={(e)=>{this.handleTreatInput(e, index, ii)}} type='text' value={ it.treatmentStr }/>  */}
          </div>: '') 

        // return <div>{it.drugs.length > 0 ? it.name : ''}: {it.drugs.map((drug, drugIndex) =>{
        //   return(<span>{drug.selected ? (drugIndex === 0 ? drug.name : '  ' + drug.name) : ''}</span>)
        // })}</div>
      })}</p>
    })

    return  <div className={`${'mainsuit-box'} ${style['main-suit']}`}>
      <ItemBox title='医嘱' editable={false} border={true} marginTop="10px">
        <div className={style['billing']}>
          {advice.assay && advice.assay.length > 0 || advice.check && advice.check.length > 0 ? <h1>开单项目</h1> : ''}
            {advice.assay && <span className={style['treat-input']}> {advice.assay}</span>}
            {advice.check && <span className={style['treat-input']}> {advice.check}</span>}
        </div>
        {advice.commontreatment && advice.commontreatment.length > 0 &&<div className={style['billing']}  >
          {advice.commontreatment && advice.commontreatment.length > 0 && <h1>一般治疗</h1>}
            {/* {advice.commontreatment && <div className={style['treat-input']}  onInput={this.handleComTreatInput}  contentEditable={true} style = {{outline: 'none'}}></div>} */}
            {<Textarea value={advice.commontreatment} isRead={isRead} handleChangeAssistValue={this.handleComTreatInput} ></Textarea>}
        </div>}
        {!isFirstMainDiag && followUp &&<div><FollowUp  noHeader="true" textStyle={{padding: '0 10px'}}  setFollowUp={saveFollowUp} followUp = {followUp} isRead={isRead}></FollowUp></div>}
        {advice.scheme && advice.scheme.length > 0 &&<div contentEditable='false' className={style['scheme']}>
          {advice.scheme && advice.scheme.length > 0  && <h1>治疗方案</h1>}
          {scheme}
        </div>}
        <div className={style['billing']} > 
            {/* {!advice.adviceInput && <Textarea value='' isRead={isRead} handleChangeAssistValue={this.handleAdviceInput} ></Textarea>}
            {advice.adviceInput && <Textarea value={advice.adviceInput} isRead={isRead} handleChangeAssistValue={this.handleAdviceInput} ></Textarea>} */}
            <Textarea value={advice.adviceInput} isRead={isRead} handleChangeAssistValue={this.handleAdviceInput} ></Textarea>
        </div>
      </ItemBox>
    </div>
  }
}

export default Advice;