UNPKG

2.39 kBTypeScriptView Raw
1import React, { Component } from 'react'
2import { View } from 'react-native'
3import { DatePicker, List } from '@sishuguojixuefu/antd-mobile-rn'
4import { SsDateRangeProps } from '../utils/PropTypes'
5import ErrorTip from './helper/ErrorTip'
6import getFieldDecorator from '../utils/getFieldDecorator'
7import Label from './helper/Label'
8
9export default class SsDateRange extends Component<SsDateRangeProps, {}> {
10 private startFieldDecorator: any
11 private endFieldDecorator: any
12 private startDate: Date = new Date()
13 private endDate: Date = new Date()
14
15 componentWillMount() {
16 const { form, id, initialValue, rules } = this.props
17 this.startFieldDecorator = getFieldDecorator(form, id[0], initialValue![0], rules)
18 this.endFieldDecorator = getFieldDecorator(form, id[1], initialValue![1], rules)
19 }
20
21 private _onChangeStartDate = (value: Date) => {
22 const { onChange } = this.props
23 this.startDate = value
24 onChange && onChange([value, this.endDate])
25 }
26
27 private _onChangeEndDate = (value: Date) => {
28 const { onChange } = this.props
29 this.endDate = value
30 onChange && onChange([this.startDate, value])
31 }
32
33 render() {
34 const { id, label, required, form, placeholder, initialValue } = this.props
35 return (
36 <View>
37 <ErrorTip error={form.getFieldError(id[0])}>
38 {this.startFieldDecorator(
39 <DatePicker
40 {...this.props}
41 onChange={this._onChangeStartDate}
42 maxDate={form.getFieldValue(id[1]) || initialValue![1] || '2030-1-1'}
43 extra={placeholder![0]}
44 >
45 <List.Item arrow="horizontal" style={{ paddingLeft: 0 }} last>
46 <Label required={required} label={label[0]} />
47 </List.Item>
48 </DatePicker>
49 )}
50 </ErrorTip>
51 <ErrorTip error={form.getFieldError(id[1])}>
52 {this.endFieldDecorator(
53 <DatePicker
54 {...this.props}
55 onChange={this._onChangeEndDate}
56 minDate={form.getFieldValue(id[0]) || initialValue![1] || '2000-1-1'}
57 extra={placeholder![1]}
58 >
59 <List.Item arrow="horizontal" style={{ paddingLeft: 0 }} last>
60 <Label required={required} label={label[1]} />
61 </List.Item>
62 </DatePicker>
63 )}
64 </ErrorTip>
65 </View>
66 )
67 }
68}