/*
 * Creator:     ML
 * CreatDate:   2020-03-22
 * descripts：  患者中心 治疗记录
 * */
import React from 'react';
import { List, WhiteSpace,Toast } from 'antd-mobile';
import { $http } from "containers/config/https";
// import { Util } from 'tools';
import './style/index.less';
import store from "store";
import AppointmentItem from './componts/AppointmentItem'
const ListItem = List.Item;
class TreatmentRecord extends React.Component {
    constructor({ history }) {
        super();
        let userData = localStorage.getItem("userData") ? JSON.parse(localStorage.getItem("userData")) : {};
        this.state = {
            userData,
            smallClassModal: false,
            itemID: ""
        };
        this.history = history;
    }

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

    //查询治疗记录
    handleGetItem = () => {
        const { userData } = this.state
        let data = {
            params: [{
                hospCode: userData && userData.hospCode ? userData.hospCode : "",
                cureAppID: (store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.ID) || "",
            }],
        }
        $http.post("urlS", this, {
            code: "01040007",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({
                        projectArr: res.result
                    })
                }else{
                    Toast.info(res.errorMessage)
                }
            }
        });
    }
    //打开治疗记录详情
    handleTreatmentDeatil = (item) => {
        this.history.push({
            pathname: "/0002/0015",
            state: { ...item }
        })
    }
     //查看申请
     handleCheckApply = (item, flag) => {
        let obj = item
        if (!flag) {
            obj["disabled"] = true
            obj["edit"] = 0
            this.history.push({
                pathname: "/0002/0011",
                state: { ...obj }
            })
        } else {
            obj["disabled"] = false
            obj["edit"] = 1
            this.history.push({
                pathname: "/0002/0011",
                state: { ...obj }
            })
        }
        
    }
    //取消订单 回到首页
    toHome=()=>{
        this.history.push({
          pathname: "0010",
          state: {}
      })
      let item = {}
      store.dispatch({
          type: "treatmentItems",
          value: {...item}
      });
      }
    render() {
        const { projectArr } = this.state
        let ListItemOp = []
        projectArr && projectArr.map((item, i) => {
            return ListItemOp.push(
                <ListItem key={i}>
                    <ListItem className="treatmentOrder-top">
                        <div className="treatmentOrder-p">
                            <div>
                                <span className="line"></span>
                                <span>{item.execDateTime}</span>
                            </div>
                        </div>
                    </ListItem>
                    <div className="appoint-lists" style={{ padding: "6px 0 0 12px" }}>
                        <div>
                            <span className={(item.cureDoctorSex === '1' ? 'card-splice-boy' : 'card-splice-girl') + " AvtorImg"}></span>
                            <span className="info">
                                <span className="name">
                                    <span>{item.cureDoctorDesc}</span>
                                    <span>{item.appMedDesc}</span>
                                </span>
                                <span className="type">{item.appLoc}</span>
                            </span>
                        </div>
                        <div>
                            <p style={{ color: "#22a9a9", }} onClick={() => this.handleTreatmentDeatil(item)}>
                                <i style={{ color: "#f79f00", border: "1px solid #f79f00", padding: "8px" }}>治疗记录</i>
                            </p>
                        </div>
                    </div>
                </ListItem>
            )
        })
        return (
            <div className="appoint-dom appointRecord-dom treatmentOrder-dom">
                <AppointmentItem info={store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData} handleCheckApply={this.handleCheckApply} toHome={this.toHome} hide={"hide"}></AppointmentItem>
                <WhiteSpace />
                <div className="patientRecord-dom">
                    <List>
                        {ListItemOp}
                    </List>
                </div>


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