myEvents.js 10.6 KB
/**
 * Created by Cassie on 2018/03/21
 */
import React, { Component } from 'react';
import {
    StyleSheet,
    ScrollView,
    View,
    Text,
    TouchableOpacity,
    Image,
    TextInput,
    ActivityIndicator,
    Keyboard,
    StatusBar,
    Modal
} from 'react-native';

import {width,height,zoomW,zoomH} from '../../utils/getSize';
import {getHeaderPadding, getHeaderHeight, NoDoublePress,xnToast,MD5} from "../../utils/utils";
import xnService from "../../service/AppService";
import Carousel from 'react-native-looped-carousel';
import md5 from 'md5';
import { NavigationActions } from 'react-navigation';

const bgImg = require('../../img/bgImg.png');
const logo = require('../../img/logo.png');
const phone = require('../../img/phone.png');
const pwd = require('../../img/pwd.png');
const bitmap = require('../../img/bitmap.png');

const phoneRule = /^1[3456789]\d{9}$/;

export default class myEvents extends Component {
    static navigationOptions = ({navigation,screenProps}) => ({
        headerTitle:'我的事件',
        headerLeft:(
            <TouchableOpacity style={styles.backWrap} onPress={() => navigation.goBack()}>
                <Image source={require('../../img/back_gray.png')} resizeMode="contain" />
            </TouchableOpacity>
        ),
        headerRight:(
            <View></View>
        )
    });

    constructor(props){
        super(props);
        this.state = {
            itemList:[],
            imageList: [],
            currentIndex: 0,
            modalShow: false
        };
    };

    componentWillMount(){

    };

    componentDidMount(){
        xnService.getMyEvents({userId:global.user.id}).then((data) => {

            if(data.message){
                xnToast(data.message);
                return;
            }
            if(data.errors.length > 0){
                xnToast(data.errors[0].message);
            }else{
                this.setState({
                    itemList:data.result
                })
            }
        });
    }

    renderItem = (item,index) => {
        return (
            <View style={{marginTop:index==0?35:10,paddingLeft:15/zoomW,paddingRight:15/zoomW,paddingBottom:13/zoomH,borderBottomWidth:1,borderBottomColor:'#e5e5e5'}}>
                <Text style={{color:'#0c50ba',fontSize:17}}>{item.title}</Text>
                <Text style={{color:'#343434',fontSize:17,marginTop:5/zoomH,marginBottom:10/zoomH}}>{item.description}</Text>
                {item.appAttachementAddress && <View style={styles.itemContent}>
                    <View style={{flexDirection:'row'}}>
                        {item.appAttachementAddress.map((item,index,arr) => this.renderImg(item,index,arr))}
                    </View>
                </View>}
                <Text numberOfLines={1} style={{color:'#4e7fcc',fontSize:16,marginBottom:3/zoomH}}>{!!!item.detailed?item.lineName+item.station:item.detailed}</Text>
                <Text style={{color:'#a0a0a0',fontSize:16}}>{item.commitTime}</Text>
                <View>
                    <Image style={{marginLeft:8/zoomW}} source={require('../../img/arrowTop.png')} resizeMode='contain'></Image>
                    <View style={{backgroundColor:'#efefef',width:'100%',padding:7}}>
                        <Text style={{color:'#104caa',fontSize:17}}>处理意见:<Text style={{color:'#3b3b3b',fontSize:17}}>{item.handleSuggestion || '处置中'}</Text></Text>
                    </View>
                </View>
            </View>
        )
    };

    // 放大图片
    enlargeImg(index,arr) {
        this.setState({
            imageList: arr,
            currentIndex: index,
        }, () => {
            this.setState({
                modalShow: true,
            });
        });
    }

    // 关闭模态框
    closeModal() {
        this.setState({
            modalShow: false,
        });
    }

    /*渲染图片*/
    renderImg(item,index,arr){
        return (
            <TouchableOpacity activeOpacity={0.8} onPress={() => this.enlargeImg(index,arr)} key={index}>
                {index == 0 && <Image source={{uri:item+'?x-oss-process=image/resize,w_1000'}} style={arr.length === 1 ? styles.coverImg : styles.moreImg} resizeMode="cover" />}
                {index == 1 && <Image source={{uri:item+'?x-oss-process=image/resize,w_1000'}} style={[styles.moreImg,{marginLeft:(7/zoomW)}]} resizeMode="cover" />}
                {index == 2 && <Image source={{uri:item+'?x-oss-process=image/resize,w_1000'}} style={[styles.moreImg,{marginLeft:(7/zoomW)}]} resizeMode="cover" />}
            </TouchableOpacity>
        )
    };

