CommentRrise.js 9.06 KB
/**
 * Created by Cassie on 2018/05/14
 * 图文详情-评论点赞
 */
import React, {Component} from 'react';
import {FlatList,ActivityIndicator, Image, StatusBar, StyleSheet, Text, TouchableOpacity, View} from 'react-native';
import {zoomH, zoomW} from '../../utils/getSize';
import {getHeaderPadding,xnToast} from '../../utils/utils';
import AppService from "../../service/AppService";

const defaultIcon = require('../../img/defaultIcon.png');
const vIcon = require('../../img/v.png');
const prise = require('../../img/prise.png');
const writeIcon = require('../../img/writeIcon.png');
const emj = require('../../img/emj.png');
const forwarding = require('../../img/forwarding.png');
const reward = require('../../img/reward.png');
const back = require('../../img/back.png');
const  pageSize = 20;

export default class CommentPrise extends Component {

    static navigationOptions = ({ navigation, screenProps }) => ({
        header:null,

    });
    constructor(props){
        super(props);
        this.state = {
            praiseList:[],//点赞人数集合
            loadMore:false,
            loading:false,
        };
    };
    componentWillMount(){
        this.getPriseList();
    };
    componentDidMount(){

    };

    //获取赞列表
    getPriseList  (){
        if (!global.isConnected){
            xnToast('暂无网络连接,请稍后重试!');
            return;
        }
        let length =  this.state.praiseList.length;
        if (length % pageSize == 0 && !this.state.loadMore) {
            let  data = this.props.navigation.state.params.detailInfo;
            let params = {
                tenantId:global.tenantId,//承租人ID
                forumId:data.forumId,//社区id
                boardId:data.boardId,//板块id
                threadId:data.threadId,//帖子id
                targetType: 1,//点赞类型0:帖子点赞 1:评论点赞 2:回复点赞  3:转发点赞
                targetId:data.id,//点赞对象ID
                isActive:true,
                pageNumber:length/pageSize+1,
                pageSize : pageSize,
            };

            this.setState({
                loadMore: true,
                loading:true,
            });
            AppService.queryLike(params).then((data) => {
                this.setState({
                    loadMore: false,
                    loading:false,
                });
                if (data.message) {
                    xnToast(data.message);
                    return;
                }
                if (data.errors.length > 0) {
                    xnToast(data.errors[0].message);
                } else {
                    if (length + data.result.length > data.totalCount) {
                        return;
                    }
                    this.setState({
                        praiseList:this.state.praiseList.concat(data.result),
                    })
                }
            }).catch((error) => {
                this.setState({
                    loadMore: false,
                    loading:false,
                });
                xnToast(error)
            })
        }

    };


    //去个人详情页面
    toPersonalInfo(id){
        if (id == global.userId){
            //自己
            this.props.navigation.navigate("MyPage",{id:id});
            return;
        }

        this.props.navigation.navigate('PersonalHomePage',{'userId':id});
    }


    //渲染评论item
    keyExtractor = (item,index) => index;
    renderItem({item,index}){
        return (
            <TouchableOpacity style = {{paddingLeft:15/zoomW,paddingTop:10/zoomH,paddingBottom:10/zoomH}}
                              onPress = {()=>{this.toPersonalInfo(item.likeUserId)}}>
                <View style={{flexDirection:'row',alignItems:'center'}}>
                    <View style={styles.commonAvatar} >
                        <Image  style={styles.commonAvatar} source={!!item.userExtend && !!item.userExtend.avatar
                            ?{uri:item.userExtend.avatar +'?x-oss-process=image/resize,w_100'} :defaultIcon} resizeMode="cover" />
                        {!!item.userExtend && !!item.userExtend.isAuthented &&<Image  style={styles.commonAvatarV} source={vIcon} resizeMode="cover" />}
                    </View>
                    <View style = {{width:'100%',flex:1,paddingLeft:10/zoomW,paddingRight:10/zoomW}}>
                        <View style = {{flexDirection:'row'}}>
                            <Text style = {{fontSize: 16,color:'#000000'}}>{item.likeUserName}</Text>
                            {/*暂时隐藏作者*/}
                            { 1==2 && this.props.navigation.state.params.userId == item.likeUserId &&
                             <Text style = {{fontSize: 10,color:'#576B95',borderColor:'#576B95',borderWidth:StyleSheet.hairlineWidth,borderRadius:2,
                                paddingLeft:5,paddingRight:5,alignSelf:'center',marginLeft:5/zoomW}}>作者</Text>
                            }
                        </View>
                        { !!item.userExtend && <Text style = {{fontSize: 12,color:'#c3c3c3'}}>{item.userExtend.agentName}</Text>}


                    </View>
                </View>
                <View style = {[styles.commonDividerLine,{marginTop:20/zoomH,marginLeft:46/zoomW}]}></View>

            </TouchableOpacity>
        );

    }

