myContribution.js 3.04 KB
/**
 * Created by tdzl2003 on 12/18/16.
 */
import React, {Component, PropTypes} from "react";
import {
    Dimensions,
    Image,
    ScrollView,
    StyleSheet,
    Text,
    TouchableOpacity,
    View,
    Platform,
    FlatList,
    BackHandler,
    ActivityIndicator,
    StatusBar,
    NativeModules
} from "react-native";
import {zoomW,zoomH} from '../../utils/getSize';
const noResult = require('../../img/noResult.png');
const logo = require('../../img/logo.png');
import xnService from "../../service/AppService";
import {clock,xnToast,timeReduce,timePlus,timeEvery,getDay} from '../../utils/utils';


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

    constructor(){
        super()
        this.state = {
            loading:false,
            escortCount:'0',
            escortTime:''
        };
    }

    componentDidMount(){
        this.state = {
            loading:true,
        };
        let prams={
            id:global.user.id
        }
        xnService.getUserById(prams).then((data)=>{
            this.setState({
                loading:false
            });
            if(data.message){
                xnToast(data.message);
                return;
            }
            if(data.errors.length > 0){
                xnToast(data.errors[0].message);
            }else{

                this.setState({
                    escortCount:data.user.escortCount,
                    escortTime:data.user.escortTime
                })
            }
        })

    }


    render(){
        return(
            <View style={styles.bg}>
                <StatusBar barStyle={'default'}/>
                <View style={{flex:1,backgroundColor:'#f6f6f6',alignItems:'center',justifyContent:'center'}}>
                    <Text >我的护行次数:</Text>
                    <Text style={{fontSize:18,marginTop:20}}>45</Text>
                    <Text style={{marginTop:40}}>我的护行时间:</Text>
                    <Text style={{fontSize:17,marginTop:20}}>{timeEvery(this.state.escortTime,'day')}</Text>
                </View>

                {this.state.loading && <View style={styles.loadingBg}>
                    <ActivityIndicator size="large" />
                </View>}
            </View>
        )
    }
}
const styles = StyleSheet.create({
    backWrap: {
        justifyContent: 'center',
        paddingLeft: 18.5/zoomW,
        paddingRight: 18.5/zoomW,
        height: 44/zoomH,
    },
    back: {
        width: 8.5/zoomW,
        height: 15/zoomH,
    },
    bg:{
        flex:1,
        backgroundColor:'#f6f6f6',
    },

    loadingBg:{
        width:'100%',
        height:'100%',
        position:'absolute',
        display:'flex',
        alignItems:'center',
        justifyContent:'center'
    },
});