import React, { useState, useEffect } from 'react';
import { InputNumber, Modal, Form, Input, Button, Select } from 'antd';
import { GetBatchingAsync } from '../services';

const CreateForm = (props) => {
  const { Option, OptGroup } = Select;
  const [batchingList, setBatchingList] = useState([]);
  console.log('ffgbvc', props.Store_Id);
  //原料
  //初始化数据
  useEffect(() => {
    const initBatching = () => {
      GetBatchingAsync({ Store_Id: props.Store_Id }).then((data) => {
        setBatchingList(data.data);
      });
    };
    initBatching();
  }, []);
  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="batching_Id"
          label="原料名称"
          rules={[{ required: true, message: '请选择原料名称' }]}
        >
          <Select placeholder="请选择原料名称">
            {batchingList.map((item, index) => {
              return (
                <Select.Option index={index} value={item.id} key={item.id}>
                  {item.name}
                </Select.Option>
              );
            })}
          </Select>
        </Form.Item>
        <Form.Item
          name="batching_Loc"
          label="库存位置"
          rules={[{ required: true }]}
          defaultValue="0"
        >
          <Input placeholder="输入库存位置编码" />
        </Form.Item>
        <Form.Item
          name="batching_Count"
          label="原料数量"
          rules={[{ required: true }]}
          defaultValue="0"
        >
          <InputNumber min={0} placeholder="请输入原料数量" />
        </Form.Item>

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

export default CreateForm;
