import React, { useEffect, useState } from 'react';
import {
  ProForm,
  ProFormDigit,
  ProFormText,
  ProFormRadio,
  ProFormSelect,
  ProFormCascader,
  ProFormTextArea,
  EditableProTable
} from '@ant-design/pro-components';
import { Form, Modal, Input } from 'antd';
import { useIntl, FormattedMessage } from '@umijs/max';
import { getMerchantSelect, getSiteTypeSelect } from '@/services/merchant/index'
import FilesManager from '@/components/FilesManage/index';


const UserForm: React.FC = (props: any) => {

  const [form] = Form.useForm();
  const { values } = props;





  useEffect(() => {
    form.resetFields();
    form.setFieldsValue(values);
  }, [form, props]);

  const intl = useIntl();
  const handleOk = () => {
    form.submit();
  };
  const handleCancel = () => {
    props.onCancel();
  };
  const handleFinish = async (values: any) => {
    let data = JSON.parse(JSON.stringify(values))
    if (!values.id) {
      delete data.merchantInfoUpdateParams
      data.merchantInfoAddParams = values.merchantInfoUpdateParams
    }
    props.onSubmit(data);
  };

  return (
    <Modal
      width={800}
      title={'比例配置'}
      open={props.open}
      forceRender
      destroyOnClose
      onOk={handleOk}
      onCancel={handleCancel}
    >
      <ProForm
        form={form}
        grid={true}
        submitter={false}
        layout="horizontal"
        onFinish={handleFinish}>
        <ProFormDigit
          name="id"
          label={'ID'}
          disabled
          hidden={true}
        />
        <ProForm.Group>

          <ProFormText
            name="name"
            label={'比例配置名称'}
            colProps={{ md: 12, xl: 12 }}
            placeholder="请输入比例配置名称"
          />
        </ProForm.Group>
        <ProForm.Group>
          <ProFormDigit
            name="electricityRate"
            label={'电费分成比例'}
            colProps={{ md: 12, xl: 12 }}
            placeholder="请输入电费分成比例"
            rules={[{ required: true, message: '请输入' }]}
          />
          <ProFormDigit
            name="serviceRate"
            label={'服务费分成比例'}
            colProps={{ md: 12, xl: 12 }}
            placeholder="请输入服务费分成比例"
            rules={[{ required: true, message: '请输入' }]}
          />
          <ProFormDigit
            name="configType"
            label={'配置类型'}
            colProps={{ md: 12, xl: 12 }}
            placeholder="请输入配置类型"
          />
        </ProForm.Group>
      </ProForm>
    </Modal>
  );
};

export default UserForm;
