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 {title,formulaResult,data} = this.props;
    // const datas = valueData&&valueData.group?valueData:mocks.newData;
    let 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,ind)=>{
                    return <div>
                      {it.row.map((item,index)=>{
                        if(item.controlType==0){
                          return <div className={style['block']} style={{border:it.required==1&&!item.isSelect&&start?'1px solid #f00':'none'}}>
                              <p className={style['miniName']}>{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,ii)=>{
                                    return <div className={style['item']}>
                                    <CheckBtn value={vv.detailName}
                                                    label={vv.detailName}
                                                    disabled={true}
                                                    isSelect={vv.select==1}>
                                          </CheckBtn>
                                    {vv.state==1?<span className={style['recomand']}>（智能推荐）</span>:''}
                                    </div>
                                  })}
                            </div>
                          }
                        
                      })}
                    </div>
                  })}
                  {v.groupCalculate.isShow==1?<p className={style['subTotal']}>
                    <span>计分：</span>
                    {/*<span>{v.groupCalculate.result.value}</span>*/}
                    <span>{scaleResult&&scaleResult.group.map((m,ii)=>{
                      if(m.groupName==v.groupName){
                        return m.groupCalculate.result.value;
                      }
                    })}</span>
                  </p>:''}  
                </div>
              })
    return content;
  }

  render(){
    const {title,data,result} = this.props;console.log(this.props)
    const scale = data && this.filterScale(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.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>
              }
            })}
          </div>
  }
}
export default ScaleTableHis;