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

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

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

  useEffect(() => {

    restFormRef.current?.setFieldsValue(values);
  }, [values]);

  return (
    <>
      <ModalForm
        title="用户-编辑"
        width={500}
        formRef={restFormRef}
        submitter={{
          searchConfig: {
            resetText: '重置',
          },
          resetButtonProps: {
            onClick: () => {
              restFormRef.current?.resetFields();
            },
          },
        }}
        initialValues={values}
        onFinish={onSubmit}
        open={modalOpenState}
        onOpenChange={onModalOpenState}
      >
        <ProFormText hidden={true} width="md" name="id" />
        <ProForm.Group>
          <ProFormRadio.Group
            rules={[{ required: true, message: '请输入' }]}
            name="type"
            label="类型"
            radioType="button"
            fieldProps={{
              defaultValue: "+"
            }}
            options={[
              {
                label: '增加',
                value: '+',
                checked: true
              },
              {
                label: '减少',
                value: '-',
              }
            ]}
          />
          <ProFormDigit
            rules={[{ required: true, message: '请输入' }]}
            label="积分"
            name="integral"
            min={1}
            fieldProps={{
              precision: 0
            }}
          />
        </ProForm.Group>

      </ModalForm>
    </>
  );
};

