import React, { Component } from 'react';
import {Form, Input, Button, Row, Col, Select} from 'antd';
import styles from './Department.less';
import index from '../../../pages/index.css';
import commonStyles from '../../../pages/index.css';
import moment from 'moment';
import config from "@/config/config";

const FormItem = Form.Item;
const Option = Select.Option;

const DepartmentSearch = (props) => {

  const { onSearch, onReset } = props;
  const [form] = Form.useForm();
  const { getFieldsValue, getFieldValue, validateFields, setFieldsValue, resetFields } = form;

  const handleSearch = () => {
    let fields = getFieldsValue();
    const date = getFieldValue("createTime");
    if (date) {
      fields["createTime"] = moment(date).format("yyyy-MM-DD");
    }
    onSearch(fields)
  }

  const handleReset = () => {
    resetFields();
    onReset()
  }

  const formItemLayout = {
    labelCol: {span: 8},
    wrapperCol: {span: 16},
  }

  const iconStyle = {
    verticalAlign: "bottom",
    marginRight: "5px",
  }

  const statusOptions = config.DEPARTMENT_STATUS.map(item => <Option key={item.key} value={item.name}>{item.name}</Option>);

  return (
    <div className={commonStyles.singleRowSearch}>
      <Form form={form}>
        <Row className={index.formRowDiv}>
          <Col span={6}>
            <FormItem {...formItemLayout} label="部门名称" name={"userName"}>
              <Input placeholder="请输入部门名称" size="default"/>
            </FormItem>
          </Col>
          <Col span={6}>
            <FormItem {...formItemLayout} label='部门编号' name={"phoneNumber"}>
              <Input placeholder="请输入部门编号" size="default"/>
            </FormItem>
          </Col>
          <Col span={6}>
            <FormItem {...formItemLayout} label='状态' name={"createTime"}>
              <Select placeholder="请选择状态" style={{ width: "100%"}}>
                {statusOptions}
              </Select>
            </FormItem>
          </Col>
          <Col span={6}>
            <FormItem>
              <Button size="default" icon={<i className="ri-search-line" style={iconStyle}></i>} style={{marginLeft: "10px", border: "0px", background: window._THEMECOLOR_}} onClick={() => handleSearch()}>查询</Button>
              <Button size="default" icon={<i className="ri-restart-line" style={iconStyle}></i>} style={{marginLeft: "10px"}} onClick={() => handleReset()}>重置</Button>
            </FormItem>
          </Col>
        </Row>
      </Form>
    </div>
  );
};

export default DepartmentSearch;
