// 库/框架 import React from 'react'; // 第三方组件 import { Form, TreeSelect } from 'antd'; // ant_components import BIInput from '@/ant_components/BIInput'; import BISelect from '@/ant_components/BISelect'; import BIButton from '@/ant_components/BIButton'; import BIRadio from '@/ant_components/BIRadio'; import BIDatePicker from '@/ant_components/BIDatePicker'; import BICheckbox from '@/ant_components/BICheckbox'; import BIForm from '@/ant_components/BIForm'; // components import OrgTreeSelect from '@/components/orgTreeSelect/index.tsx'; import AssociationSearch from '@/components/associationSearch/index.tsx'; import AssociationSearchFilter from '@/components/associationSearchFilter/index.tsx'; import NumberRange from '@/components/numberRange'; // 样式 import styles from './index.less'; // 工具 /* eslint-disable no-underscore-dangle */ // 基础搜索组件 class SearchView extends React.Component { _renderItem = (col) => { const { type, placeholder, options = [], style, disabled, className, render, componentAttr = {}, key } = col; switch (type) { case 'select': return ( { return (
{ this.props.form.setFieldsValue({ [`${key}`]: options.map((item) => { return `${item.id}`; }), }); }} onMouseDown={(e) => { e.preventDefault(); }} > 全选 {/* 反选功能 */} {/* { const result = this.props.searchForm[`${key}`] || []; const resultArr = options.filter( item => result.indexOf(`${item.id}`) < 0, ); this.props.form.setFieldsValue({ [`${key}`]: resultArr.map( item => `${item.id}`, ), }); }} onMouseDown={e => { e.preventDefault(); }} > 反选 */}
{menu}
); } : undefined } dropdownMenuStyle={componentAttr.dropdownStatus ? { borderTop: '1px solid #E1E1E1' } : null} > {options.map((option) => { return ( {option.name} ); })}
); case 'selectMult': return ( {options.map((option) => { return ( {option.name} ); })} ); case 'radio': return ( {options.map((option) => { return ( {option.name} ); })} ); case 'checkbox': return ( {options.map((option) => { return (
{option.name}
); })}
); case 'date': return ( ); case 'datetime': return ( ); case 'daterange': return ( ); case 'daterangetime': return ( ); case 'orgtree': return ( ); case 'usertree': return ( ); case 'associationSearch': return ( { return (
{ const res = await componentAttr.request(); const result = res.data.list.map((item) => { return { value: item.index, label: item.value, }; }); this.props.form.setFieldsValue({ [`${key}`]: result, }); }} onMouseDown={(e) => { e.preventDefault(); }} > 全选
{menu}
); } : undefined } dropdownMenuStyle={componentAttr.dropdownStatus ? { borderTop: '1px solid #E1E1E1' } : null} /> ); case 'associationSearchFilter': return ( { return triggerNode.parentNode; }} className={className || styles.itemContent} disabled={disabled} /> ); case 'numberRange': return ( ); case 'custom': return render(this.props.form); case 'tag': return ( ); case 'search': return ( ); // case 'advancedSearch': // return ( // // ); default: return ( ); } }; changeRange = (key, dates) => { if (dates.length !== 2) { return; } const newData = {}; newData[key] = dates; this.props.form.setFieldsValue(newData); }; _renderCol = (col) => { const { label, type, key, checkOption, className } = col; const { getFieldDecorator } = this.props.form; if (!key && type !== 'custom') { return null; } return (
{!!label &&
{label}
}
{type === 'custom' ? this._renderItem(col) : getFieldDecorator(key, checkOption)(this._renderItem(col))}
); }; _renderRow = (arr, index) => { const len = arr.length; let colClass = styles.colWrap; if (len > 1) { colClass += ` ${styles[`_${len}`]}`; } return (
{arr.map((col, i) => { return (
{this._renderCol(col)}
); })}
); }; render() { const { style, searchCols = [] } = this.props; return ( {searchCols.map((arr, index) => { return this._renderRow(arr, index); })}

高级搜索

); } } function mapPropsToFields(props) { const { searchForm } = props; const returnObj = {}; if (!searchForm || typeof searchForm !== 'object') return returnObj; Object.keys(searchForm).forEach((item) => { let value = searchForm[item]; if (Array.isArray(searchForm[item])) { value = searchForm[item].slice(); } returnObj[item] = Form.createFormField({ value, }); }); return returnObj; } function onValuesChange(props, changedValues, allValues) { props.onChangeParams(props, changedValues, allValues); } export default Form.create({ name: 'search_view', mapPropsToFields, onValuesChange })(SearchView);