|
|
|
@ -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) : ''))
|
|
|
|
|