import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; import { Input, Select, Button, Icon } from 'antd'; import styles from './index.less'; export default class DataSearch extends PureComponent { static propTypes = { size: PropTypes.string, select: PropTypes.bool, selectProps: PropTypes.object, onSearch: PropTypes.func, selectOptions: PropTypes.array, style: PropTypes.object, keyword: PropTypes.string, } constructor(props) { super(props); const { select, selectProps, keyword } = this.props; this.state = { selectValue: select && selectProps ? selectProps.defaultValue : '', inputValue: keyword ? keyword : '', } } handleSearch = () => { const query = { keyword: this.state.inputValue }; if (this.props.select) { query.field = this.state.selectValue; } this.props.onSearch && this.props.onSearch(query); } handleSelectChange = (value) => { this.setState({ ...this.state, selectValue: value, }); } handleInputChange = (e) => { this.setState({ ...this.state, inputValue: e.target.value, }); } handleClearInput = () => { this.setState({ inputValue: '', }, () => this.handleSearch()); } render() { const { size, select, selectOptions, selectProps, style } = this.props; const { inputValue } = this.state; const suffix = inputValue ? : null; return ( {select && } ); } }