diff --git a/src/components/search/DatePickerCharts.jsx b/src/components/search/DatePickerCharts.jsx
index bb73445..d6dc4f0 100644
--- a/src/components/search/DatePickerCharts.jsx
+++ b/src/components/search/DatePickerCharts.jsx
@@ -7,6 +7,16 @@ import "moment/locale/zh-cn";
import locale from "antd/es/date-picker/locale/zh_CN";
import { stores_Context } from "../../config";
+// 1.0的搜索组件 不需要Form包裹
+const SectionWrapper = ({ isform, id, title, children, right, ...extProps }) =>
+ !isform ? (
+ <>{children}>
+ ) : (
+
+ {children}
+
+ );
+
// 用于日期选择,计算上一时间段、同比时间等
class DatePickerCharts extends Component {
static contextType = stores_Context;
@@ -17,17 +27,20 @@ class DatePickerCharts extends Component {
render() {
const { date_picker_store } = this.context;
+ const { isform } = this.props;
+ const defaultV = [date_picker_store.start_date, date_picker_store.end_date];
+ const defaultVdiff = [date_picker_store.start_date_cp, date_picker_store.end_date_cp];
return (
-
+
{
date_picker_store.onChange_dataPicker(e);
if (typeof this.props.onChange === 'function') {
@@ -46,19 +59,20 @@ class DatePickerCharts extends Component {
今年: [moment().startOf("year"), moment().endOf("year")],
去年: [moment().subtract(1, "year").startOf("year"), moment().subtract(1, "year").endOf("year")],
}}
- />
+ />
+
{this.props.hide_vs ? (
""
) : (
-
+
{
@@ -76,7 +90,7 @@ class DatePickerCharts extends Component {
前三个月: [moment().subtract(5, "month").startOf("month"), moment().subtract(3, "month").endOf("month")],
去年: [moment().subtract(1, "year").startOf("year"), moment().subtract(1, "year").endOf("year")],
}}
- />
+ />
)}
diff --git a/src/components/search/GroupSelect.jsx b/src/components/search/GroupSelect.jsx
index 0dc2fc6..24daa00 100644
--- a/src/components/search/GroupSelect.jsx
+++ b/src/components/search/GroupSelect.jsx
@@ -32,7 +32,7 @@ class GroupSelect extends Component {
{...extProps}
>
{_show_all ? (
-
+
所有小组
) : (
diff --git a/src/components/search/Input.jsx b/src/components/search/Input.jsx
new file mode 100644
index 0000000..2317d5c
--- /dev/null
+++ b/src/components/search/Input.jsx
@@ -0,0 +1,133 @@
+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 { objectMapper } from './../../utils/commons';
+
+const { Option } = Select;
+
+let timeout;
+let currentValue;
+
+function curl(opts, callback) {
+ if (timeout) {
+ clearTimeout(timeout);
+ timeout = null;
+ }
+ currentValue = opts.value;
+
+ function fake() {
+ // console.log(currentValue, opts.value);
+ if (currentValue === opts.value && opts.value === '空') {
+ const _p = [{ 'key': '0', 'label': '空' }];
+ return callback(_p);
+ }
+ const param = {
+ code: 'utf-8',
+ q: opts.value,
+ };
+ // const str = new URLSearchParams({
+ // code: 'utf-8',
+ // q: opts.value,
+ // }).toString();
+
+ fetchJSON(`${opts.url}`, param)
+ .then(d => {
+ if (currentValue === opts.value) {
+ const result = objectMapper(d.result, opts.map) || [];
+ callback(result);
+ }
+ });
+ }
+
+ timeout = setTimeout(fake, 300);
+}
+
+/**
+ * 异步请求的下拉菜单, 可搜索
+ * @property {array} defaultOptions 默认选项 [{key: '', label: '' }]
+ * @property {string} url
+ * @property {object} map 异步结果的字段转换定义
+ * @property {boolean} autoGet 首次默认请求
+ * @property {string} resultkey 结果的根字段
+ */
+class SearchInput extends React.Component {
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ data: this.props.defaultOptions || [],
+ value: undefined,
+ autoData: this.props.defaultOptions || [],
+ };
+ }
+
+ componentDidMount() {
+ if (this.props.autoGet === true) {
+ const { map, resultkey } = this.props;
+ const mapKey = Object.keys(map).reduce((r, v) => ({ ...r, [v]: { key: map[v] } }), {});
+ curl({ value: '', url: this.props.url || '', map: mapKey, resultkey }, (data) =>
+ this.setState({ data, autoData: data }, () => (typeof this.props.onSearchAfter === 'function' ? this.props.onSearchAfter(data, this.state.value) : ''))
+ );
+ }
+ }
+
+ componentDidUpdate(prevProps) {
+ if (this.props.value !== prevProps.value) {
+ this.setState({ value: undefined });
+ }
+ }
+
+ handleClear = () => {
+ this.setState({ data: this.state.autoData });
+ };
+
+ handleSearch = value => {
+ if ( ! this.props.url && this.props.defaultOptions?.length) {
+ const f = this.props.defaultOptions.filter(r => String(r.label).indexOf(value) !== -1);
+ this.setState({ data: f || [] });
+ return false;
+ }
+ const { map, resultkey } = this.props;
+ const mapKey = Object.keys(map).reduce((r, v) => ({ ...r, [v]: { key: map[v] } }), {});
+ if (value) {
+ curl({ value, url: this.props.url || '', map: mapKey, resultkey }, (data) =>
+ this.setState({ data }, () => (typeof this.props.onSearchAfter === 'function' ? this.props.onSearchAfter(data, this.state.value) : ''))
+ );
+ } else {
+ this.setState({ data: this.state.autoData || [] });
+ }
+ };
+
+ handleChange = (value, option) => {
+ this.setState({ value }, () => this.props.onChange(value, option));
+ };
+
+ render() {
+ const options = this.state.data.map(d => );
+ const { onSearchAfter, defaultOptions, autoGet, ...props } = this.props;
+ return (
+
+ );
+ }
+}
+export default observer(SearchInput);
diff --git a/src/components/search/SearchForm.jsx b/src/components/search/SearchForm.jsx
index 74d634e..02b0ad6 100644
--- a/src/components/search/SearchForm.jsx
+++ b/src/components/search/SearchForm.jsx
@@ -1,4 +1,5 @@
import { createContext } from 'react';
+import { toJS } from "mobx";
import { observer } from 'mobx-react';
import { DATE_FORMAT } from './../../config';
import { SearchOutlined, } from "@ant-design/icons";
@@ -11,7 +12,9 @@ import SiteSelect from './SiteSelect';
import DateTypeSelect from './DataTypeSelect';
import DatePickerCharts from './DatePickerCharts';
import YearPickerCharts from './YearPickerCharts';
+import SearchInput from './Input';
import { objectMapper, at } from './../../utils/commons';
+
import './search.css';
const EditableContext = createContext();
@@ -19,8 +22,12 @@ const Option = Select.Option;
/**
* 搜索表单
- * @property defaultValue
- * * { initialValue, fieldProps, hides, shows, sort }
+ * @property defaultValue { initialValue, fieldProps, hides, shows, sort }
+ * * {object} initialValue 默认值
+ * * {object} fieldProps 表单项属性
+ * * {array} hides 隐藏的表单项
+ * * {array} shows 显示的表单项
+ * * {object} sort 表单项排序
* @property onSubmit
*/
export default observer((props) => {
@@ -33,7 +40,6 @@ export default observer((props) => {
shows: [],
...props.defaultValue,
};
-
const { onSubmit } = props;
const onFinish = (values) => {
@@ -54,14 +60,14 @@ export default observer((props) => {
'DepartmentList': {
key: 'DepartmentList',
transform: (value) => {
- return Array.isArray(value) ? value.map((ele) => ele.key).join(',') : value ? (!isNaN(parseInt(value.key), 10) ? value.key : '') : '-1';
+ return Array.isArray(value) ? value.map((ele) => ele.key).join(',') : value ? value.key : 'ALL';
},
default: '',
},
'WebCode': {
key: 'WebCode',
transform: (value) => {
- return Array.isArray(value) ? value.map((ele) => ele.key).join(',') : value ? (!isNaN(parseInt(value.key), 10) ? value.key : '') : '-1';
+ return Array.isArray(value) ? value.map((ele) => ele.key).join(',') : value ? (value.key) : 'ALL';
},
default: '',
},
@@ -70,6 +76,11 @@ export default observer((props) => {
transform: (value) => value?.key || '',
default: '',
},
+ 'operator': {
+ key: 'operator',
+ transform: (value) => value?.key || '',
+ default: '',
+ },
'applyDate': [
{
key: 'Date1',
@@ -147,7 +158,7 @@ export default observer((props) => {