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>
          <ProFormSelect
            name="deviceId"
            label={'选择设备'}
            colProps={{ md: 8, xl: 8 }}
            placeholder="请选择设备"
            fieldProps={
              {
                fieldNames: {
                  label: 'label',
                  value: 'id'
                },
              }
            }
            request={async () => {
              let { data } = await getMerchantSelectDevice()
              return data
            }}
          />
          <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>
        <ProForm.Group>

          <ProFormText
            name="gunNo"
            label={'枪编号'}
            colProps={{ md: 12, xl: 12 }}
            placeholder="请输入枪编号"
          />
          <ProFormText
            name="gunName"
            label={'枪名称'}
            colProps={{ md: 8, xl: 8 }}
            placeholder="请输入枪名称"
          />
          <ProFormText
            name="maxPower"
            label={'最大功率'}
            colProps={{ md: 12, xl: 12 }}
            placeholder="请输入最大功率"
          />
          <ProFormText
            name="maxVoltage"
            label={'最大电压'}
            colProps={{ md: 12, xl: 12 }}
            placeholder="请输入最大电压"
          />
        </ProForm.Group>
        <ProFormRadio.Group
          name="status"
          options={[
            {
              label: '启用',
              value: 1,
            },
            {
              label: '禁用',
              value: 2,
            },
          ]}
          label={'状态'}
          colProps={{ md: 12, xl: 12 }}
        />
        <ProFormRadio.Group
          name="businessStatus"
          options={[
            {
              label: '未使用',
              value: 0,
            },
            {
              label: '充电中',
              value: 1,
            },
            {
              label: '预约中',
              value: 2,
            },
          ]}
          label={'业务状态'}
          colProps={{ md: 12, xl: 12 }}
        />
      </ProForm>
    </Modal>
  );
};

export default UserForm;
