import React from 'react';
import style from './index.less';
// import mocks from '../../mock/chronicTable.js'
import { Radio,CheckBtn ,Notify} from '@commonComp';
 import Information from '../Information';
 import {deepClone} from '@utils/tools.js';
 import {getFormulaResult} from '@store/async-actions/fetchModules.js';
/**
*量表 具体信息页面
*title:量表标题/scaleName
*data:量表内容:scaleName量表标题，calculate量表计算结果，group分组，
*
*
**/
class ScaleTableHis extends React.Component{
  constructor(props){
    super(props);
  }
  filterScale(data){//type=1为表格内容
    let scale = {};
    for(let i=0; i<data.length; i++){
      if(data[i].type==1){
        scale = data[i];
      }
    }
    return scale;
  }

  getContent(datas){
    const {tableId,result,comfirnFlag} = this.props;
    const scaleResult = result&&result[tableId]; //量表计算结果
    let content;
    if(datas&&datas.scaleType==1){//计分
      content =  datas&&datas.group&&datas.group.map((v,i)=>{
        return <div className={style['group']}>
          <p className={style['groupName']}>{v.groupName}</p>
          {v.rows&&v.rows.map((it)=>{
            return <div className={style['rows']}>
              {it.required==1&&it.row.length>1?<span className={style['tip']}>本组选项可多选或根据需要选择某一条选项</span>:''}
              {it.row.map((item,index)=>{
                if(item.controlType==0){
                  return <div className={style['block']} style={{border:it.required==1&&!item.isSelect?'1px solid #f00':'none'}}>
                    {/*<p className={style['miniName']}>{item.name}</p>*/}
                    <p className={style['miniName']}>
                      <i>{index==0?it.indexId + '.':''}</i>
                      {item.name}
                    </p>
                    {item.details&&item.details.map((vv,ii)=>{
                      return <div className={style['item']}>
                        <Radio label={vv.detailName+'('+vv.score+')'}
                               isSelect={vv.select==1}
                               disabled={true}>
                        </Radio>
                        {vv.state==1?<span className={style['recomand']}>（智能推荐）</span>:''}
                      </div>
                    })}

                  </div>
                }else{
                  return <div className={style['block']}>
                    <p className={style['miniName']}>{item.name}</p>
                    {item.details&&item.details.map((vv)=>{
                      return <div className={style['item']}>
                        <CheckBtn value={vv.detailName}
                                  label={vv.detailName}
                                  isSelect={vv.select==1}
                                  disabled={true}>
                        </CheckBtn>
                        {vv.state==1?<span className={style['recomand']}>（智能推荐）</span>:''}
                      </div>
                    })}
                  </div>
                }

              })}
            </div>
          })}
          {/*<p className={style['subTotal']}>
            <span>计分：</span>
            <span></span>
          </p>*/}
        </div>
      })
    }else if(datas&&datas.scaleType==2){//不计分
      content =  datas&&datas.rows.map((item)=>{
        return <div className={style['block']} style={{border:item.required==1&&!item.isSelect&&comfirnFlag?'1px solid #f00':'none'}}>
          <p className={style['miniName']}>{item.name}</p>
          {item.details&&item.details.map((vv)=>{
            return <div className={style['item']}>
              <Radio label={vv.detailName+'('+vv.result+')'}
                     isSelect={vv.select==1}
                     disabled={true}>
              </Radio>
              {vv.state==1?<span className={style['recomand']}>（智能推荐）</span>:''}
            </div>
          })}

        </div>
      })
    }

    return content;
  }

  render(){
    const {title,data,result} = this.props;
    const scale = data && this.filterScale(data.data);
    const datas = scale && scale.content && JSON.parse(scale.content);
    const scaleResult = datas; //量表计算结果
    return <div className={style['tableBox']} id="printcontent">
            <div className={style['printShow']}>
              <Information></Information>
            </div> 
            <h1>{datas?datas.scaleName:''}</h1>
            {data &&data.data&& data.data.map((v,i)=>{
              if(v.type==0){
                return <div dangerouslySetInnerHTML={{__html:v.content}} className={style['textlh']}></div>
              }else{
                return <div className={style['textContent']}>
                  {this.getContent(datas)}
                  {datas&&datas.Calc==1?<div className={style['total']}>
                    <span>总分：</span>
                    <span>{result&&result.calcalculate&&result.calcalculate.result&&result.calcalculate.result.value +' '+ (result.calcalculate.result.text||'')}</span>
                  </div>:<div className={style['total']}>
                    <span>结果：</span>
                    <span>{result&&result.calcalculate&&result.calcalculate.result&&result.calcalculate.result.value +' '+ (result.calcalculate.result.text||'')}</span>
                  </div>}
                </div>
              }
            })}
          </div>
  }
}
export default ScaleTableHis;