// 体检报告
import React from 'react';
import { List } from 'antd-mobile';
import './style/index.less';
import { $http } from "containers/config/https";

const Item = List.Item;
const Brief = Item.Brief;

export default class MedicalExaminationReport extends React.Component {
  constructor({history}) {
    super();
    this.state = {
      medicalReportData: {}
    };
    this.history = history;
  }

  componentDidMount() {
    let rowData = this.props.location&&this.props.location.state ? this.props.location.state : {};
    if (rowData&&rowData.eventValue) {
      this.getMedicalReportData(rowData.eventValue)
    }
  }

  // 获取体检报告数据
  getMedicalReportData = (healthRecordID) => {
    let data = {
			params: [{
        healthRecordID
      }]
		}
		$http.post("urlS", this, {
			code: "03070092",
      data: data,
      namespace: "HIS",
			success: function(res) {
				if (+res.errorCode === 0) {
          this.setState({medicalReportData: res.result})
				} else {
					this.setState({medicalReportData: {}});
				}
			}
		});
  }

	componentWillUnmount() { 
		// 组件销毁前将静止让setState修改state的状态
		this.setState = (state,callback)=>{ return; }
  }

  // 遍历数据
  mapData = (data) => {
    return data&&data.map((item, index) => {
      return (
        <Item key={index}>
          {item.desc}
        </Item>
      )
    })
  }

  render() {
    let {medicalReportData} = this.state;
    let {CMGuidance, healthAssessment, healthGuidance, riskFactor} = medicalReportData
    return (
      <div className="medical-examination-report">
        <div className="mer-content">
          <List> 
            <Item className="list-header">
              健康评价 {healthAssessment&&healthAssessment.length > 0 ? <Brief>有异常</Brief> : ""}
            </Item>
            {healthAssessment instanceof Array&&healthAssessment.length > 0 ? this.mapData(healthAssessment) : <Item>暂无健康评价</Item>}
          </List>
          <List> 
            <Item className="list-header">
              健康指导
            </Item>
            {healthGuidance instanceof Array&&healthGuidance.length > 0 ? this.mapData(healthGuidance) : <Item>暂无健康指导</Item>}
          </List>
          <List> 
            <Item className="list-header">
              危险控制因素
            </Item>
            {riskFactor instanceof Array&&riskFactor.length > 0 ? this.mapData(riskFactor) : <Item>暂无危险控制因素</Item>}
          </List>
          <List> 
            <Item className="list-header">
              中医指导
            </Item>
            {CMGuidance instanceof Array&&CMGuidance.length > 0 ? this.mapData(CMGuidance) : <Item>暂无中医指导</Item>}
          </List>
        </div>
      </div>
    )
  }
}