import React, { Component } from "react";
import style from "./index.less";
import { Radio} from '@commonComp';
import Notify from '@commonComp/Notify';
import ChooseItem from "./ChooseItem";
import ScaleItem from "./ScaleItem";
import ChartItem from "./ChartItem";


class AssessResult extends Component {
  constructor(props) {
    super(props)
  }
  componentWillMount(){
    //获取评估
    this.props.getAssess();
  }
  parseChartData(){
    const {indexData}=this.props;
    let arr=[],obj={},temp={};
    let nameArr=[],nameObj={};
    if(!indexData){
      return [];
    }
    indexData.indexConfigData.map((it)=>{
      arr=obj[it.orderNo]||[];
      nameArr=nameObj[it.orderNo]||[];
      temp=indexData.itemIndexData.find((i)=>{return i.itemName==it.indexUnique});
      obj[it.orderNo]=[...arr,temp];
      nameObj[it.orderNo]=[...nameArr,it.indexUnique];
    });
    //nameObj,obj;
    return {nameObj,obj};
  }
  handoutTypes(item){
    const {getIndexData,indexData} =this.props;
    //console.log(indexData)
    const chartData = this.parseChartData();
    const name = item.regionName+"：";
    const list = item.data&&item.data.rows;
    switch (+item.regionType){
      case 0:
        return <ScaleItem title={name} data={list}></ScaleItem>;
      case 1:
        return <ChooseItem title={name} data={list}></ChooseItem>;
      case 10:
        return <ChartItem title={name} data={chartData} initFn={getIndexData}></ChartItem>;
      default:
        return '';
    }
  }
  render() {
    const { onClose,data } = this.props;
    return <div className={style['assess-cont']}>
      {data&&data.map((it)=>{
        return this.handoutTypes(it);
      })}
    </div>;
  }
}

export default AssessResult;
