/*
 * Creator:     ML
 * CreatDate:   2020-03-19
 * descripts：  配送单 取消订单按钮
 * */
import React from 'react';
import { Modal } from 'antd-mobile';
import "pages/common/style/index.less";
import '../style/index.less';
import { $http } from "containers/config/https";
import store from "store";

const alert = Modal.alert;
export default class CancelBtn extends React.Component {
    constructor({ history }) {
        super();
        this.state = {
            activeTabs: "1",
            expressModal: false
        }
        this.history = history;
    }

    componentDidMount() {
      
    }
    //获取已取消订单
    geDeliveredData = (flag, orderID) => {
        let datas = {
            params: [{
                patID: "1",
                hospID: "1",
                ordStatusID: flag || "5",
            }],
        }
        $http.post("urlS", this, {
            code: "03030067",
            data: datas,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let data = res.result && res.result.data && res.result.data.length > 0 ? res.result.data : [];
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].orderID === orderID) {
                            this.props.handlePush(data[i])
                        }
                    }
                    // res.result.data && res.result.data.map((i, s) => {
                        
                    // })

                }
            }
        });
    }
    //未配送 / 新增完配送单  取消订单
    handleCancelOrder = () => {
        let data = {
            params: [{
                orderID: this.props.info && this.props.info.orderID,
            }],
        }
        $http.post("urlS", this, {
            code: "03030037",
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.geDeliveredData("4", res.result);
                }
            }
        });
    }
    render() {
        // let { } = this.state;
        return (
            <div className="detail-dom">
                {
                    (+store.getState().electronicPrescription && store.getState().electronicPrescription.distributionTabsData === 1) || (store.getState().electronicPrescription && +store.getState().electronicPrescription.distributionStepData === 2) ? <div className="btn-info">
                        <span onClick={() =>
                            alert('提示', '订单取消后不可恢复,如需配送请在配送单页面重新填写.', [
                                { text: '取消', onPress: () => console.log('cancel') },
                                { text: <span style={{ color: "red" }}>删除</span>, onPress: () => this.handleCancelOrder() },
                            ])
                        }>取消订单</span>
                    </div> : ""
                }
             
            </div>
        )
    }
}