/*
 * Creator:     ML
 * CreatDate:   2020-03-12
 * descripts：  患者中心 申请列表
 * */
import React from 'react';
import { Toast, List, SearchBar, WhiteSpace, } from 'antd-mobile';
import { $http } from "containers/config/https";
// import { Util } from 'tools';
import './style/index.less';
import store from "store";
const ListItem = List.Item;
// const alert = Modal.alert;
class PatientCenter extends React.Component {
  constructor({ history }) {
    super();
    let userData = localStorage.getItem("userData") ? JSON.parse(localStorage.getItem("userData")) : {};
    // console.log("userData",userData)
    this.state = {
      userData,
      errorData: {}
    };
    this.history = history;
  }

  componentDidMount = () => {
    this.handleGetItem()
  }

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

  }
  // 搜索
  handleSearch = (val) => {
    this.handleGetItem(val)
  }

  //查询治疗项目
  handleGetItem = (val) => {
    const { userData } = this.state
    let data = {
      params: [{
        hospCode: userData && userData.hospCode ? userData.hospCode : "",
        cureItemDesc: this.state.searchValue || "",
      }],
    }
    $http.post("urlS", this, {
      code: "01040009",
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          this.setState({
            projectArr: res.result.data
          })
        } else {
          Toast.info(res.errorMessage)
        }
      }
    });
  }

  //申请
  handleApply = (item) => {
    this.history.push({
      pathname: "/0002/0011",
      state: { ...item }
    })
    store.dispatch({
      type: "treatmentItems",
      value: { ...item }
    });
  }
  //实时获取搜索框的值
  handleChangeValue = (e) => {
    this.setState({
      searchValue: e
    })
  }
  render() {
    const { projectArr, searchValue } = this.state
    let ListItemOp = []
    projectArr && projectArr.map((item, i) => {
      return ListItemOp.push(
        <ListItem key={i}>
          <div className="project-lists" >
            <p>
              <span>{item.descripts}</span>
              <span> <span style={{ color: "#3dc17f" }}>{item.patPrice}</span>{"元/" + item.unit}</span>
            </p>
            <p><span>{item.locDesc || "--"}</span></p>
            <span className="bth" onClick={() => this.handleApply(item)}>申请</span>
          </div>
        </ListItem>
      )
    })
    return (
      <div className="patientCenter-dom">
        <SearchBar
          placeholder="治疗项目名称"
          cancelText={<span>搜索</span>}
          onCancel={this.handleSearch}
          showCancelButton
          value={searchValue}
          onChange={(e) => this.handleChangeValue(e)}
        />
        <WhiteSpace />
        <div class="scroll-view">
          <List>
            {ListItemOp}
          </List>
        </div>


      </div>
    )
  }
};
export default PatientCenter;