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


import React, { useRef, useEffect,useState } 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';
import { usersPage } from '@/services/user/user';



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


    const [shopOption, setShopOption] = useState([]);
    const searchShop = async (value) => {
        const { success, data } = await usersPage({
            userId: value
        });
        data.records.map((i) => {
            i.userName = i.userName + ' ' + i.phone
        })
        setShopOption(data.records)
    }

    const columns = [
        {
            title: '支付号',
            dataIndex: 'paymentNo',
            valueType: 'text',
            search: true,
        },
        {
            title: '用户信息',
            dataIndex: 'userId',
            valueType: 'text',
            render: (_: any, record: any) => {
                return <div>
                    <div>用户ID:{record?.userId}</div>
                    <div>用户名：{record?.userName}</div>
                    <div>手机号：{record?.phone}</div>
                    <div>用户等级：{record?.level}</div>
                </div>
            },
            renderFormItem: (
                _,
                { type, defaultRender, formItemProps, fieldProps, ...rest },
                form,
            ) => {
                return <Select
                    {...fieldProps}
                    allowClear
                    showSearch
                    placeholder="请输入用户名或手机号"
                    style={{ width: "100%" }}
                    filterOption={false}
                    onSearch={
                        (e) => {
                            if (!e) {
                                return;
                            }
                            searchShop(e);
                        }
                    }
                    fieldNames={{
                        label: "userName",
                        value: "id"
                    }}
                    options={shopOption}
                />
            },
        },
        {
            title: '支付类型',
            dataIndex: 'payType',
            valueType: 'text',
            search: true,
            render: (_: any, record: any) => {
                let color = record.payType == 1 ? 'volcano' : record.payType == 2 ? 'orange' : 'red'
                return <Tag color={color}>{record.payType == 1 ? '支付宝' : record.payType == 2 ? '微信' : '-'}</Tag>
            },
            renderFormItem: (
                _,
                { type, defaultRender, formItemProps, fieldProps, ...rest },
                form,
            ) => {
                const statusMap = [
                    { label: '支付宝', value: 1 },
                    { label: '微信', value: 2 },
                ]
                return <Select
                    {...fieldProps}
                    allowClear
                    style={{ width: "100%" }}
                    filterOption={false}
                    fieldNames={{
                        label: "label",
                        value: "value"
                    }}
                    options={statusMap}
                />
            },
        },
        {
            title: '业务类型',
            dataIndex: 'businessType',
            valueType: 'text',
            search: false,
            render: (_: any, record: any) => {
                let color = record.businessType == 1 ? 'volcano' : record.businessType == 2 ? 'orange' : 'red'
                return <Tag color={color}>{record.businessType == 1 ? '钱包充值' : record.businessType == 2 ? '购买商品' : '-'}</Tag>
            }
        },
        {
            title: '支付通道',
            dataIndex: 'platform',
            valueType: 'text',
            search: true,
            render: (_: any, record: any) => {
                let color = record.platform == 1 ? 'volcano' : record.platform == 2 ? 'orange' : 'red'
                return <Tag color={color}>{record.platform == 1 ? '上海汇付' : record.platform == 2 ? '京东支付' : record.platform == 3 ? '微信' : record.platform == 4 ? '金钱吧' : ''}</Tag>
            },
            renderFormItem: (
                _,
                { type, defaultRender, formItemProps, fieldProps, ...rest },
                form,
            ) => {
                const statusMap = [
                    { label: '上海汇付', value: 1 },
                    { label: '支付宝', value: 2 },
                    { label: '微信', value: 3 },
                    { label: '金钱吧', value: 4 },
                ]
                return <Select
                    {...fieldProps}
                    allowClear
                    style={{ width: "100%" }}
                    filterOption={false}
                    fieldNames={{
                        label: "label",
                        value: "value"
                    }}
                    options={statusMap}
                />
            },
        },
        {
            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: '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 paymentPage(params)
                        return {
                            data: data?.records || [],
                            total: data?.total,
                        };
                    }}
                    columns={columns}
                />
            </div>
        </PageContainer>
    );
};

export default LogTableList;
