// 就诊详情 - 诊疗记录
import React from 'react';
import { List } from 'antd-mobile';
import './style/index.less';
import { $http } from "containers/config/https";

const Item = List.Item;

export default class DetailsOfTreatment extends React.Component {
  constructor() {
    super();
    this.state = {
      diagnosisAndTreatmentInfo: {}
    }
  }

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

  // 获取诊疗记录信息
  getDiagnosisAndTreatmentInfo = (admID) => {
    let data = {
			params: [{
        admID
      }]
		}
		$http.post("urlS", this, {
			code: "03070063",
      data: data,
      namespace: "HIS",
			success: function(res) {
				if (+res.errorCode === 0) {
          this.setState({diagnosisAndTreatmentInfo: res.result})
				} else {
					this.setState({diagnosisAndTreatmentInfo: {}});
				}
			}
		});
  }

  render() {
    let {diagnosisAndTreatmentInfo} = this.state;
    let doctorAdvice = diagnosisAndTreatmentInfo&&diagnosisAndTreatmentInfo.data instanceof Array ? diagnosisAndTreatmentInfo.data.map((item, index) => {
      return (
        <div key={index} style={{marginBottom: '12px'}}>
          {(index + 1 + '：') + item.medItemDesc + (item.frequence ? ('[' + item.frequence + ']') : "") + (item.dose ? ('[' + item.dose + item.doseUnit + ']') : "") + (item.durQty ? ('[' + item.durQty + item.duration + ']') : "")}
        </div>
      )
    }) : "暂无数据";
    return (
      <div className="details-of-treatment">
        <List>
          <Item extra="医院" multipleLine align="top" wrap>
            {diagnosisAndTreatmentInfo.hospDesc || "暂无数据"}
          </Item>
          <Item extra="科室" multipleLine align="top" wrap>
            {diagnosisAndTreatmentInfo.locDesc || "暂无数据"}
          </Item>
          <Item extra="医生" multipleLine align="top" wrap>
            {diagnosisAndTreatmentInfo.docName || "暂无数据"}
          </Item>
          <Item extra="日期" multipleLine align="top" wrap>
            {diagnosisAndTreatmentInfo.admDate || "暂无数据"}
          </Item>
          <Item extra="诊断" multipleLine align="top" wrap>
            {diagnosisAndTreatmentInfo.diagnosisDesc || "暂无数据"}
          </Item>
          <Item extra="医嘱" multipleLine align="top" wrap>
            {doctorAdvice}
          </Item>
        </List>
      </div>
    )
  }
}