import React, { Component } from 'react'
import { DatePicker, Row, Col,TimePicker  } from 'antd';
import moment from 'moment';
import 'moment/locale/zh-cn';
moment.locale('zh-cn');

class DateTime extends Component {
	render() {
		let {
			value,
            scope,
            date_type,
            date_start_value,
            date_end_value,
		} = this.props
		if(scope ==="among") {
			return (
				<Row  className="u-field-search-among" gutter={0}>
					<Col span={11}>
                       
                        <TimePicker 
                            // className="rep-u-field-search-datatime" 
                            value={value.start ? moment(value.start, "YYYY-MM-DD HH:mm:ss") : null}
                            format={date_type}
                            onChange={(date,datestring)=>{
                                let newValue = value;  //有效日期格式
                                newValue.start =  date?moment(date._d).format('YYYY-MM-DD HH:mm:ss'):"";

                                let dateValue=JSON.parse(JSON.stringify(value));
                                dateValue.start =  datestring;  //普通 的日期字符串
                                dateValue.end =  moment(dateValue.end).format(date_type);  //普通 的日期字符串

                                this.props.onChange(dateValue,newValue)
                            }} />
                        
					</Col>
					<Col span={1}  offset={1}>
						-
					</Col>
					<Col span={11} >
                        <TimePicker 
                            // className="rep-u-field-search-datatime" 
                            value={value.end? moment(value.end, "YYYY-MM-DD HH:mm:ss") : null}
                            format={date_type}
                            onChange={(date,datestring)=>{
                                let newValue = value;  //有效日期格式
                                newValue.end =  date?moment(date._d).format('YYYY-MM-DD HH:mm:ss'):"";

                                let dateValue=JSON.parse(JSON.stringify(value));
                                dateValue.start =  moment(dateValue.start).format(date_type);  //普通 的日期字符串
                                dateValue.end =  datestring;  //普通 的日期字符串
                                this.props.onChange(dateValue,newValue)
                            }} />
					</Col>
					
				</Row>
			)
		}else{
			return (
                <TimePicker 
                    // className="rep-u-field-search-datatime" 
                    value={value ? moment(value, "YYYY-MM-DD HH:mm:ss") : null}
                    format={date_type}
                    // onChange={(date,datestring)=>this.props.onChange(date?moment(date._d).format('YYYY-MM-DD HH:mm:ss'):"")} 
                    onChange={(date,datestring)=>{
                        let newValue = value;  //有效日期格式
                            newValue =  date?moment(date._d).format('YYYY-MM-DD HH:mm:ss'):"";

                            let dateValue=JSON.parse(JSON.stringify(value));
                            dateValue =  datestring;  //普通 的日期字符串
                        this.props.onChange(dateValue,newValue)
                    }} 

                />
                )	
		}
	}
}

export default DateTime
