/*
 * @Note:
 * @Author: 2058827620@qq.com
 * @Date: 2022-04-03 10:53:25
 */
import React, { useState, useEffect } from 'react';
import {
    Modal,
    Table
} from 'antd';


import { findOrdersStatusByOrderId } from '@/services/order/index';

export default ({ values, modalOpenState, onModalOpenState }) => {

    const [items, setItems] = useState(null);


    useEffect(() => {
        if (!values) {
            return
        }
        findOrdersStatusByOrderId({ orderId: values }).then(({ data, success }) => {
            if (success) {
                setItems(data || []);
            }
        }).catch(() => {

        });
    }, [values]);

    const columns = [
        {
            "title": "ID",
            "dataIndex": "id"
        },
        {
            "title": "订单ID",
            "dataIndex": "ordersId"
        },
        {
            "title": "状态",
            "dataIndex": "orderStatus",
            render: (_: any, record: any) => {
                // 订单状态:1-订单初始化;2-启动充电中;3-正在充电;4-充电结束中;5:交易记录确认;6-订单完成;-1-启动失败;-2-启动超时
                return _ == 1 ? '初始化订单' : _ == 2 ? '启动充电中' : _ == 3 ? '正在充电' : _ == 4 ? '充电结束中' : _ == 5 ? '支付成功' : _ == 6 ? '订单完成' : _ == -1 ? '启动失败' : _ == -2 ? '启动超时' : ''
            },
        },
        {
            "title": "备注说明",
            "dataIndex": "remarks"
        },
        {
            "title": "创建时间",
            "dataIndex": "createTime"
        }
    ];

    return (
        <>
            <Modal width="1200px" title="订单-状态" open={modalOpenState} onOk={() => {
                onModalOpenState(false);
            }} onCancel={() => {
                onModalOpenState(false)
            }}>
                <>
                    <Table
                        rowKey="id"
                        columns={columns}
                        dataSource={items}
                        pagination={false}
                    />
                </>
            </Modal >
        </>
    );
};