import React from 'react';
import {
  ProFormSelect,
  ProFormText,
  ModalForm,
  ProFormDependency
} from '@ant-design/pro-form';
import { useIntl, FormattedMessage } from 'umi';


const UpdateForm = (props) => {
  const { updateModalVisible, updateModalVisibleChange, values, onSubmit } = props;
  // console.log({values});
  return (
    <>
      {
        JSON.stringify(values) !== '{}' && <ModalForm
          title="编辑医院"
          width="800px"
          initialValues={{ ...values }}
          labelCol={{ span: 5, offset: 3 }}
          layout={'horizontal'}
          visible={updateModalVisible}
          onVisibleChange={(visible) => updateModalVisibleChange(visible)}
          onFinish={(value) => onSubmit({ ...values, ...value })}
        >
          <ProFormText
            label="责任中心名"
            rules={[
              {
                required: true,
                message: (
                  <FormattedMessage id="pages.searchTable.responsibilityName" defaultMessage="医院名是必填项" />
                ),
              },
            ]}
            width="sm"
            name="responsibilityName"
          />
          <ProFormSelect
            rules={[
              {
                required: true,
                message: (
                  <FormattedMessage id="pages.searchTable.isGatherCenter" defaultMessage="请选择是否为汇总中心" />
                ),
              },
            ]}
            options={[
              {
                value: 1,
                label: '是',
              },
              {
                value: 0,
                label: '否',
              },
            ]}
            width="sm"
            name="isGatherCenter"
            label="是否汇总中心"
          />
          <ProFormSelect
            rules={[
              {
                required: true,
                message: (
                  <FormattedMessage id="pages.searchTable.responsibilityType" defaultMessage="请选择责任类型" />
                ),
              },
            ]}
            options={[
              {
                value: 1,
                label: '收费中心',
              },
              {
                value: 2,
                label: '成本(费用)中心',
              },
            ]}
            width="sm"
            name="responsibilityType"
            label="选择责任类型"
          />
          <ProFormSelect
            rules={[
              {
                required: true,
                message: (
                  <FormattedMessage id="pages.searchTable.shareLevel" defaultMessage="请选择分摊级别" />
                ),
              },
            ]}
            options={[
              {
                value: 1,
                label: '收费中心',
              },
              {
                value: 2,
                label: '成本(费用)中心',
              },
            ]}
            width="sm"
            name="shareLevel"
            label="选择分摊级别"
          />

          <ProFormDependency name={['shareLevel']}>
            {({ label }) => {
              return label ? (
                <ProFormText
                  initialValue={label}
                  label="主医院名称"
                  rules={[
                    {
                      required: false,
                      message: (
                        <FormattedMessage id="pages.searchTable.parentName" defaultMessage="..." />
                      ),
                    },
                  ]}
                  width="sm"
                />
              ) : <></>;
            }}
          </ProFormDependency>
        </ModalForm>
      }
    </>
  );
};

export default UpdateForm;
