home.js 14 KB
/**
 * Created by Cassie on 2018/03/21
 */
import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    Text,
    TouchableOpacity,
    Image,
    TextInput,
    Animated,
    ActivityIndicator,
    NativeModules,
    NativeEventEmitter,
    DeviceEventEmitter,
    Alert,
    Modal,
    Platform,
    BackHandler,
    AsyncStorage,
    ScrollView,StatusBar
} from 'react-native';
import moment from 'moment';

import {width,height,zoomW,zoomH} from '../../utils/getSize';
import {clock,xnToast,timeReduce,timePlus,timeEvery,getDay} from '../../utils/utils';
import xnService from "../../service/AppService";
import md5 from 'md5';
import IndexBanner from '../component/IndexBanner'

const nativeBridge = NativeModules.BlueToolManage;
const NativeModule = new NativeEventEmitter(nativeBridge);
const defaultIcon = require('../../img/小头像.png');
const defaultIcon1 = require('../../img/volunteerService.png');
const defaultIcon2 = require('../../img/safeEscort.png');
const defaultIcon3 = require('../../img/myEvents.png');

export default class home extends Component {
    static navigationOptions = ({navigation}) => ({
        title:'首页',
        headerTitle:'平安地铁',
        headerRight:<TouchableOpacity onPress={() => { navigation.navigate('PersonCenter', {})}}>
            <Image source={require('../../img/my.png')} style={{marginRight:16}} resizeMode="contain"
            />
        </TouchableOpacity>,
        // tabBarIcon: ({ tintColor }) => (
        //     <Image
        //         source={require('./asset/current.png')}
        //         style={[styles.icon, {tintColor: tintColor}]}
        //     />
        // )
    });

    constructor(props){
        super(props);
        this.state = {
            adList:[
                {
                    id: 1,
                    count: 0,
                    type: 'CREDIT_PLATFORM',
                    // pictureUrl: "https://img-xiniunet-com.alikunlun.com/512824102474878976/312824102474878976/856442535890006016.png"
                },
                {
                    id: 2,
                    count: 0,
                    type: 'CREDIT_AUTH',
                    // pictureUrl: "https://img-xiniunet-com.alikunlun.com/512824102474878976/312824102474878976/856442535890006016.png"
                },
                {
                    id: 3,
                    count: 0,
                    type: 'CREDIT_INFO',
                    // pictureUrl: "https://img-xiniunet-com.alikunlun.com/512824102474878976/312824102474878976/896970581981933568.png"
                },
            ],
            detailList:[
                {
                    imgeAttachmentCount: 1,
                    contentText: '刚刚过去的这2017年,上海地铁站出现很多好人好事,我猜就是这个样子....',
                    attachmentList: ['1'],
                },
                {
                    imgeAttachmentCount:0,
                    contentText:'刚刚过去的这2017年,上海地铁站出现很多好人好事,我猜就是这个样子....',
                    attachmentList: [],
                },
                {
                    imgeAttachmentCount:2,
                    contentText:'刚刚过去的这2017年,上海地铁站出现很多好人好事,我猜就是这个样子....',
                    attachmentList: ['2','2'],
                },
                {
                    imgeAttachmentCount:3,
                    contentText:'刚刚过去的这2017年,上海地铁站出现很多好人好事,我猜就是这个样子....',
                    attachmentList: ['1','2','3'],
                }
            ],
        };
    };

    componentWillMount(){

    };

    componentDidMount(){
        this
    }

    renderItem = (item,index) => {
        return (
            <TouchableOpacity activeOpacity={0.8} style={styles.listItem} onPress={()=>console.log(index)}>
                <View style={styles.itemTop}>
                    <Image source={require('../../img/fire.png')} resizeMode="cover" style={{width:16/zoomW,height:20/zoomH}}/>
                    <Text style={{marginLeft:6/zoomW,fontSize:16,fontWeight:'600'}}>上海“不老义工”温暖南方寒冬!</Text>
                </View>
                <View style={styles.itemContent}>
                    {item.imgeAttachmentCount == 1  &&  <Image style={styles.coverImg} resizeMode="cover" />}
                    {item.imgeAttachmentCount > 1  && <View style={{flexDirection:'row'}}>
                        {item.attachmentList.map((item,index) => this.renderImg(item,index))}
                    </View>}
                    {item.contentText != null && item.contentText.length != 0 && <Text numberOfLines={2} style={styles.contentText}>{item.contentText}</Text>}
                </View>
                <View style={styles.itemBottom}>
                    <Text style={{fontSize:14,color:'#999'}}>回复333</Text>
                    <View style={{display:'flex',flexDirection:'row',alignItems:'center'}}>
                        {item.threadUserAvatarUrl && <Image  style={styles.avatar} resizeMode="cover" />}
                        {!item.threadUserAvatarUrl && <Image source={defaultIcon} style={styles.avatar} resizeMode="cover" />}
                        <Text style={{fontSize:14,color:'#999'}}>发布人·2018-04-13 11:50</Text>
                    </View>
                </View>
            </TouchableOpacity>
        )

    };

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

