diff --git a/src/components/search/Input.jsx b/src/components/search/Input.jsx index cbdbaac..d821b7c 100644 --- a/src/components/search/Input.jsx +++ b/src/components/search/Input.jsx @@ -1,7 +1,5 @@ import React from 'react'; import { Select } from 'antd'; -import querystring from 'querystring'; -// import * as oMapper from 'object-mapper'; import { fetchJSON } from './../../utils/request'; import { observer } from 'mobx-react'; import { isEmpty, merge, objectMapper } from './../../utils/commons'; @@ -19,7 +17,6 @@ function curl(opts, callback) { currentValue = opts.value; function fake() { - // console.log(currentValue, opts.value); if (currentValue === opts.value && opts.value === '空') { const _p = [{ 'key': '0', 'label': '空' }]; return callback(_p); @@ -29,11 +26,12 @@ function curl(opts, callback) { // code: 'utf-8', // q: opts.value, // }).toString(); + const resultkey = opts.resultkey || 'result'; fetchJSON(`${opts.url}`, param) .then(d => { if (currentValue === opts.value) { - const result = objectMapper(d.result, opts.map) || []; + const result = objectMapper(d[resultkey], opts.map) || []; callback(result); } }); @@ -65,7 +63,7 @@ class SearchInput extends React.Component { if (this.props.autoGet === true) { const { map, resultkey, dependenciesFun } = this.props; const param = typeof dependenciesFun === 'function' ? dependenciesFun() : {}; - const mapKey = Object.keys(map).reduce((r, v) => ({ ...r, [v]: { key: map[v] } }), {}); + const mapKey = Object.keys(map).reduce((r, v) => ({ ...r, [v]: typeof map[v] === 'string' ? { key: map[v] } : (map[v] || []).map(vi => ({ key: vi})) }), {}); curl({ value: '', url: this.props.url || '', map: mapKey, resultkey, param }, (data) => this.setState({ data, autoData: data }, () => (typeof this.props.onSearchAfter === 'function' ? this.props.onSearchAfter(data, this.state.value) : '')) ); @@ -90,7 +88,9 @@ class SearchInput extends React.Component { } const { map, resultkey, dependenciesFun } = this.props; const param = typeof dependenciesFun === 'function' ? dependenciesFun() : {}; - const mapKey = Object.keys(map).reduce((r, v) => ({ ...r, [v]: { key: map[v] } }), {}); + // const mapKey = Object.keys(map).reduce((r, v) => ({ ...r, [v]: { key: map[v] } }), {}); + const mapKey = Object.keys(map).reduce((r, v) => ({ ...r, [v]: typeof map[v] === 'string' ? { key: map[v] } : (map[v] || []).map(vi => ({ key: vi})) }), {}); + if (value || !isEmpty(param)) { curl({ value, url: this.props.url || '', map: mapKey, resultkey, param }, (data) => this.setState({ data }, () => (typeof this.props.onSearchAfter === 'function' ? this.props.onSearchAfter(data, this.state.value) : '')) diff --git a/src/components/search/SearchForm.jsx b/src/components/search/SearchForm.jsx index 47f7439..4f43365 100644 --- a/src/components/search/SearchForm.jsx +++ b/src/components/search/SearchForm.jsx @@ -62,7 +62,7 @@ export default observer((props) => { 'businessUnits': { key: 'businessUnits', transform: (value) => { - return Array.isArray(value) ? value.map((ele) => ele.key).join(',') : value ? (!isNaN(parseInt(value.key), 10) ? value.key : '') : ''; + return isEmpty(value) ? 'ALL': Array.isArray(value) ? value.map((ele) => ele.value).join(',') : value ? value.value : ''; }, default: '', }, @@ -148,6 +148,11 @@ export default observer((props) => { transform: (value) => value?.key || '', default: '', }, + 'billtype': { + key: 'billtype', + transform: (value) => isEmpty(value) ? 'ALL' : value?.key || '', + default: '', + }, }; let dest = {}; const { applyDate, applyDate2, year, yearDiff, dates, months, ...omittedValue } = values; @@ -242,6 +247,20 @@ function getFields(props) { }; let baseChildren = []; baseChildren = [ + item( + 'billtype', + 99, +