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

import { ProForm, ModalForm, ProFormSelect, ProFormText, ProFormDatePicker, ProFormRadio } from '@ant-design/pro-components';
import { Tree } from 'antd';
import { useEffect, useRef, useState } from 'react';
import FilesManager from '@/components/FilesManage/index';
// import services from '@/services/admin';

// const { shopLevelItems } = services.ShopLevelController;

// const { shopItems } = services.ShopController;


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

  const [shopOption, setShopOption] = useState([]);

  const searchShop = (e) => {
    console.log(e);
  }

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

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

  return (
    <>
      <ModalForm
        title="513活动-添加"
        formRef={restFormRef}
        submitter={{
          searchConfig: {
            resetText: '重置',
          },
          resetButtonProps: {
            onClick: () => {
              restFormRef.current?.resetFields();
            },
          },
        }}
        initialValues={values}
        onFinish={handleFinish}
        open={modalOpenState}
        onOpenChange={onModalOpenState}
      >
        <ProForm.Group>
          <ProFormText
            width="md"
            name="username"
            label="用户名"
            placeholder="请输入用户名"
            rules={[{ required: true, message: '请输入' }]}
          />
          <ProFormText
            width="md"
            name="mobile"
            label="手机号"
            placeholder="请输入手机号"
            rules={[{ required: true, message: '请输入手机号' },{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' }]}
          />
          <ProFormRadio.Group
            label="时间"
            name="m"
            initialValue="6月"
            rules={[{ required: true, message: '请选择' }]}
            options={[
              { label: '6月', value: '6月' },
              { label: '12月', value: '12月' },
              { label: '24月', value: '24月' },
              { label: '36月', value: '36月' },
              { label: '48月', value: '48月' },
              { label: '60月', value: '60月' },
            ]}
          />
          <ProFormText
            width="md"
            name={['info', 'car_name']}
            label="车辆型号"
            placeholder="请输入车辆型号"
          />
          <ProFormText
            width="md"
            name={['info', 'realname']}
            label="车主姓名"
            placeholder="请输入车主姓名"
          />
          <ProFormText
            width="md"
            name={['info', 'plate_code']}
            label="车牌号码"
            placeholder="请输入车牌号码"
          />
          <ProFormText
            width="md"
            name={['info', 'car_code']}
            label="车架号码"
            placeholder="请输入车架号码"
          />
          <ProFormText
            width="md"
            name={['info', 'bank_num']}
            label="还款卡号"
            placeholder="请输入还款卡号"
          />
          <ProFormText
            width="md"
            name={['info', 'bank_name']}
            label="银行名称"
            placeholder="请输入银行名称"
          />
          <ProFormText
            width="md"
            name={['info', 'todate']}
            label="还款日期"
            placeholder="请输入还款日期"
          />
        </ProForm.Group>
      </ModalForm>
    </>
  );
};

