// 住院床旁结算列表
import React, { Component } from 'react';
import { Toast } from 'antd-mobile';
import { $http } from "containers/config/https";
import { Util } from 'tools';

import '../../assets/less/common.less';

class InpatientBedsideSettlementList extends Component {
  constructor(props) {
    super(props);
    this.state = {
      userData: JSON.parse(localStorage.getItem("userData")) || {},
      settlementList: {}
    }
  }

  componentDidMount() {
    let url = window.location.href.indexOf("?") !== -1 ? String(window.location.href).split("?")[1] : "";
    let startDate = Util.interceptTheValueOfTheURL(Util.interceptTheValueOfTheURL(url, "params", "&", "="), "startDate", "^", ":");
    console.log(startDate)
    this.getSettlementList(startDate);
  }

  componentWillMount() {

  }

  getSettlementList = (startDate) => {
    let { userData } = this.state;
    let data = {
      params: [{
        hospCode: userData.hisHospID,
        userCode: "wxsf",
        startDate: startDate ? startDate : "2020-09-10",
      }]
    }
    $http.post("urlS", this, {
      code: "130986",
      data: data,
      namespace: "UPP",
      success: function (res) {
        if (+res.errorCode === 0) {
          let settlementList = res.result && res.result.length > 0 ? res.result[0] : {};
          this.setState({ settlementList })
        } else {
          Toast.info(res.errorMessage, 3, () => { }, false)
        }
      }
    });
  }

  render() {
    let { settlementList } = this.state;
    return (
      <div className="inpatient-bedside-settlement-list">
        <div className="ibsl-header">住院床边结算数据列表</div>
        <div className="ibsl-date">统计日期：{settlementList && settlementList.Date ? settlementList.Date : ""}</div>
        <div className="primary-table" style={{ height: 'calc(100% - 92px)', overflow: "hidden" }}>
          <div style={{ overflowY: "scroll" }}>
            <table border="0" cellSpacing="1" cellPadding="0" className="t-head">
              <tbody>
                <tr>
                  <th className="t-col-key">序号</th>
                  <th className="t-col-1">科室</th>
                  <th>床旁结算人数</th>
                  <th>出院人数</th>
                  <th>结算比例</th>
                  <th>床旁入院人数</th>
                  <th>入院人数</th>
                  <th>入院比例</th>
                  {/* <th>合计</th> */}
                </tr>
              </tbody>
            </table>
          </div>
          <div style={{ height: "calc(100% - 66px)", overflowY: "scroll" }}>
            <table border="0" cellSpacing="1" cellPadding="0">
              <tbody>
                {settlementList && settlementList.tableData instanceof Array && settlementList.tableData.map((item, index) => {
                  return (<tr key={index}>
                    <td className="t-col-key">{index + 1}</td>
                    <td className="t-col-1">{item.locDesc}</td>
                    <td>{item.bedsideSettlementNum}</td>
                    <td>{item.leaveHospitalNum}</td>
                    <td>{item.settlementRatio}</td>
                    <td>{item.bedsideAdmissionNum}</td>
                    <td>{item.beHospitalizedNum}</td>
                    <td>{item.admissionRatio}</td>
                    {/* <td>{item.admissionRatio}</td> */}
                  </tr>)
                })}
              </tbody>
            </table>
          </div>
        </div>
      </div>
    );
  }
}

export default InpatientBedsideSettlementList;