import React, { useState, useEffect } from 'react';
import { Modal, Form, Input, Button, Select, TreeSelect } from 'antd';

const CreateForm = (props) => {
  const { Option, OptGroup } = Select;
  return (
    <Modal
      title={props.values.id ? '编辑' : '新建'}
      width={640}
      visible={props.createModalVisible}
      bodyStyle={{ padding: '32px 40px 48px' }}
      footer={null}
      onCancel={() => {
        props.onCancel();
      }}
      destroyOnClose
    >
      <Form
        layout="Horizontal"
        labelCol={{ span: 4 }}
        preserve={false}
        initialValues={props.values}
        onFinish={props.onFinish}
      >
        <Form.Item name="id" hidden={true}>
          <Input />
        </Form.Item>

        <Form.Item label={'店铺名称'} name="store_Name" rules={[{ required: true }]}>
          <Input />
        </Form.Item>

        <Form.Item label={'店铺地址'} name="store_Addr" rules={[{ required: true }]}>
          <Input />
        </Form.Item>

        <Form.Item label={'联系电话'} name="store_Tel" rules={[{ required: true }]}>
          <Input placeholder="多个手机号用,分隔" />
        </Form.Item>

        <Form.Item label={'状态'} name="store_Status" rules={[{ required: true }]}>
          <Select placeholder="请选择状态">
            <OptGroup>
              <Select.Option value={0}>正常</Select.Option>
              <Select.Option value={1}>停用</Select.Option>
            </OptGroup>
          </Select>
        </Form.Item>
        <Form.Item label={'设备分类'} name="storeTypeKey" rules={[{ required: true }]}>
        <Select>
            { props.dicData.map((item, index) => {
              return (
                <Select.Option index={index} value={item.id} key={item.id}>
                  {item.text}
                </Select.Option>
              );
            })}
          </Select>
        </Form.Item>
        <Form.Item label={'图标'} name="store_ImgUrl" rules={[{ required: true }]}>
          <Input />
        </Form.Item>

        <Form.Item label={'坐标'} name="store_Loc" rules={[{ required: true }]}>
          <Input />
        </Form.Item>

        <Form.Item label={'类型'} name="store_TypeId" rules={[{ required: true }]}>
          <Select>
            {props.storeType.map((item, index) => {
              return (
                <Select.Option index={index} value={item.id} key={item.id}>
                  {item.text}
                </Select.Option>
              );
            })}
          </Select>
        </Form.Item>
        <Form.Item name="orgId" label="所属机构" rules={[{ required: true }]}>
          <TreeSelect
            style={{ width: '100%' }}
            dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
            treeData={props.OrgData}
            placeholder="请选择所属机构"
            treeDefaultExpandAll
          />
        </Form.Item>
        <Form.Item label={'等级'} name="store_LevelId" rules={[{ required: true }]}>
          <Select>
            {props.storeLevel.map((item, index) => {
              return (
                <Select.Option index={index} value={item.id} key={item.id}>
                  {item.text}
                </Select.Option>
              );
            })}
          </Select>
        </Form.Item>

        <Form.Item>
          <Button type="primary" htmlType="submit">
            保存
          </Button>
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default CreateForm;