    render(){
        return(
            <ScrollView style={styles.background} bounces={false} scrollEventThrottle={200}>
                <StatusBar barStyle={'default'}/>
                <Modal
                    animationType={'none'}
                    visible={this.state.modalShow}
                    transparent
                    onRequestClose={() => {}}
                >
                    <View style={styles.viewBg}>
                        <View
                            style={{
                                width,
                                height: getHeaderHeight(),
                                paddingTop: getHeaderPadding(),
                                display: 'flex',
                                flexDirection: 'row',
                                justifyContent: 'center',
                                alignItems: 'center',
                            }}
                        >
                            <TouchableOpacity
                                activeOpacity={0.8} style={{
                                height: '100%',
                                display: 'flex',
                                justifyContent: 'center',
                                paddingLeft: 15 / zoomW,
                                paddingRight: 15 / zoomW,
                                position: 'absolute',
                                left: 0,
                                top: getHeaderPadding(),
                            }} onPress={() => NoDoublePress.onPress(() => {
                                this.closeModal();
                            })}
                            >
                                <Image source={require('../../img/closeImgModal.png')} style={{ width: 12 / zoomW, height: 12 / zoomW }} resizeMode="contain" />
                            </TouchableOpacity>
                            <Text style={{ fontSize: 16, color: '#fff' }}>{this.state.currentIndex + 1}/{this.state.imageList.length}</Text>
                        </View>
                        <Carousel
                            style={{ height: height - getHeaderHeight(), width, paddingBottom: getHeaderHeight() }}
                            bullets={false}
                            isLooped={false}
                            autoplay={false}
                            currentPage={this.state.currentIndex}
                            onAnimateNextPage={index => this.setState({ currentIndex: index })}
                        >
                            {this.state.imageList.map((item, index) =>
                                <TouchableOpacity
                                    activeOpacity={1} key={index} style={{
                                    width,
                                    height: height - 2 * getHeaderHeight(),
                                    display: 'flex',
                                    justifyContent: 'center',
                                    alignItems: 'center',
                                }}
                                >
                                    <Image source={{ uri: `${item}?x-oss-process=image/resize,w_640` }} style={{ width, height: '100%' }} resizeMode="contain" />
                                </TouchableOpacity>,
                            )}
                        </Carousel>
                    </View>
                </Modal>
                <Image style={{width:'100%',height:195/zoomH}} source={global.user.politicalStatus == 1?require('../../img/myEventsBanner.png'):require('../../img/myEventsBanner_unparty.png')} resizeMode='cover'></Image>
                <View style={{position:'absolute',right:14/zoomW,top:136/zoomH,backgroundColor:'#f1f1f1',width:80/zoomW,height:80/zoomW,borderRadius:4,alignItems:'center',justifyContent:'center'}}>
                    {global.user.avatar&&global.user.avatar!=''?
                        <Image style={{width:74/zoomW,height:74/zoomW}} defaultSource={global.user.politicalStatus == 1?require('../../img/defultPartyIcon.png'):require('../../img/defultIcon.png')} source={{uri:global.user.avatar}} resizeMode='cover'/>:
                        <Image style={{width:74/zoomW,height:74/zoomW}} source={global.user.politicalStatus == 1?require('../../img/defultPartyIcon.png'):require('../../img/defultIcon.png')} resizeMode='cover'/>}
                    {/*<Image style={{width:74/zoomW,height:74/zoomW}} defaultSource={global.user.politicalStatus == 1?require('../../img/defultPartyIcon.png'):require('../../img/defultIcon.png')} source={{uri:global.user.avatar}} resizeMode='cover'/>*/}
                </View>
                <Text style={{backgroundColor:'transparent',color:'white',position:'absolute',right:109/zoomW,top:162/zoomH,fontFamily:'PingFangSC-Medium',fontSize:18}}>{global.user.nickName}</Text>
                {this.state.itemList.length==0&&<View style={{flexDirection:'row',width:'100%',height:20,justifyContent:'center',alignItems:'flex-start',marginTop:65/zoomH,paddingLeft:15/zoomW,paddingRight:15/zoomW}}>
                    <View style={{flex:1,height:2/zoomW,backgroundColor:'#d8d8d8',marginRight:14/zoomW}}></View>
                    <View style={{width:4/zoomW,height:4/zoomW,backgroundColor:'#d8d8d8'}}></View>
                    <View style={{flex:1,height:2/zoomW,backgroundColor:'#d8d8d8',marginLeft:14/zoomW}}></View>
                </View>}
                {this.state.itemList.length != 0 && this.state.itemList.map((v, i) => this.renderItem(v, i))}
            </ScrollView>
        );
    }
}

const styles = StyleSheet.create({
    backWrap: {
        justifyContent: 'center',
        paddingLeft: 18.5/zoomW,
        paddingRight: 18.5/zoomW,
        height: 44/zoomH,
    },
    background:{
        flex:1,
        backgroundColor:'#fff',
    },
    viewBg: {
        width,
        height,
        backgroundColor: '#000',
        display: 'flex',
        justifyContent: 'flex-end',
    },
    itemContent:{
        display:'flex',
        flexDirection:'row',
        marginBottom:(5/zoomH)
    },
    coverImg:{
        width:(345/zoomW),
        height:(193/zoomH),
        backgroundColor:'#eee'
    },
    moreImg:{
        width:(110/zoomW),
        height:(110/zoomW),
        backgroundColor:'#eee'
    },
});