import React, { Component } from 'react' import { StyleSheet, View, StatusBar, Text, TouchableOpacity, Dimensions, PixelRatio, Platform, DatePickerAndroid, } from 'react-native' import { connect } from 'react-redux' import Icon from '../../components/Iconfont/Iconfont' import { NavigationActions } from '../../utils' // import TopTab from "../../components/toptab/TopTab"; import SelectTime from '../common/SelectTime' import Input from '../../components/input' import Collapsible from 'react-native-collapsible' import OrderList from './ordertoptab/orderlist/OrderList' import DeliverySign from './ordertoptab/deliverysign/DeliverySign' import ReturnSign from './ordertoptab/returnsign/ReturnSign' import moment from 'moment' import { setNowFormatDate } from '../../utils/utils' const { width, height } = Dimensions.get('window') @connect(({ theme ,orderlist}) => ({ ...theme,...orderlist })) class OrderHome extends Component { constructor() { const date = new Date() super() this.state = { showSearch: false, titleActive: true, titleIndex: 0, title: '订单列表', inputSearch: '', dateActive: true, //时间折叠-true为关 // 开始时间 startTime: setNowFormatDate(true), // 结束时间 endTime: setNowFormatDate(), } this.startTime = '' this.endTime = '' } static navigationOptions = { tabBarLabel: ({ tintColor }) => ( 订单 ), tabBarIcon: ({ focused, tintColor }) => tintColor == '#333' ? ( ) : ( ), } componentWillReceiveProps(nextProps) { if(nextProps.routerParams) { this.setState({ title : '订单列表', titleIndex : 0, dateActive : true }) } } header() { return ( {this.state.showSearch ? ( { this.setState({ activeSection: true, inputSearch: e }) }} /> this.setState({ showSearch: false, dateActive: true }) } style={{ alignSelf: 'center', paddingHorizontal: 10 }} > 取消 ) : ( !this.state.dateActive && !this.state.titleActive ? this.setState({ dateActive: true }) : this.setState({ dateActive: false, titleActive: false }) } style={{ flexDirection: 'row', justifyContent: 'center' }} > {this.state.title} this.setState({ showSearch: true, dateActive: true }) } style={{ marginRight: 10 }} > !this.state.dateActive && this.state.titleActive ? this.setState({ dateActive: true }) : this.setState({ dateActive: false, titleActive: true }) } > )} ) } async TimeAndroid(mark) { const { action, year, month, day } = await DatePickerAndroid.open({ date: new Date(), //maxDate: new Date(), mode: 'spinner', }) if (action !== DatePickerAndroid.dismissedAction) { let newDate = `${year}-${(month + 1)<10?"0"+(month+1):(month+1)}-${day}` if (mark == 'start') { if (newDate <= this.state.endTime) { this.setState({ startTime: newDate, }) } } else if (mark == 'end') { if (this.state.startTime <= newDate) { this.setState({ endTime: newDate, }) } } // 这里开始可以处理用户选好的年月日三个参数:year, month (0-11), day } } render() { const { appTheme,routerParams } = this.props let postList = { inputSearch: this.state.inputSearch, startTime: this.startTime, endTime: this.endTime, } return ( {/* 头部 */} {this.header()} {this.state.title == '订单列表' ? ( ) : null} {this.state.title == '签收列表' ? ( ) : null} {this.state.title == '退货列表' ? ( ) : null} {/* */} {/* 下拉遮罩 */} {!this.state.dateActive ? ( ) : null} {/* 时间弹窗 */} (this.showTime = showTime)} cb={(date, mark) => { let newDate = moment(date).format('YYYY-MM-DD') if (mark == 'start') { if (newDate <= this.state.endTime) { this.setState({ startTime: newDate, }) } } else if (mark == 'end') { if (this.state.startTime <= newDate) { this.setState({ endTime: newDate, }) } } }} /> {/* 时间选择下拉 */} {!this.state.titleActive ? ( {['订单列表', '签收列表', '退货列表'].map((item, key) => ( this.setState({ titleIndex: key, dateActive: true, title: item, }) } key={key} style={{ marginTop: 10 }} > {item} ))} ) : ( 开始时间 Platform.OS == 'ios' ? this.showTime._openModal('start') : this.TimeAndroid('start') } style={{ paddingHorizontal: 40, paddingVertical: 7, marginTop: 16, borderColor: '#DDD', borderWidth: 1, borderRadius: 100, }} > {this.state.startTime} ~ 结束时间 Platform.OS == 'ios' ? this.showTime._openModal('end') : this.TimeAndroid('end') } style={{ paddingHorizontal: 40, paddingVertical: 7, marginTop: 16, borderColor: '#DDD', borderWidth: 1, borderRadius: 100, }} > {this.state.endTime} this.setState({ dateActive: true, //startTime: this.startTime, //endTime: this.endTime, }) } style={{ width: width / 2, backgroundColor: '#FFF', justifyContent: 'center', }} > 取消 { this.startTime = this.state.startTime this.endTime = this.state.endTime this.setState({ dateActive: true }) }} style={{ width: width / 2, backgroundColor: '#E70013', justifyContent: 'center', }} > 确定 )} ) } } const styles = StyleSheet.create({ container: { flex: 1, }, }) export default OrderHome