/*
 * Create:      柿子
 * CreateDate:  2023/08/23
 * Describe：   出院带药详情
 * */
import React, { Component } from 'react';
import { List } from 'antd-mobile';
import './style/visitRecords.less';
import zljlNodata from 'assets/images/zljl-nodata.png';

const Item = List.Item;

class DischargeMedicationDetails extends Component {
  constructor({ history }) {
    super();
    this.state = {
      drugData: []
    };
    this.history = history;
  }

  componentDidMount() {
    let drugData = this.props.location && this.props.location.state ? this.props.location.state : [];
    if (drugData && drugData.length > 0) {
      this.setState({ drugData }, () => {
        window.sessionStorage.setItem(
          'DischargeMedicationDetails',
          JSON.stringify(
            [...drugData]
          )
        );
      })
    } else {
      let sessionDrugData = sessionStorage.getItem('DischargeMedicationDetails') ? JSON.parse(sessionStorage.getItem('DischargeMedicationDetails')) : [];
      if (sessionDrugData && sessionDrugData.length > 0) {
        this.setState({ drugData: sessionDrugData });
      } else {
        this.setState({ drugData: [] })
      }
    }
  }
  render() {
    const { drugData } = this.state;
    return (
      <div className="visit-records">
        <List className="visit-records-list">
          {drugData && drugData.map((item, index) => {
            return <Item key={index} multipleLine>
              <div className="visit-records-list-item">
                <p className="border-bottom-after visit-records-list-item-drug">
                  {item.arcimDesc || ''}
                </p>
                <p>
                  <span className="visit-records-list-item-key visit-records-list-item-width-56">用法：</span>每次{item.doseQty + item.doseUnit} {item.instr}
                </p>
                <p>
                  <span className="visit-records-list-item-key visit-records-list-item-width-56">数量：</span>{item.qtyPackUOM}
                </p>
                <p>
                  <span className="visit-records-list-item-key visit-records-list-item-width-56">频次：</span>{item.PHFreq}
                </p>
              </div>
            </Item>
          })}
        </List>
        <div style={{ display: drugData && drugData.length > 0 ? 'none' : 'block', width: '100%', textAlign: 'center', color: '#999' }}>
          <img style={{ width: '100%' }} src={zljlNodata} alt="" />
          暂无记录
        </div>
      </div>
    )
  }
};

export default DischargeMedicationDetails;