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

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

import services from '@/services/admin';
const { smsSendcode } = services.SmsController;

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

  return (
    <>
      <ModalForm
        title="订单-下单"
        formRef={restFormRef}
        submitter={{
          searchConfig: {
            resetText: '重置',
          },
          resetButtonProps: {
            onClick: () => {
              restFormRef.current?.resetFields();
            },
          },
        }}
        onFinish={onSubmit}
        open={modalOpenState}
        onOpenChange={onModalOpenState}
      >
        <div className='text-red-600'>
          <div>单个订单限购100台，如需更多请多次下单</div>
        </div>
        <ProForm.Group>
          <ProFormText
            rules={[{ required: true, message: '请输入' }]}
            width="md"
            name="username"
            label="用户名"
            placeholder="请输入"
          />
          <ProFormText
            rules={[{ required: true, message: '请输入' }]}
            width="md"
            name="mobile"
            label="手机号"
            placeholder="请输入"
          />
        </ProForm.Group>
        <ProForm.Group>
          <ProFormDigit
            rules={[{ required: true, message: '请输入' }]}
            label="购买数量"
            name="num"
            min={1}
            max={100}
          />
          <ProFormCaptcha
            placeholder={'请输入验证码'}
            captchaTextRender={(timing, count) => {
              if (timing) {
                return `${count} ${'获取验证码'}`;
              }
              return '获取验证码';
            }}
            label="验证码"
            name="code"
            rules={[
              {
                required: true,
                message: '请输入验证码！',
              },
            ]}
            onGetCaptcha={async () => {
              const { data } = await smsSendcode();
            }}
          />
        </ProForm.Group>

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

