import React, { Component } from 'react' import { StyleSheet, ScrollView, View, Image, ImageBackground, Text, Dimensions, StatusBar, TouchableOpacity, PixelRatio, Platform, DatePickerAndroid, } from 'react-native' import { connect } from 'react-redux' import Icon from '../../components/Iconfont/Iconfont' import TopTab from '../../components/toptab/TopTab' import { NavigationActions, ScaleUtil, createAction } from '../../utils' import Collapsible from 'react-native-collapsible' import SelectTime from '../common/SelectTime' import Input from '../../components/input' import AllAnnounce from './announcement/AllAnnounce' import { setNowFormatDate } from '../../utils/utils' const { width, height } = Dimensions.get('window') @connect(({ theme, announce }) => ({ ...theme, ...announce })) class AnnouncementTab extends Component { constructor(props) { const date = new Date() super(props) this.state = { setButton: 0, inputSearch: '', dateActive: true, //时间折叠-true为关 typeId: '', // 开始时间 startTime: setNowFormatDate(true), // 结束时间 endTime: setNowFormatDate(), } this.startTime = '' this.endTime = '' // console.disableYellowBox = true; } componentDidMount() { this.topTouchFn() } topTouchFn() { let searchInfo = { page: 0, pageSize: 20, customerId: CUSTOMERINFO.id, search_EQ_statusCode: 2, search_EQ_pubdate: 1, } if (this.state.typeId) { searchInfo['search_EQ_bulletin.id'] = this.state.typeId } if (this.startTime) { searchInfo.search_GTE_pubdate_date = new Date(this.startTime).getTime() } if (this.endTime) { searchInfo.search_LT_pubdate_date = new Date(this.endTime).getTime() } if (this.state.inputSearch) { searchInfo.search_LIKE_title = `%${this.state.inputSearch}%` } this.props.dispatch(createAction('announce/getAnnounceContent')(searchInfo)) } // 订单按钮组 setList(setAtt) { let textColor = ['#333', '#E14C46'] let border = ['transparent', '#E14C46'] setArr = [] // const setAtt = [ // { touchName: "全部" }, // { touchName: "物流" }, // { touchName: "促销" }, // { touchName: "新品" }, // { touchName: "企业动态" } // ]; for (let j = 0; j < setAtt.length; j++) { setArr.push( { this.state.typeId = setAtt[j].noticeType this.topTouchFn() this.setState({ setButton: j }) }} key={j} style={{ justifyContent: 'center' }} > {setAtt[j].noticeTypeName} ) } return setArr } selectTimeFn() { return ( 开始时间 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.topTouchFn() this.setState({ dateActive: true }) }} style={{ width: width / 2, backgroundColor: '#E70013', justifyContent: 'center', }} > 确定 ) } // 头部 header() { return ( this.props.dispatch(NavigationActions.back())} > 返回 {this.state.showSearch ? ( { this.state.inputSearch = e this.topTouchFn() this.setState({ activeSection: true }) }} /> ) : ( 公告 )} {this.state.showSearch ? ( this.setState({ showSearch: false, activeSection: true }) } style={{ position: 'absolute', right: 10, flexDirection: 'row' }} > 取消 ) : ( this.setState({ showSearch: true, activeSection: true, dateActive: true, }) } > this.setState({ dateActive: !this.state.dateActive, activeSection: true, }) } > )} ) } async TimeAndroid(mark) { const { action, year, month, day } = await DatePickerAndroid.open({ date: new Date(), // minDate: new Date(), mode: 'spinner', }) if (action !== DatePickerAndroid.dismissedAction) { let newDate = `${year}-${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, announceDatas } = this.props return ( {/* 头部 */} {this.header()} {announceDatas && announceDatas.length > 1 ? ( {this.setList(announceDatas)} ) : 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.selectTimeFn()} ) } } const styles = StyleSheet.create({ container: { flex: 1, }, pngstyle: { width: width, }, buttonStyle: { backgroundColor: 'transparent', flexDirection: 'column', alignItems: 'center', }, buttonText: { marginTop: 9, fontSize: 14, color: '#FFF', }, }) export default AnnouncementTab