/**
 * @Classname ConfigSearchForm
 * @Description TODO
 * @Date 2019/8/23 14:12
 * @Created by Administrator
 * 配置表格上的搜索框
 */

import React from 'react';
import * as PropTypes from 'prop-types';
import { Button, Form, Input, Select } from 'antd';
import TuonSelect from '../../../components/widget/TuonSelect';

class ConfigSearchForm extends React.Component {

    static propTypes = {
        fData: PropTypes.object,
        onRefresh: PropTypes.func,
        onAdd: PropTypes.func,
        loading: PropTypes.bool,
        onSearch: PropTypes.func,
    };

    static defaultProps = {};

    constructor(props) {
        super(props);
        this.state = {};
        this.params = {};
    }

    componentDidMount() {

    }

    onRefresh = (refresh) => {
        refresh && this.props.form.resetFields();
        this.props.onRefresh(refresh);
    };

    onSearch() {
        let values = this.props.form.getFieldsValue();
        this.props.onSearch && this.props.onSearch(values);
    }

    render() {
        let { getFieldDecorator } = this.props.form;
        let { cApps, cProfiles } = this.props.fData;
        return (<Form layout="inline">
            <Form.Item>
                <Button loading={this.props.loading}
                        htmlType="button"
                        icon="sync"
                        onClick={() => this.onRefresh(true)}
                />
            </Form.Item>
            <Form.Item>
                <Button htmlType="button"
                        icon="plus"
                        onClick={this.props.onAdd}
                />
            </Form.Item>
            <Form.Item>
                {getFieldDecorator('application')(<TuonSelect placeholder="请选择应用系统" data={cApps}/>)}
            </Form.Item>

            <Form.Item>
                {getFieldDecorator('profile')(<TuonSelect placeholder="请选择应用环境" data={cProfiles}/>)}
            </Form.Item>
            <Form.Item>
                {getFieldDecorator('key')(<Input placeholder="请输入配置项"/>)}
            </Form.Item>
            <Form.Item>
                <Button type="primary" htmlType="button" icon="search"
                        loading={this.props.loading}
                        onClick={this.onSearch.bind(this)}
                />

            </Form.Item>
        </Form>);
    }

}


export default Form.create()(ConfigSearchForm);
