import React, { Component } from "react";
import style from "./index.less";
import config from '@config/index';
import $ from 'jquery';

class Textarea extends Component {
  constructor(props) {
    super(props);
    this.state = {
      timer:null,
      val:'报告描述或意见'
    };
    this.textInput = React.createRef();
    this.$dom = React.createRef();
    this.$domW = React.createRef();
    this.handleInput = this.handleInput.bind(this);
  }
  handleInput(e){
    e.stopPropagation();
    const {handleChangeAssistValue,idx,handlePush} = this.props;
    const text = e.target.innerText || e.target.innerHTML;
    const stimer = this.state.timer;
    handleChangeAssistValue&&handleChangeAssistValue(text);
   
  }
  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
    //   next.value ? this.$dom.current.innerText = next.value :  this.$dom.current.innerText = next.value 
    //   // this.$dom.current.innerText?(this.$dom.current.innerText = next.value||''):(this.$dom.current.innerHTML = next.value||'');
    // }
    if(next.isRead != isRead && next.value || next.isRead != isRead && next.value!=this.props.value){      //value对比解决复诊不显示bug
      next.value ? this.$dom.current.innerText = next.value :  this.$dom.current.innerText = '' 
      // this.$dom.current.innerText?(this.$dom.current.innerText = next.value||''):(this.$dom.current.innerHTML = next.value||'');
    }
  }
  componentDidMount(){
    const {value} = this.props;
    if(value && value.trim()){
      this.$dom.current.innerText = value
      // this.$dom.current.focus()
      // this.$dom.current.innerText ? (this.$dom.current.innerText = value) : (this.$dom.current.innerHTML = value)
    //   this.$dom.current.nextSibling.innerText?(this.$dom.current.nextSibling.innerText = ''):(this.$dom.current.nextSibling.innerHTML = '')
    }
  }
 
  render() {
    return (
      <div>
        <div 
            style={{outline: 'none'}}
            contenteditable={true}
            ref={this.$dom}
            onInput={this.handleInput}
            onKeyUp={this.handleInput}
        ></div>
      </div>
    );
  }
}
export default Textarea;
