import React, { Component } from "react";
import style from "../index.less";
import deleteIcon from '@common/images/delete.png';
/**
 * 来源于页面选择
 *
 * **/
class ScaleItem extends Component {
  constructor(props) {
    super(props);
    this.state={
      supplement:''
    };
    this.getItems = this.getItems.bind(this);
    this.getDetailItems = this.getDetailItems.bind(this);
  }
  getDetailItems(item,i){
    let arr = [],temp='';
    const {indexs} = this.props;
    item.details.map((it,j)=>{
      if(indexs[i]&&indexs[i].includes(j)){
        if(it.type==1){     //量表
          temp =<span className={style['scale']}>【{it.content.name}】</span>;
        }else if(it.type==2){      //计算公式
          temp = <span>计算公式</span>
        }else if(it.type==3){
          temp = <span>可能结果</span>
        }
        arr.push(<li>
          <span>{item.name}：</span>
          <div className={style['row']}>{temp}</div>
          <div className={style["recommend"]} onClick={()=>this.props.handleRemove(i,j)}>
            <img src={deleteIcon} />
          </div>
        </li>);
      }
    });
    return arr;
  }
  getItems(){
    const { data } = this.props;
    return data.map((it,i)=>{
      return this.getDetailItems(it,i);
    });
  }
  render() {
    const {title,handleInp} = this.props;
    return <div className={style['assess-item']}>
      <h2>{title}</h2>
      <div className={style['item-content']}>
        <ul>
          {
            this.getItems()
          }
          <li>
            <textarea className={style['edit-row']} name="supplement" rows="6" placeholder='评估描述' onInput={(e)=>handleInp(e.target.value)}></textarea>
          </li>
        </ul>
      </div>
    </div>;
  }
}

export default ScaleItem;