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 = ''

    // advice.assay.forEach((item, index) => {
    //   if(index === advice.assay.length - 1){
    //     billing = billing + (index + 1) + '：' + item + '；'
    //   }else{
    //     billing = billing + (index + 1) + '：' + item + '，'
    //   }
    // })

    // advice.check.forEach((item, index) => {
    //   if(index === advice.check.length - 1){
    //     billing = billing + (index + 1) + '：' + item + '；'
    //   }else{
    //     billing = billing + (index + 1) + '：' + item + '，'
    //   }
    // })

    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}>
        <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>}
          {/* {billing} */}
        </div>
        <div className={style['scheme']}>
          {advice.scheme && advice.scheme.length > 0  && <h1>治疗方案</h1>}
          {scheme}
        </div>
      </ItemBox>
    </div>
  }
}

export default Advice;