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, getMerchantSelectDevice, getStationSelect } from '@/services/merchant/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) => {
    props.onSubmit(values);
  };

  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="请输入卡名称"
          />
          <ProFormText
            name="amount"
            label={'金额'}
            colProps={{ md: 8, xl: 8 }}
            placeholder="请输入金额"
          />
          <ProFormText
            name="giveAmount"
            label={'赠送金额'}
            colProps={{ md: 12, xl: 12 }}
            placeholder="请输入最大功率"
          />
        </ProForm.Group>

        <ProForm.Group>
          <ProFormSelect
            name="merchantId"
            label={'选择商户'}
            colProps={{ md: 8, xl: 8 }}
            placeholder="请选择商户"
            fieldProps={
              {
                fieldNames: {
                  label: 'label',
                  value: 'id'
                },
              }
            }
            request={async () => {
              let { data } = await getMerchantSelect()
              return data
            }}
          />
          <ProFormSelect
            name="stationId"
            label={'选择电站'}
            colProps={{ md: 8, xl: 8 }}
            placeholder="请选择电站"
            fieldProps={
              {
                fieldNames: {
                  label: 'label',
                  value: 'id'
                },
              }
            }
            request={async () => {
              let { data } = await getStationSelect()
              return data
            }}
          />
        </ProForm.Group>
        {/* <ProFormRadio.Group
          name="status"
          options={[
            {
              label: '未使用',
              value: 0,
            },
            {
              label: '发布',
              value: 1,
            },
            {
              label: '取消发布',
              value: 2,
            },
          ]}
          label={'业务状态'}
          colProps={{ md: 12, xl: 12 }}
        /> */}
      </ProForm>
    </Modal>
  );
};

export default UserForm;
