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

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

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

  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) {
    console.log(e.target.value)
    const changeInput = e.target.value
    const { setChangeAdviceAssay } = this.props;
    setChangeAdviceAssay && setChangeAdviceAssay(changeInput)
  }
  handleCheckInput(e) {
    console.log(e.target.value)
    const changeInput = e.target.value
    const { setChangeAdviceCheck } = this.props;
    setChangeAdviceCheck && setChangeAdviceCheck(changeInput)
  }

  render(){
    const {advice} = this.props.pushMessage;
    let billing = ''

    

    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']} contentEditable={true} style = {{outline: 'none'}}>
          {advice.commontreatment && advice.commontreatment.length > 0 && <h1>一般治疗</h1>}
            {advice.commontreatment && <span  className={style['treat-input']}  >{advice.commontreatment} </span>}
        </div>}
        {advice.scheme && advice.scheme.length > 0 &&<div contentEditable='false' className={style['scheme']}>
          {advice.scheme && advice.scheme.length > 0  && <h1>治疗方案</h1>}
          {scheme}
        </div>}
        <div contentEditable={true} style = {{outline: 'none'}}>
          
        </div>
      </ItemBox>
    </div>
  }
}

export default Advice;