import { refundPage } from '@/services/payment/index';


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




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

    const columns: any = [
        {
            title: 'ID',
            dataIndex: 'id',
            valueType: 'text',
            search: false,
        },
        {
            title: '支付ID',
            dataIndex: 'paymentId',
            valueType: 'text',
            search: false,
        },
        {
            title: '退款金额',
            dataIndex: 'refundAmount',
            valueType: 'text',
            search: false,
        },
        {
            title: '退款单号',
            dataIndex: 'refundNo',
            valueType: 'text',
            search: false,
        },
        {
            title: '退款完成时间',
            dataIndex: 'completeTime',
            valueType: 'text',
            search: false,
        },
        {
            title: '支付类型',
            dataIndex: 'payType',
            valueType: 'text',
            render: (_,data) => {
                return data.payment.payType == 1 ? <Tag color="green">微信小程序</Tag> : data.payment.payType == 2 ? <Tag color="blue">支付宝小程序</Tag> : data
            },
            renderFormItem: (
                _,
                { type, defaultRender, formItemProps, fieldProps, ...rest },
                form,
            ) => {
                return <Select
                    {...fieldProps}
                    allowClear
                    placeholder="请选择支付类型"
                    style={{ width: "100%" }}
                    filterOption={false}
                    fieldNames={{
                        label: "name",
                        value: "id"
                    }}
                    options={[
                        {
                            name: '微信小程序',
                            id: 1
                        },
                        {
                            name: '支付宝小程序',
                            id: 2
                        },
                    ]}
                />
            },
        },
        {
            title: '状态',
            dataIndex: 'status',
            valueType: 'text',
            render: (_: any, record: any) => {
                // 0-待支付;1-处理中;2-支付完成; -1支付失败;
                return _ == 0 ? '待处理' : _ == 1 ? '处理中' : _ == 2 ? '退款完成' : _ == -1 ? '退款失败' : _
            },
            renderFormItem: (
                _,
                { type, defaultRender, formItemProps, fieldProps, ...rest },
                form,
            ) => {
                return <Select
                    {...fieldProps}
                    allowClear
                    placeholder="请选择状态"
                    style={{ width: "100%" }}
                    filterOption={false}
                    fieldNames={{
                        label: "name",
                        value: "id"
                    }}
                    options={[
                        {
                            name: '待支付',
                            id: 0
                        },
                        {
                            name: '处理中',
                            id: 1
                        },
                        {
                            name: '退款完成',
                            id: 2
                        },
                        {
                            name: '退款失败',
                            id: -1
                        },
                    ]}
                />
            },
        },
        {
            title: '来源',
            dataIndex: 'sourceType',
            valueType: 'text',
            render: (_: any, record: any) => {
                // 来源类型:1-订单预付;2-钱包;3-电卡购买
                return _ == 1 ? '订单预付' : _ == 2 ? '钱包' : _ == 3 ? '电卡购买' : _
            },
            renderFormItem: (
                _,
                { type, defaultRender, formItemProps, fieldProps, ...rest },
                form,
            ) => {
                return <Select
                    {...fieldProps}
                    allowClear
                    placeholder="请选择来源"
                    style={{ width: "100%" }}
                    filterOption={false}
                    fieldNames={{
                        label: "name",
                        value: "id"
                    }}
                    options={[
                        {
                            name: '订单预付',
                            id: 1
                        },
                        {
                            name: '钱包',
                            id: 2
                        },
                        {
                            name: '电卡购买',
                            id: 3
                        },
                    ]}
                />
            },
        },
        {
            title: '退款原因',
            dataIndex: 'refundReason',
            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,
                        defaultCollapsed: false,
                    }}
                    request={async (params, sorter, filter) => {
                        let { data } = await refundPage(params)
                        return {
                            data: data?.records || [],
                            total: data?.total,
                        };
                    }}
                    columns={columns}
                />
            </div>
        </PageContainer>
    );
};

export default LogTableList;
