import React, { useState, useEffect } from 'react';
import { Modal, Form, Input, Button, Select, Switch, InputNumber } 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="vertical"
        preserve={false}
        initialValues={props.values}
        onFinish={props.onFinish}
      >
        <Form.Item name="id" hidden={true}>
          <Input />
        </Form.Item>
        <Form.Item name="code" label="配方编码" >
          <Input placeholder="配方编码" />
        </Form.Item>
        <Form.Item name="name" label="配方名称" >
          <Input placeholder="配方名称" />
        </Form.Item>
        <Form.Item name="bomTypeList" label="配方类型" >
          <Select
             mode="multiple"
             allowClear >
            {props?.bomtype?.map((item, index) => {
              return (
                <Select.Option index={item.id} value={item.id} key={item.id}>
                  {item.name}
                </Select.Option>
              );
            })}
          </Select>
        </Form.Item>
        <Form.Item name="isMain" label="配方类型" >
          <Switch checkedChildren="主料" unCheckedChildren="辅料" />
        </Form.Item>
        <Form.Item name="sort" label="排序" >
          <InputNumber placeholder="排序" min={1} />
        </Form.Item>
        <Form.Item>
          <Button type="primary" htmlType="submit">
            保存
          </Button>
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default CreateForm;
