/*
* 物流信息
* */

import React, { Component } from 'react';
import { Input, Form, Select, Modal, Button, Card, Timeline, message } from 'antd';
import { Util } from 'tools/index';
import { $http } from 'containers/config/https';
import '../courierStyle/index.less';
import moment from 'moment';


class ConfirmRegistrModal extends Component {

    constructor(props) {
        super(props);
        this.state = {
        }
    }

    componentWillReceiveProps(nextProp) {
        if (nextProp.isShow === true) {
            this.setState({
                orderID: nextProp.cuorierID
            }, () => {
                this.loadData()
            })
        } else if (this.props.isShow === false) {
            this.cleanInput();
        }
    }

    loadData() {
        var params = {
            params: [{
                orderID: this.state.orderID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03030036",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        dataSource: res.result ? res.result[0].routeData : '',
                        expressNo: res.result ? res.result[0].expressNo : ''
                    })
                }
            }
        });
    }

    closeModal() {
        let { onHide } = this.props;
        onHide && onHide();
        this.cleanInput();
    }

    //清空输入框
    cleanInput() {
        this.setState({
            dataSource: [],
            expressNo: ''
        })
    }

    render() {
        var { dataSource } = this.state;
        var dataOption = []
        dataSource && dataSource.map((item, index) => {
            dataOption.push(
                <Timeline.Item key={index} label={item.acceptTime} value={item.acceptTime}>
                    <span>
                        <span>{item.acceptAddress}</span>
                        <span>{item.remark}</span>
                        <span>{item.acceptTime}</span>
                    </span>
                </Timeline.Item>
            )
        })
        return <div>
            <Modal className='courier-modal'
                title={'物流信息'}
                maskClosable={false}
                visible={this.props.isShow}
                onCancel={this.closeModal.bind(this)}
                footer={null}>
                <Card title={<span>订单号：{this.state.expressNo}</span>}>
                    <Timeline mode='Alternate'>
                        {dataOption}
                    </Timeline>
                </Card>
            </Modal></div>
    }
}

export default Form.create()(ConfirmRegistrModal);