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




export default ({ id, setModalVisit, modalVisit }) => {
    const restFormRef = useRef<ProFormInstance>();
    restFormRef.current?.setFieldsValue({ id });
    useEffect(() => {
        restFormRef.current?.setFieldsValue({ id });
    }, [id]);
    return (
        <>
            <ModalForm
                formRef={restFormRef}
                width={450}
                title="订单-退单"
                open={modalVisit}
                onFinish={async (data) => {
                    refundAmount(data).then((res) => {
                        message.success('退单成功')
                        restFormRef.current?.resetFields();
                        setModalVisit(false)
                    })
                }}
                onOpenChange={async (e) => {
                    setModalVisit(e)
                    restFormRef.current?.resetFields();
                }}
            >
                <ProFormText
                    label="ID"
                    name="id"
                    disabled
                />
                <ProFormText
                    name="refundAmount"
                    label="退款金额"
                    placeholder='请输入退款金额'
                />
            </ModalForm>
        </>
    );
};