import { paymentrefundPage } from '@/services/payment';


import React, { useRef, useEffect } from 'react';
import { useIntl, useAccess } from '@umijs/max';
import { message, Tag, Image, Button, Select } from 'antd';
import { ActionType, PageContainer, ProTable } from '@ant-design/pro-components';




const LogTableList: React.FC = () => {
    const actionRef = useRef<ActionType>();

    const columns = [
        {
            title: '支付ID',
            dataIndex: 'paymentId',
            valueType: 'text',
            search: true,
        },
        {
            title: '退款金额',
            dataIndex: 'refundAmount',
            valueType: 'text',
            search: false,
        },
        {
            title: '退款单号',
            dataIndex: 'refundNo',
            valueType: 'text',
            search: false,
        },
        {
            title: '平台',
            dataIndex: 'platformId',
            valueType: 'text',
            search: false,
        },
        {
            title: '退款完成时间',
            dataIndex: 'completeTime',
            valueType: 'text',
            search: false,
        },
        {
            title: '状态',
            dataIndex: 'status',
            valueType: 'text',
            search: true,
            render: (_: any, record: any) => {
                let colors = ['gold', 'green', 'volcano', 'red', 'magenta']
                return <Tag color={colors[record.status]}>{record.status == 0 ? '提交退款' : record.status == 1 ? '处理中' : record.status == 2 ? '退款完成' : record.status == -1 ? '退款失败' : ''}</Tag>
            },
            renderFormItem: (
                _,
                { type, defaultRender, formItemProps, fieldProps, ...rest },
                form,
            ) => {
                const statusMap = [
                    { label: '提交退款', value: 0 },
                    { label: '处理中', value: 1 },
                    { label: '退款完成', value: 2 },
                    { label: '退款失败', value: -1 },
                ]
                return <Select
                    {...fieldProps}
                    allowClear
                    style={{ width: "100%" }}
                    filterOption={false}
                    fieldNames={{
                        label: "label",
                        value: "value"
                    }}
                    options={statusMap}
                />
            },
        },
        {
            title: '备注',
            dataIndex: 'remarks',
            valueType: 'text',
            search: false,
        },
        {
            title: '操作人',
            dataIndex: 'operatorUser',
            valueType: 'text',
            search: false,
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
            valueType: 'text',
            search: false,
        },
    ];

    return (
        <PageContainer>
            <div style={{ width: '100%', float: 'right' }}>
                <ProTable
                    actionRef={actionRef}
                    rowKey="id"
                    key="logList"
                    search={{
                        labelWidth: 120,
                    }}
                    request={async (params, sorter, filter) => {
                        let { data } = await paymentrefundPage(params)
                        return {
                            data: data?.records || [],
                            total: data?.total,
                        };
                    }}
                    columns={columns}
                />
            </div>
        </PageContainer>
    );
};

export default LogTableList;
