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="stockGoodsCode"
          label="原料名称"
          rules={[{ required: true, message: '请选择原料名称' }]}
        >
          <Select placeholder="请选择原料名称">
            {props.stockGoodsData.map((item, index) => {
              return (
                <Select.Option index={index} value={item.id} key={item.id}>
                  {item.name}
                </Select.Option>
              );
            })}
          </Select>
        </Form.Item>
        <Form.Item name="bomQty" label="配方用量" defaultValue={props.values.bomQty}>
          <InputNumber placeholder="配方用量" min={0} />
        </Form.Item>
        <Form.Item name="isMain" label="主要原料" >
          <Switch checkedChildren="否" unCheckedChildren="是" defaultChecked />
        </Form.Item>
        <Form.Item name="isReplace" label="是否可以替换" >
          <Switch checkedChildren="否" unCheckedChildren="是" defaultChecked />
        </Form.Item>
        <Form.Item>
          <Button type="primary" htmlType="submit">
            保存
          </Button>
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default CreateForm;
