import {
    ModalForm,
    ProFormText,
    ProFormInstance,
    ProForm,
    ProFormRadio,
} from '@ant-design/pro-components';
import { message } from 'antd';
import { useRef, useEffect } from 'react';
import { adminCharge } from '@/services/order/index';




export default ({ id, setModalVisit, modalVisit }) => {
    const restFormRef = useRef<ProFormInstance>();
    if(id){
        restFormRef.current?.setFieldsValue({ userId:id });
    }
    useEffect(() => {
        if(id){
            restFormRef.current?.setFieldsValue({ userId:id });
        }
    }, [id]);
    return (
        <>
            <ModalForm
                formRef={restFormRef}
                width={450}
                title="余额-变更"
                open={modalVisit}
                onFinish={async (data) => {
                    adminCharge(data).then((res) => {
                        message.success('变更成功')
                        restFormRef.current?.resetFields();
                        setModalVisit(false)
                    })
                }}
                onOpenChange={async (e) => {
                    setModalVisit(e)
                }}
            >
                <ProFormText
                    label="用户ID"
                    name="userId"
                    disabled
                />
                <ProForm.Group>
                    <ProFormRadio.Group
                        rules={[{ required: true, message: '请输入!' }]}
                        name="type"
                        label="类型"
                        radioType="button"
                        options={[
                            {
                                label: '充值',
                                value: '1',
                            },
                            {
                                label: '划扣',
                                value: '2',
                            },
                        ]}
                    />
                </ProForm.Group>
                <ProFormText
                    name="refundAmount"
                    label="金额"
                    placeholder='请输入金额'
                />
            </ModalForm>
        </>
    );
};