import React, { useMemo } from 'react'; import classnames from 'classnames'; import { Button as BIButton, Checkbox, Form, Row, Col, } from 'antd'; // base-component import Input from './baseComponent/input'; import DatePicker from './baseComponent/date'; import RangePicker from './baseComponent/rangePicker'; import Search from './baseComponent/selectSearch' import Filter from '../filterCondition'; import styles from './styles.less'; export type searchCols = { key: string; type: string; label?: string | undefined; span?: number | undefined; // 控件站位宽度 expand?: boolean | undefined; // 是否折叠 itemAttr?: any; // 设置form.item, antd全量设 } interface Props { searchCols?: searchCols[]; advancedSearchCols?: searchCols[]; searchForm?: any; search?: Function; onChangeParams?: Function onResert: Function onSubmit: Function } const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 }, }; const SearchForm = (props: Props) => { const [form] = Form.useForm(); const { searchCols = [], advancedSearchCols, searchForm } = props; const onValuesChange = (changedValues: any, allValues: any) => { if (props.onChangeParams) { console.log(allValues) props.onChangeParams(changedValues, allValues) } } const _renderItem = (col: any) => { const { type, placeholder, options = [], style, disabled, className, render, componentAttr = { width: 320 }, key } = col; switch (type) { case 'checkbox': return ( {options.map((option: any) => { return (
{option.name}
); })}
); case 'date': return ( ); case 'daterange': return ( ); case 'search': return ( ); default: return ( ); } }; const getFields = () => { const children = searchCols.map((ls: searchCols, i) => { const { label } = ls; const node = _renderItem(ls); return ( {!!label &&
{label}
}
{node ? ( {node} ) : null}
) }) return children; } const fields = useMemo(getFields, [searchCols]) const onResert = () => { form.resetFields(); if (props.onResert) { props.onResert(); } } return (
{fields}
{/* 已选条件、搜索按钮 */}
) } export default SearchForm