1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { DatePicker, Button } from 'antd';
import moment from 'moment';
import config from '../../../utils/config';
import styles from './date.less';
const RangePicker = DatePicker.RangePicker;
class DateSearch extends Component {
constructor(props, context) {
super(props, context);
this.onClick = this::this.onClick;
this.onChange = this::this.onChange;
this.onOk = this::this.onOk;
this.bindContainer = this::this.bindContainer;
this.state = {
value: [moment(), moment()],
};
}
onClick() {
const [start, end] = this.state.value;
let sValue = '';
let eValue = '';
if (start && start.isValid()) {
sValue = start.valueOf().toString();
}
if (end && end.isValid) {
eValue = end.valueOf().toString();
}
const filter = (sValue || eValue) ? `~[${sValue},${eValue})` : null;
this.props.onSearchSubmit(filter);
}
onChange(value) {
this.setState({
value,
});
}
onOk(value) {
this.setState({
value,
});
}
bindContainer(node) {
this.container = node;
}
render() {
return (
<div ref={this.bindContainer} className={styles.container}>
<RangePicker
showTime
value={this.state.value}
format={config.defaultDateTimeFormat}
placeholder={['开始时间', '结束时间']}
onChange={this.onChange}
onOk={this.onOk}
getCalendarContainer={() => this.container}
/>
<Button className={styles.popupOk} onClick={this.onClick}>ok</Button>
</div>
);
}
}
DateSearch.propTypes = {
onSearchSubmit: PropTypes.func,
};
const funcVoid = () => {};
DateSearch.defaultProps = {
onSearchSubmit: funcVoid,
};
export default DateSearch;