// 电子健康卡
import React from 'react';
import { Button, WhiteSpace, Toast } from 'antd-mobile';
import { $http } from "containers/config/https";
import "./style/index.less";
import { Util } from 'tools';
// import store from "store";

export default class ElectronicHealthCard extends React.Component {
  constructor({ history }) {
    super();
    let userData = localStorage.getItem("userData") ? JSON.parse(localStorage.getItem("userData")) : {};
    this.state = {
      userData,
      imgData: [],
      imgHeight: 176,
      unBindParArr: [], // 就诊人列表
    }
    this.history = history;
  }

  componentDidMount() {
    this.getCardList();
    // this.getImgData()
  }

  componentWillUnmount() {
    this.setState = (state, callback) => {
      return;
    };
  }

  // 获取轮播图数据
  getImgData = () => {
    let data = [
      {
        id: 1,
        imgPath: "https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=f9f84966ba99a9012f3853647cfc611e/4ec2d5628535e5dd01d930ad74c6a7efcf1b62cf.jpg"
      },
      {
        id: 2,
        imgPath: "https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=f9f84966ba99a9012f3853647cfc611e/4ec2d5628535e5dd01d930ad74c6a7efcf1b62cf.jpg"
      },
      {
        id: 3,
        imgPath: "https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=f9f84966ba99a9012f3853647cfc611e/4ec2d5628535e5dd01d930ad74c6a7efcf1b62cf.jpg"
      }
    ];
    this.setState({ imgData: data })
  }

  // 跳转到卡信息
  handleGoCardInfo = () => {
    this.history.push("/0001/00010002");
  }

  // 跳转到绑定电子健康卡界面
  handleGoBindingCard = () => {
    let { userData } = this.state;
    switch (userData.hospID) {
      case "1":
        this.history.push("/0001/00010004");
        break;
      default:
        this.history.push("/0001/00010003");
        break;
    }
  }

  // 跳转到就诊卡详情
  handleGoVisitCardDetails = (item) => {
    let id = item && item.patID ? item.patID : "";
    let path = `/0001/00010001/${id}`
    this.history.push(path);
  }

  // 升级电子健康卡
  handleUpgrade = (e, item) => {
    e.stopPropagation(); // 阻止事件冒泡
    // console.log(item)
  }

  // 获取所有卡列表
  getCardList = () => {
    Toast.loading('数据加载中...', 30);
    let data = {
      params: [{

      }]
    }
    $http.post("urlS", this, {
      code: "01030001",
      data: data,
      success: function (res) {
        Toast.hide()
        if (+res.errorCode === 0) {
          let unBindParArr = res.result.rows && res.result.rows instanceof Array ? res.result.rows : [];
          this.setState({ unBindParArr })
        }
      },
      error: function () {
        Toast.hide()
      }
    });
  }

  handleAddCard = () => {
    // store.dispatch({
    //   type: "isAddAdm",
    //   value: true
    // });
    Toast.info("开发中……", 3, () => { }, false)
  }

  // 返回首页
  handleGoHome = () => {
    this.history.push("/0001/00000001");
  }

  render() {
    let { unBindParArr } = this.state;

    let admListDom = unBindParArr && unBindParArr.map((item, index) => {
      let setIcon = Util.calculateAge(item && item.idCardNo ? item.idCardNo : "") < 14 ? "iconfont icon-ertong icon-child" : (item.patSexDesc === "女" ? "iconfont icon-nvshi icon-girl" : "iconfont icon-nanshi icon-boy")
      return (
        <li key={index} className="the-patient" onClick={() => this.handleGoVisitCardDetails(item)}>
          <i className={setIcon}></i> {item.patName}
          <span style={{ fontSize: "12px", color: "#999" }}>  {Util.identityCardEncryption(item.idCardNo)}</span>
          {/* <span className="tp-button" onClick={(e) => this.handleUpgrade(e, item)}>升级为电子健康卡</span> */}
        </li>
      )
    })
    return (
      <div className="electronic-health-card">
        <p className="title-p">就诊人列表</p>
        <ul className="ehc-content">
          {admListDom}
        </ul>
        <div className="ehc-btn">
          <Button type="primary" onClick={this.handleGoBindingCard}>添加就诊人</Button>
          {/* <WhiteSpace />
          <Button type="ghost" onClick={this.handleAddCard}>添加社保卡</Button> */}
          <WhiteSpace />
          <Button type="ghost" onClick={this.handleGoHome}>返回首页</Button>
          {/* <p className="font14 lineheight24" style={{ textAlign: "center", color: "#999" }}>您还可以添加4张电子健康卡</p> */}
        </div>
      </div>
    )
  }
}
