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


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

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

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


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

        });
    }, [values]);

    const columns = [
        {
            "title": "ID",
            "dataIndex": "id"
        },
        {
            "title": "订单ID",
            "dataIndex": "ordersId"
        },
        {
            title: '订单号',
            dataIndex: 'orderNo',
        },
        {
            title: '金额',
            dataIndex: 'amount',
        },
        {
            title: '支付类型',
            dataIndex: 'type',
            render: (_: any, record: any) => {
                // 11-线上预付;12-;13-;\n14-;15-;16-;\n21-;22-;23-;\n31-;32-;33-;
                let data = [
                    { id: 11, name: '线上预付' },
                    { id: 12, name: '钱包预付' },
                    { id: 13, name: '刷卡预付' },
                    { id: 14, name: '线上后付' },
                    { id: 15, name: '钱包后付' },
                    { id: 16, name: '刷卡后付' },
                    { id: 21, name: '线上预付退款' },
                    { id: 22, name: '钱包预付退款' },
                    { id: 23, name: '刷卡预付退款' },
                    { id: 31, name: '线上退款' },
                    { id: 32, name: '钱包退款' },
                    { id: 33, name: '刷卡退款' },
                ]
                var findData = data.find((val) => val.id == record.type)
                return findData ? findData.name : '-'
            }
        },
        {
            title: '来源',
            dataIndex: 'sourceType',
            render: (_: any, record: any) => {
                // 1-支付记录;2-钱包记录;3-卡片记录;4-退款记录;
                return _ == 1 ? '支付记录' : _ == 2 ? '钱包记录' : _ == 3 ? '卡片记录' : _ == 4 ? '退款记录' : ''
            },
        },
        {
            "title": "状态",
            "dataIndex": "status",
            render: (_: any, record: any) => {
                return _ == 1 ? '处理中' : '处理成功'
            },
        },
        {
            "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 >
        </>
    );
};