/*
 * Create:      柿子
 * CreateDate:  2023/12/29
 * Describe：   退院 - 移入退院区
 * */
import React, { Component } from 'react';
import { Modal } from 'antd';
import { Util } from 'tools';
import store from 'store';
import PatientInfo from './PatientInfo'; // 患者信息展示
import PublicTablePagination from 'pages/common/PubilcTablePagination';
import './style/index.less';

class DischargeFromHospital extends Component {
  constructor(props) {
    super(props);
    this.state = {
      userData: React.$getSessionData(),
      visible: false,
      rowData: {},
      totalWidth: 0,
      columns: [],
      tableData: []
    }
  };

  componentDidMount() {
    this.props && 'onRef' in this.props && this.props.onRef(this);
  };

  modifyVisible = (visible, rowData = {}) => {
    const { columns } = this.state;
    if (visible) {
      !(columns && columns.length > 0) && this.getTableColumns();
    }
    this.setState({ visible, rowData }, () => {
      visible && this.getTableData();
    });
  };

  // 获取列表表头数据
  getTableColumns = async () => {
    try {
      let data = {
        params: [{
          type: 'C',
          compontName: 'DischargeFromHospital',
        }]
      }
      let res = await React.$asyncPost(this, '01040073', data);
      let columns = res.result?.C || [];
      if (columns && columns.length > 0) {
        this.setState({
          columns,
          totalWidth: res.totalWidth
        })
      }
    } catch (error) {
      console.log(error)
    }
  };

  // 病区信息明细
  getTableData = async () => {
    try {
      this.setState({ loading: true });
      const { rowData } = this.state;
      let data = {
        params: [{
          ...rowData
        }]
      }
      let res = await React.$asyncPost(this, '123', data);
      let tableData = Util.addKeyValueToDataSource(res?.result || []);
      this.setState({ tableData, loading: false });
    } catch (error) {
      console.log(error);
      this.setState({ loading: false });
    }
  };

  // 确认
  handleOk = () => {

  };

  render() {
    const { visible, rowData, tableData, totalWidth, columns, loading } = this.state;
    return (
      <Modal
        title="退院"
        width="60vw"
        footer={null}
        bodyStyle={{ padding: '12px', paddingTop: '6px' }}
        visible={visible}
        onOk={this.handleOk}
        onCancel={() => this.modifyVisible(false)}
      >
        <div className="table-body-height">
          <PatientInfo patInfo={rowData} />
          <div style={{ paddingTop: '8px' }}>
            <PublicTablePagination
              param={{
                y: store.getState().tableHeight.y - 150,
                height: store.getState().tableHeight.y - 100 + 'px',
                data: tableData, // 表格数据
                x: totalWidth, // 表格的宽度
                columns, // 表头配置
                loading: loading,
                componentName: 'DischargeFromHospital',
              }}
              getColumns={this.getTableColumns}
            />
          </div>
        </div>
      </Modal>
    )
  }
};

export default DischargeFromHospital;