|
|
@@ -1,8 +1,6 @@
|
|
|
import React from 'react'
|
|
|
import PropTypes from 'prop-types'
|
|
|
-import { Modal, Form, Row, Col, Input, Icon, Button, Select, InputNumber, DatePicker, Spin, Tag,
|
|
|
- // Divider
|
|
|
-} from 'antd'
|
|
|
+import { Modal, Form, Row, Col, Input, Icon, Button, Select, InputNumber, DatePicker, Spin, Tag } from 'antd'
|
|
|
import OPERATORS from './filterOperators.js';
|
|
|
import './filterBox.less'
|
|
|
import * as service from '../../../services/index'
|
|
|
@@ -10,7 +8,8 @@ import URLS from '../../../constants/url'
|
|
|
import moment from 'moment'
|
|
|
const FormItem = Form.Item
|
|
|
const SelectOption = Select.Option
|
|
|
-const OptionGroup = Select.OptGroup
|
|
|
+const OptionGroup = Select.OptGroup
|
|
|
+const { RangePicker } = DatePicker
|
|
|
|
|
|
let uuid = Math.ceil(Math.random() * 1000);
|
|
|
class FilterBox extends React.Component {
|
|
|
@@ -140,6 +139,25 @@ class FilterBox extends React.Component {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 改变过滤条件的值(一次改两个)
|
|
|
+ */
|
|
|
+ changeFilterValues = (filter, values) => {
|
|
|
+ const { form } = this.props;
|
|
|
+ const filters = form.getFieldValue('filters');
|
|
|
+
|
|
|
+ form.setFieldsValue({
|
|
|
+ filters: filters.map((f) => {
|
|
|
+ if (f.key === filter.key) {
|
|
|
+ // f.key = uuid++;
|
|
|
+ f[`value1`] = values[0];
|
|
|
+ f[`value2`] = values[1];
|
|
|
+ }
|
|
|
+ return f;
|
|
|
+ })
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通过列名从数据列中获得其类型
|
|
|
*/
|
|
|
@@ -239,43 +257,69 @@ class FilterBox extends React.Component {
|
|
|
// let dropdownOpen = this.state['dropdownOpen-' + filter.key] || false;
|
|
|
let columnData = this.state['columnData-' + filter.name] || [];
|
|
|
|
|
|
- let defaultValue = type==='time' ? ( filter['value' + index] ? ( filter['value' + index].dynamic ? ( filter['value' + index] ) : moment(filter['value' + index]) ) : null ) : filter['value' + index]
|
|
|
- const commonProps = { placeholder: '无默认值', defaultValue }
|
|
|
+ let defaultValue = type==='time' ? (
|
|
|
+ operator === 'between' ? (
|
|
|
+ filter['value1'] ? [filter['value1'], filter['value2']] : null
|
|
|
+ ) :
|
|
|
+ (filter['value' + index] ? ( filter['value' + index].dynamic ? ( filter['value' + index] ) : moment(filter['value' + index]) ) : null)
|
|
|
+ ) : filter['value' + index];
|
|
|
+ const commonProps = { placeholder: '无默认值', defaultValue };
|
|
|
if(['index', 'string'].indexOf(type) !== -1) {
|
|
|
field = <Input { ...commonProps } onBlur={(e) => {this.changeFilterValue(filter, e.target.value, index)}}/>
|
|
|
}else if(['scale', 'ordinal'].indexOf(type) !== -1) {
|
|
|
field = <InputNumber { ...commonProps } onBlur={(e) => {this.changeFilterValue(filter, e.target.value, index)}}/>
|
|
|
}else if(type === 'time') {
|
|
|
- field = <div className='cus-time-picker' >
|
|
|
- <Input
|
|
|
+ if(operator === 'between') {
|
|
|
+ field = <RangePicker
|
|
|
key={Math.random()}
|
|
|
- allowClear
|
|
|
- // suffix={<Icon style={{ color: 'rgba(0, 0, 0, 0.25)' }} type="calendar" />}
|
|
|
- defaultValue={ commonProps.defaultValue ? (commonProps.defaultValue.dynamic ? commonProps.defaultValue.label : moment(commonProps.defaultValue).format('YYYY-MM-DD')) : '' }
|
|
|
- onFocus={() => {
|
|
|
- let obj = {};
|
|
|
- obj['datePickerOpen' + index] = true;
|
|
|
- this.setState(obj);
|
|
|
- }}
|
|
|
- onChange={() => {
|
|
|
- // 因为onFocus方法弹出了浮层,onChange方法只在点击清楚图标时会调用(相当于不可编辑的input),所以这里只做清除
|
|
|
- this.changeFilterValue(filter, null, index)
|
|
|
+ defaultValue={defaultValue}
|
|
|
+ ranges={{
|
|
|
+ '今天': [moment().startOf('day'), moment().endOf('day')],
|
|
|
+ '本月': [moment().startOf('month'), moment().endOf('month')],
|
|
|
+ '上月': [moment().month(moment().month() - 1).startOf('month'), moment().month(moment().month() - 1).endOf('month')],
|
|
|
+ '近半年': [moment().subtract(6, "months").startOf('day'), moment().endOf('day')],
|
|
|
+ '本年': [moment().startOf('year'), moment().endOf('year')],
|
|
|
+ '上年': [moment().subtract(1, "years").startOf('year'), moment().subtract(1, "years").endOf('year')],
|
|
|
}}
|
|
|
- />
|
|
|
- <DatePicker
|
|
|
- key={Math.random()}
|
|
|
- defaultValue={commonProps.defaultValue ? (commonProps.defaultValue.dynamic ? null : commonProps.defaultValue) : null}
|
|
|
- showToday={operator !== '='}
|
|
|
- open={this.state['datePickerOpen' + index]}
|
|
|
- onOpenChange={status => {
|
|
|
- let obj = {};
|
|
|
- obj['datePickerOpen' + index] = status;
|
|
|
- this.setState(obj);
|
|
|
+ showTime={false}
|
|
|
+ format="YYYY-MM-DD"
|
|
|
+ onChange={values => {
|
|
|
+ this.changeFilterValues(filter, [values[0], values[1]]);
|
|
|
}}
|
|
|
- onChange={(value) => {this.changeFilterValue(filter, value, index)}}
|
|
|
- renderExtraFooter={operator === '=' ? () => this.generateTimeTags(filter, index, commonProps.defaultValue) : null}
|
|
|
- />
|
|
|
- </div>
|
|
|
+ >
|
|
|
+ </RangePicker>
|
|
|
+ }else {
|
|
|
+ field = <div className='cus-time-picker' >
|
|
|
+ <Input
|
|
|
+ key={Math.random()}
|
|
|
+ allowClear
|
|
|
+ // suffix={<Icon style={{ color: 'rgba(0, 0, 0, 0.25)' }} type="calendar" />}
|
|
|
+ defaultValue={ commonProps.defaultValue ? (commonProps.defaultValue.dynamic ? commonProps.defaultValue.label : moment(commonProps.defaultValue).format('YYYY-MM-DD')) : '' }
|
|
|
+ onFocus={() => {
|
|
|
+ let obj = {};
|
|
|
+ obj['datePickerOpen' + index] = true;
|
|
|
+ this.setState(obj);
|
|
|
+ }}
|
|
|
+ onChange={() => {
|
|
|
+ // 因为onFocus方法弹出了浮层,onChange方法只在点击清除图标时会调用(相当于不可编辑的input),所以这里只做清除
|
|
|
+ this.changeFilterValue(filter, null, index)
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <DatePicker
|
|
|
+ key={Math.random()}
|
|
|
+ defaultValue={commonProps.defaultValue ? (commonProps.defaultValue.dynamic ? null : commonProps.defaultValue) : null}
|
|
|
+ showToday={operator !== '='}
|
|
|
+ open={this.state['datePickerOpen' + index]}
|
|
|
+ onOpenChange={status => {
|
|
|
+ let obj = {};
|
|
|
+ obj['datePickerOpen' + index] = status;
|
|
|
+ this.setState(obj);
|
|
|
+ }}
|
|
|
+ onChange={(value) => {this.changeFilterValue(filter, value, index)}}
|
|
|
+ renderExtraFooter={operator === '=' ? () => this.generateTimeTags(filter, index, commonProps.defaultValue) : null}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ }
|
|
|
}else if(type === 'categorical') { // 类别
|
|
|
if(operator === 'include' || operator==='notInclude') { // 包含/不包含
|
|
|
field = <Input { ...commonProps } onBlur={(e) => {this.changeFilterValue(filter, e.target.value, index)}}/>
|
|
|
@@ -472,7 +516,7 @@ class FilterBox extends React.Component {
|
|
|
)}
|
|
|
</FormItem>
|
|
|
</Col>
|
|
|
- <Col span={(operator&&operator!=='null'&&operator!=='notNull')?(operator==='between'?6:12):0}>
|
|
|
+ <Col span={(operator&&operator!=='null'&&operator!=='notNull')?(operator==='between'?(type === 'time' ? 12: 6):12):0}>
|
|
|
<FormItem
|
|
|
key={key}
|
|
|
className='filterValueOne'
|
|
|
@@ -480,7 +524,7 @@ class FilterBox extends React.Component {
|
|
|
{this.getFilterValueField(f, 1)}
|
|
|
</FormItem>
|
|
|
</Col>
|
|
|
- {operator==='between' && <Col span={6}>
|
|
|
+ {operator==='between' && type !== 'time' && <Col span={6}>
|
|
|
<FormItem
|
|
|
key={key}
|
|
|
className='filterValueTwo'
|