// 出院小结
import React from 'react';
import { $http } from "containers/config/https";
import { List, Toast } from 'antd-mobile';
import './style/visitRecords.less';
import zljlNodata from 'assets/images/zljl-nodata.png'

const Item = List.Item;

export default class DischargeSummary extends React.Component {
  constructor({ history }) {
    super();
    let userData = localStorage.getItem("userData") ? JSON.parse(localStorage.getItem("userData")) : {};
    this.state = {
      userData,
      visitRecordsListData: [],
    }
    this.history = history;
  }

  componentDidMount() {
    this.getVisitRecordsListData();
  }

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

  // 获取就诊记录
  getVisitRecordsListData = () => {
    Toast.loading('数据加载中...', 30);
    let { userData } = this.state;
    let data = {
      params: [{
        hospCode: userData && userData.hisHospID ? userData.hisHospID : "",
        patDesc: userData && userData.patDesc ? userData.patDesc : "",
        userCode: "wxsf",
        patNO: userData.hisPatNo
        // patNO: "0000038961"
      }]
    }
    $http.post("urlS", this, {
      code: "130972",
      data: data,
      namespace: "UPP",
      success: function (res) {
        Toast.hide()
        if (+res.errorCode === 0) {
          this.setState({ visitRecordsListData: res.result });
        } else {
          this.setState({ visitRecordsListData: [] });
          Toast.info(res.errorMessage, 3, () => { }, false)
        }
      },
      error: function () {
        Toast.hide()
      }
    });
  }

  render() {
    let { visitRecordsListData } = this.state;
    let detailData = visitRecordsListData && visitRecordsListData.length > 0 ? visitRecordsListData[0] : {};
    return (
      <div className="visit-records">
        <List className="visit-records-list">
          {detailData.admDetail && detailData.admDetail.map((item, index) => {
            return <Item key={index} multipleLine>
              <div className="visit-records-list-item">
                <p>
                  <span className="visit-records-list-item-key">就诊科室：</span>{item.admLoc}
                </p>
                <p>
                  <span className="visit-records-list-item-key">就诊医生：</span>{item.admDoctor}
                </p>
                <p>
                  <span className="visit-records-list-item-key">费别：</span>{item.admReasonDesc}
                </p>
                <p>
                  <span className="visit-records-list-item-key">就诊人：</span>{item.patName}
                </p>
                <p>
                  <span className="visit-records-list-item-key">登记号：</span>{detailData.patNo}
                </p>
                <p>
                  <span className="visit-records-list-item-key">就诊日期：</span>{item.admDate + item.admTime}
                </p>
                <p>
                  <span className="visit-records-list-item-key">出院小结：</span>{item.admEPRData ? item.admEPRData : <span style={{ color: "#999" }}>暂无记录</span>}
                </p>
              </div>
            </Item>
          })}
        </List>
        <div style={{ display: detailData.admDetail && detailData.admDetail.length > 0 ? 'none' : 'block', width: '100%', textAlign: 'center', color: '#999' }}>
          <img style={{ width: '100%' }} src={zljlNodata} alt="" />
          暂无记录
        </div>
      </div>
    )
  }
}