/*
 * @Note:
 * @Author: 2058827620@qq.com
 * @Date: 2022-04-03 17:02:15
 */

import { ProForm, ModalForm, ProFormRadio, ProFormText, ProFormTextArea, ProFormMoney, ProFormCaptcha } from '@ant-design/pro-components';
import { Button } from 'antd';
import { useEffect, useRef } from 'react';

import { smsSendcode } from '@/services/code';


export default ({ values, modalOpenState, onModalOpenState, typeMoney, onSubmit }) => {
  const restFormRef = useRef();

  useEffect(() => {
    restFormRef.current?.setFieldsValue(values);
  }, [values]);


  const handleFinish = async (formValues) => {
    await onSubmit(formValues);
    restFormRef.current?.resetFields();
  };

  return (
    <>
      <ModalForm
        title={typeMoney == '1' ? '投资人-基础收益' : '投资人-增值收益'}
        formRef={restFormRef}
        submitter={{
          searchConfig: {
            resetText: '重置',
          },
          resetButtonProps: {
            onClick: () => {
              restFormRef.current?.resetFields();
            },
          },
        }}
        initialValues={values}
        onFinish={handleFinish}
        open={modalOpenState}
        onOpenChange={onModalOpenState}
      >
        {/* <ProFormText hidden={true} width="md" name="id" /> */}
        <ProForm.Group>
          <ProFormText
            width="md"
            name="phone"
            label="手机号"
            placeholder="请输入"
            rules={[{ required: true, message: '请输入!' }]}
          />
          <ProFormText
            width="md"
            name="userName"
            label="用户名"
            placeholder="请输入"
            rules={[{ required: true, message: '请输入!' }]}
          />
        </ProForm.Group>

        <ProForm.Group>
          <ProFormCaptcha
            placeholder={'请输入验证码'}
            captchaTextRender={(timing, count) => {
              if (timing) {
                return `${count} ${'获取验证码'}`;
              }
              return '获取验证码';
            }}
            label="验证码"
            name="smsCode"
            rules={[
              {
                required: true,
                message: '请输入验证码！',
              },
            ]}
            onGetCaptcha={async () => {
              const { data } = await smsSendcode();
            }}
          />
        </ProForm.Group>
        <ProForm.Group>
          {/* <ProFormRadio.Group
            rules={[{ required: true, message: '请输入!' }]}
            name="money_type"
            label="积分类型"
            radioType="button"
            options={[
              {
                label: '消费积分',
                value: 'money2',
              },
              {
                label: '提现积分',
                value: 'money',
              },
            ]}
          /> */}
          <ProFormRadio.Group
            rules={[{ required: true, message: '请输入!' }]}
            name="type"
            label="类型"
            radioType="button"
            options={[
              {
                label: '线下充值',
                value: true,
              },
              {
                label: '余额划扣',
                value: false,
              },
            ]}
          />
          <ProFormMoney
            rules={[{ required: true, message: '请输入!' }]}
            label={typeMoney == '1' ? '基础收益' : '增值收益'}
            name="amount"
            customSymbol="￥"
          />

        </ProForm.Group>
        <ProFormTextArea
          rules={[{ required: true, message: '请输入' }]}
          width="md"
          name="remark"
          label="备注"
          placeholder="请输入"
        />
      </ModalForm>
    </>
  );
};

