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

import {width,height,zoomW,zoomH} from '../../utils/getSize';
import {getHeaderPadding,xnToast,MD5} from "../../utils/utils";
import xnService from "../../service/AppService";
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:[]
        };
    };

    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
                })
            }
        });
    }

    typeScreening = (type)=>{
       if (type == 'STATION'){
           return '车站事件';
       }else if (type == 'CARRIAGE'){
           return '车厢事件';
       }else if (type == 'GOOD'){
           return '好人好事';
       }else{
           return '';
       }

    }

    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:13}}>{this.typeScreening(item.type)}</Text>
                <Text style={{color:'#343434',fontSize:13,marginTop:5/zoomH,marginBottom:10/zoomH}}>{item.description}</Text>
                {/*<Image style={{width:99/zoomW,height:138/zoomH,backgroundColor:'#eee',marginBottom:5/zoomH}} resizeMode='cover'/>*/}
                {item.appAttachementAddress&&<View style={styles.itemContent}>
                    {item.appAttachementAddress.length == 1  &&  <Image style={styles.coverImg} source={{uri:item.appAttachementAddress[0]}} resizeMode="cover" />}
                    {item.appAttachementAddress.length > 1  && <View style={{flexDirection:'row'}}>
                        {item.appAttachementAddress.map((item,index) => this.renderImg(item,index))}
                    </View>}
                </View>}
                <Text style={{color:'#4e7fcc',fontSize:12,marginBottom:3/zoomH}}>{item.lineName+item.station}</Text>
                <Text style={{color:'#a0a0a0',fontSize:12}}>{item.commitTime}</Text>
                <Image style={{marginLeft:8/zoomW}} source={require('../../img/arrowTop.png')} resizeMode='contain'></Image>
                {item.handled&&<View style={{backgroundColor:'#efefef',width:'100%',padding:7}}>
                    <Text style={{color:'#104caa',fontSize:12}}>处理意见:<Text style={{color:'#3b3b3b',fontSize:12}}>{item.handleSuggestion}</Text></Text>
                </View>}
            </View>
        )
    };

    /*渲染图片*/
    renderImg(item,index){
        return (
            <View key={index}>
                {index == 0 && <Image source={{uri:item}} style={styles.moreImg} resizeMode="cover" />}
                {index == 1 && <Image source={{uri:item}} style={[styles.moreImg,{marginLeft:(7/zoomW)}]} resizeMode="cover" />}
                {index == 2 && <Image source={{uri:item}} style={[styles.moreImg,{marginLeft:(7/zoomW)}]} resizeMode="cover" />}
            </View>
        )
    };

    render(){
        return(
            <ScrollView style={styles.background} bounces={false}>
                <Image style={{width:'100%',height:195/zoomH}} source={require('../../img/myEventsBanner.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'}}>
                    <Image style={{width:74/zoomW,height:74/zoomW}} defaultSource={require('../../img/defultIcon.png')} source={{uri:global.user.avatar}} resizeMode='cover'></Image>
                </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',
    },
    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'
    },
});