/*
 * Creator:     ML
 * CreatDate:   2020-03-21
 * descripts：  患者中心 预约治疗 预约项目小组件 
 * */
import React from 'react';
import { Button, List,Modal } from 'antd-mobile';
import { $http } from "containers/config/https";
// import { Util } from 'tools';
import '../style/index.less';
import store from "store";
import PayTips from './payTips'
const ListItem = List.Item;
const alert = Modal.alert;
class AppointmentItem extends React.Component {
    constructor({ history }) {
        super();
        let userData = sessionStorage.getItem("userData") ? JSON.parse(sessionStorage.getItem("userData")) : {};
        this.state = {
            userData,
            cancel:false
        };
        this.history = history;
    }

    componentDidMount = () => {
        // console.log("store.getState().homeRedux.treatmentItemsData预约治疗主页面",store.getState().homeRedux.treatmentItemsData)
    }
    //取消治疗订单
    handleCancel = (item) => {
        const {userData} = this.state
        alert('取消订单将回到申请页面', '确定取消???', [
            { text: '取消', onPress: () => console.log('cancel') },
            { text: '确定', onPress: () => {
                let data = {
                    params: [{
                        userID: userData && userData.patID ? userData.patID : "",
                        cureAppID: item.cureAppID || item.ID
                    }],
                }
                $http.post("urlS", this, {
                    code: "01040014",
                    data: data,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                         this.props.toHome()
                        }else{
                            
                        }
                    }
                });
            } },
          ])
     
    }
    onRef = (ref) => {
        this.childPay = ref
    }
    //点击付款
    handleToPay = (price) => {
        this.childPay.showModal(price)
    }
    componentWillUnmount() {
        // 组件销毁前将静止让setState修改state的状态
        this.setState = (state, callback) => { return; }
    }
    handleCheckApply = (item, flag) => {
        this.props.handleCheckApply(item, flag)
    }
    render() {
        // const { } = this.state
        return (
            <div className="treatmentOrder-dom">
                {/* <WhiteSpace /> */}
                <List>
                    <ListItem >
                        <div className="project-lists treatmentOrder-center" >
                            <p className="small">
                                <span>{store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.descripts}</span>
                                <span> <span >{((store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.totalPrice)||store.getState().homeRedux) && store.getState().homeRedux.treatmentItemsData.total}元</span></span>
                            </p>
                            <p className="small">
                                <span>{store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.locDesc}</span>
                                <span>{store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.patPrice}元</span>
                            </p>
                            <p className="number">
                                <span>x{((store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.count)||store.getState().homeRedux) && store.getState().homeRedux.treatmentItemsData.totalNumber}</span>
                            </p>
                        </div>
                        <div className="treatmentOrder-bottom" style={{display:(this.props.hide&&this.props.hide?"none":"block")}}>
                            <div>
                                <Button className="applyEdit" onClick={() => this.handleCheckApply(store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData)}>查看申请</Button>
                                {/* <Button className="applyEdit"
                                    style={{
                                        display: ((store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.reportFlag) == "N"
                                        && (store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.statusCode) == "3"
                                             ? "block" : "none")
                                    }}
                                    onClick={() => this.handleCheckApply(store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData, "1")}>修改申请</Button> */}
                                <Button
                                    style={{
                                        display: (
                                            ((store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.reportFlag) === "N"
                                            && (store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.statusCode) === "3")
                                            || !this.state.cancel
                                           ? "block" : "none")
                                    }}
                                    className="applyEdit" onClick={() => this.handleCancel(store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData)}>取消</Button>
                                <Button
                                    onClick={
                                        ()=>this.handleToPay(
                                            (((store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.totalPrice)||store.getState().homeRedux) && store.getState().homeRedux.treatmentItemsData.total),
                                            (store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.payNote)
                                            )
                                        }
                                    style={{ display: ((store.getState().homeRedux && store.getState().homeRedux.treatmentItemsData.reportFlag) === "N" ? "block" : "none") }}
                                    className="patOrder">付款</Button>
                            </div>
                        </div>
                    </ListItem>
                </List>
                <PayTips onRef={this.onRef}></PayTips>
            </div>
        )
    }
};
export default AppointmentItem;