    render(){
        return(
            <View style={styles.background}>
                <StatusBar
                    backgroundColor={'#B0B1B1'}
                    networkActivityIndicatorVisible
                />
                <View style = {{height:getHeaderPadding(),backgroundColor:'#ffffff'}}>
                </View>
                <View style = {styles.backgroundRadius}>
                    {/*头部*/}
                    <View  style = {{flexDirection:'row',alignItems:'center',height:48/zoomH}}>
                        <View style={{width:'100%',flexDirection:'row',justifyContent:'center'}}>
                            <Text style = {{flex:1,color:'rgba(0,0,0,0.85)', textAlign: "center",
                                alignSelf: "center",fontSize:16}}>{ this.props.navigation.state.params.length +'人点赞'}</Text>
                        </View>
                        <TouchableOpacity style = {{position:'absolute',padding:15/zoomW}} activeOpacity={0.8} onPress = {()=>{this.props.navigation.goBack()}}>
                            <Image style = {{width:15/zoomW,height:15/zoomW}} resizeMode='contain' source={back}></Image>
                        </TouchableOpacity>
                    </View>

                    <View style = {styles.commonDividerLine}></View>

                    <FlatList  refreshing={false}
                               onEndReachedThreshold={0.01}
                               onEndReached={() => this.getPriseList()}
                               keyExtractor={this.keyExtractor}
                               data={this.state.praiseList}
                               renderItem={this.renderItem.bind(this)}/>
                    {/*局部loading*/}
                    { this.state.loading && (
                        <View style={styles.loadingBg}>
                            <View style={styles.loadingBox}>
                                <ActivityIndicator size="large" color="#fff" />
                                <Text
                                    style={{ fontSize: 16, color: "#fff", marginTop: 6 / zoomH }}
                                >
                                    加载中...
                                </Text>
                            </View>
                        </View>
                    )}

                </View>

            </View>

        );
    }
}

const styles = StyleSheet.create({
    background:{
        flex: 1,
        backgroundColor: 'rgba(0,0,0,0.50)',

    },
    backgroundRadius:{
        flex: 1,
        backgroundColor: '#ffffff',
        borderTopLeftRadius:5,
        borderTopRightRadius:5,
        borderColor:'rgba(0,0,0,0.50)',
        borderWidth:1,

    },

    commonSpaceBetween:{
        flexDirection:'row',
        justifyContent:'space-between',

    },
    commonRow:{
        flexDirection:'row',
        paddingLeft:15/zoomW,
        paddingRight:15/zoomW,

    },
    commonAvatar:{
        width:36/zoomH,
        height:36/zoomH,
        borderRadius:18/zoomH,
    },
    commonAvatarV:{
        width:10/zoomH,height:10/zoomH,position:'absolute',right:1/zoomW,bottom:1/zoomW
    },
    itemBackground:{
        width:'100%',
        flex:1,
        padding: 10/zoomH,
        flexDirection :'row',
        marginBottom:10/zoomW
    },
    commonDividerLine:{
        width:'100%',
        height:StyleSheet.hairlineWidth,
        backgroundColor:'#eeeeee'
    },
    loadingBg: {
        position: "absolute",
        top: 0,
        width: "100%",
        height: "100%",
        display: "flex",
        justifyContent: "center",
        alignItems: "center"
    },
    loadingBox: {
        width: 100 / zoomW,
        height: 120 / zoomH,
        backgroundColor: "rgba(0,0,0,.5)",
        borderRadius: 8,
        display: "flex",
        alignItems: "center",
        justifyContent: "center"
    },


});