    render(){
        return (
            <View style={styles.background}>
                <StatusBar barStyle={'default'}/>
                <ScrollView
                    style={styles.container}
                    alwaysBounceVertical={false}
                    alwaysBounceHorizontal={false}
                >
                    <IndexBanner data={this.state.adList} navigation={this.props.navigation}/>
                    {/*报表信息*/}
                    <View style={styles.record}>
                        <View style={styles.bgImg}>
                            <Image source={defaultIcon1} style={{width:'100%',height:'100%',position:'absolute', top:0, left:0}} resizeMode="contain" />
                            <View style={{flex:1,justifyContent:'space-around',alignItems:'center',paddingBottom:2,paddingTop:2}}>
                                <View style={{width:110/zoomW,paddingLeft:7/zoomW,flexDirection:'row',alignItems:'center',justifyContent:'flex-start'}}>
                                    <Image source={require('../../img/volunteerServiceIcon.png')} style={{width:14/zoomW,height:14/zoomW}}/>
                                    <Text style={{backgroundColor:'transparent',fontSize:14,marginLeft:2/zoomW,color:'white'}}>志愿服务</Text>
                                </View>
                                <Text style={{backgroundColor:'transparent',fontSize:18,color:'white'}}>10<Text style={{fontSize:12}}> </Text></Text>
                                <Text style={{backgroundColor:'transparent',fontSize:14,color:'white'}}>报名成功</Text>
                            </View>
                        </View>
                        <View style={[styles.bgImg,{marginLeft:7.5/zoomW}]}>
                            <Image source={defaultIcon2} style={{width:'100%',height:'100%',position:'absolute', top:0, left:0}} resizeMode="contain" />
                            <View style={{flex:1,justifyContent:'space-around',alignItems:'center'}}>
                                <View style={{width:110/zoomW,paddingLeft:7/zoomW,flexDirection:'row',alignItems:'center',justifyContent:'flex-start'}}>
                                    <Image source={require('../../img/safeEscortIcon.png')} style={{width:14/zoomW,height:14/zoomW}}/>
                                    <Text style={{backgroundColor:'transparent',fontSize:14,marginLeft:2/zoomW,color:'white'}}>安全护航员</Text>
                                </View>
                                <Text style={{backgroundColor:'transparent',fontSize:18,color:'white'}}>39<Text style={{fontSize:12}}> </Text></Text>
                                <Text style={{backgroundColor:'transparent',fontSize:14,color:'white'}}>本车护航员</Text>
                            </View>
                        </View>
                        <View style={[styles.bgImg,{marginLeft:7.5/zoomW}]}>
                            <Image source={defaultIcon3} style={{width:'100%',height:'100%',position:'absolute', top:0, left:0}} resizeMode="contain" />
                            <View style={{flex:1,justifyContent:'space-around',alignItems:'center'}}>
                                <View style={{width:110/zoomW,paddingLeft:7/zoomW,flexDirection:'row',alignItems:'center',justifyContent:'flex-start'}}>
                                    <Image source={require('../../img/myEvents.png')} style={{width:14/zoomW,height:14/zoomW}}/>
                                    <Text style={{backgroundColor:'transparent',fontSize:14,marginLeft:2/zoomW,color:'white'}}>我的事件</Text>
                                </View>
                                <Text style={{backgroundColor:'transparent',fontSize:18,color:'white'}}>22<Text style={{fontSize:12}}> </Text></Text>
                                <Text style={{backgroundColor:'transparent',fontSize:14,color:'white'}}>已上报</Text>
                            </View>
                        </View>

                    </View>
                    {/*我是一条分割线*/}
                    <View style={{flexDirection:'row',height:45/zoomH,alignItems:'center',justifyContent:'center',paddingLeft:16/zoomW,paddingRight:16/zoomW}}>
                        <View style={{flex:1,height:1/zoomH,backgroundColor:'#d4d4d4'}}></View>
                        <Text style={{marginLeft:19/zoomW,marginRight:19/zoomW,color:'#b8b8b8',fontSize:12}}>公益社区</Text>
                        <View style={{flex:1,height:1/zoomH,backgroundColor:'#d4d4d4'}}></View>
                    </View>
                    {/*社区列表*/}
                    {this.state.detailList.map((v, i) => this.renderItem(v, i))}
                </ScrollView>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    background:{
        flex:1,
        backgroundColor:'#f6f6f6',
        display:'flex',
        alignItems:'center',

    },
    container: {
        flex: 1,
    },
    record:{
        width:width,
        height:90/zoomH,
        backgroundColor:'white',
        marginTop:10,
        flexDirection:'row',
        alignItems:'center',
        justifyContent:'center'
    },
    listItem:{
        minHeight:(110/zoomH),
        backgroundColor:'#fff',
        marginBottom:(8/zoomH),
        padding:(15/zoomH),
    },
    itemContent:{
        marginTop:(15/zoomH),
        marginBottom:(15/zoomH)
    },
    itemBottom:{
        display:'flex',
        flexDirection:'row',
        justifyContent:'space-between'
    },
    moreImg:{
        width:(110/zoomW),
        height:(110/zoomW),
        backgroundColor:'#eee'
    },
    coverImg:{
        width:(345/zoomW),
        height:(193/zoomH),
        backgroundColor:'#eee'
    },
    contentText:{
        marginTop:10/zoomH,
        fontSize:14,
        color:'#666'
    },
    avatar:{
        width:(20/zoomW),
        height:(20/zoomW),
        borderRadius:(10/zoomW),
        marginRight:(6/zoomW)
    },
    itemTop:{
        justifyContent:'flex-start',
        flexDirection:'row',
        alignItems:'center'
    },
    bgImg:{
        width:110/zoomW,
        height:70/zoomH,

    }
});


// {/*<Image style={{width:110/zoomW,height:70/zoomH,backgroundColor:'red',borderRadius:4}}>*/}
// {/*<View style={{flex:1,justifyContent:'space-around',alignItems:'center'}}>*/}
// {/*<View style={{width:110/zoomW,paddingLeft:7/zoomW,flexDirection:'row',alignItems:'center',justifyContent:'flex-start'}}>*/}
// {/*<Image style={{width:14/zoomW,height:14/zoomW,backgroundColor:'green'}}></Image>*/}
// {/*<Text style={{fontSize:12,marginLeft:2/zoomW,color:'white'}}>志愿服务</Text>*/}
// {/*</View>*/}
// {/*<Text style={{fontSize:18,color:'white'}}>10<Text style={{fontSize:12}}> 件</Text></Text>*/}
// {/*<Text style={{fontSize:13,color:'white'}}>报名成功</Text>*/}
// {/*</View>*/}
// {/*</Image>*/}
// {/*<Image style={{marginLeft:7.5/zoomW,width:110/zoomW,height:70/zoomH,backgroundColor:'red',borderRadius:4}}>*/}
//     {/*<View style={{flex:1,justifyContent:'space-around',alignItems:'center'}}>*/}
//         {/*<View style={{width:110/zoomW,paddingLeft:7/zoomW,flexDirection:'row',alignItems:'center',justifyContent:'flex-start'}}>*/}
//             {/*<Image style={{width:14/zoomW,height:14/zoomW,backgroundColor:'green'}}></Image>*/}
//             {/*<Text style={{fontSize:12,marginLeft:2/zoomW,color:'white'}}>安全护航员</Text>*/}
//         {/*</View>*/}
//         {/*<Text style={{fontSize:18,color:'white'}}>39<Text style={{fontSize:12}}> 人</Text></Text>*/}
//         {/*<Text style={{fontSize:13,color:'white'}}>本车护航员</Text>*/}
//     {/*</View>*/}
// {/*</Image>*/}
//
// <Image style={{marginLeft:7.5/zoomW,width:110/zoomW,height:70/zoomH,backgroundColor:'red',borderRadius:4}}>
//     <View style={{flex:1,justifyContent:'space-around',alignItems:'center'}}>
//         <View style={{width:110/zoomW,paddingLeft:7/zoomW,flexDirection:'row',alignItems:'center',justifyContent:'flex-start'}}>
//             <Image style={{width:14/zoomW,height:14/zoomW,backgroundColor:'green'}}></Image>
//             <Text style={{fontSize:12,marginLeft:2/zoomW,color:'white'}}>我的事件</Text>
//         </View>
//         <Text style={{fontSize:18,color:'white'}}>22<Text style={{fontSize:12}}> 件</Text></Text>
//         <Text style={{fontSize:13,color:'white'}}>已上报</Text>
//     </View>
// </Image>