Comments.js 4.91 KB
'use strict';

import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
import {getSlicedUrl} from '../../../classify/utils/Utils';
import YH_Image from '../../../common/components/YH_Image';

const {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Image,
  ListView,
  Dimensions,
  TouchableOpacity,
} = ReactNative;


export default class Comments extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        let {resource} = this.props;
        console.log('ddddd');
        console.log(resource.toJS());
        let avator = resource?resource.get('avator'):'';
        let username = resource?resource.get('username'):'';
        let content = resource?resource.get('content'):'';
        let isPraise = resource?resource.get('isPraise'):'N';
        let praiseNum = resource&&resource.get('praiseNum') ? resource.get('praiseNum'):0;
        praiseNum = praiseNum > 999 ? '999+' : praiseNum;

        let id = resource?resource.get('id'):0;
        let create_time = resource?resource.get('create_time'):'';

        let relayTo = resource?resource.get('relayTo'):null;
        let relayToUsername = relayTo?relayTo.get('username'):'';

        let thumbsUpIcon = isPraise=='Y' ? require('../../image/g_z_ic_h.png') : require('../../image/g_z_ic.png');

        let uid = resource? resource.get('uid'):'';
		return (
			<View style={styles.container}>
				<View style={styles.rightContainer}>
					<YH_Image url={avator} style={styles.icon}
                        radius={{'topLeft':'60','topRight':'60','bottomRight':'60','bottomLeft':'60'}}
                        masksToBounds={true} />
				</View>
				<View style={styles.leftContainer}>
					<View style={styles.headerContainer}>
						<Text style={styles.name} numberOfLines={1}>{username}</Text>
                        <TouchableOpacity onPress={()=>{
                            this.props.onThumbsUp&&this.props.onThumbsUp(id,isPraise=='Y'?'N':'Y', uid)
                        }}>
                            <View style={styles.thumbsUp}>
                                <Image style={styles.thumbsUpIcon} source={thumbsUpIcon}/>
                                <Text style={styles.thumbsUpNum} numberOfLines={1} >{praiseNum}</Text>
                            </View>
                        </TouchableOpacity>
                        <Text style={styles.time}>{create_time}</Text>
					</View>
                    <View style={styles.commentView}>
                        <TouchableOpacity onPress={()=>{this.props.onPressComment&&this.props.onPressComment(id,username)}}>
                            {relayTo ? <Text style={styles.commentText}>
                                回复:<Text style={styles.replayName}>{relayToUsername}</Text>
                                :<Text style={styles.commentText}>{content}</Text>
                            </Text> : <Text style={styles.commentText}>{content}</Text>}
                        </TouchableOpacity>
                    </View>
                    <View style={styles.line}/>
				</View>
			</View>
		);
    }
};

let {width, height} = Dimensions.get('window');

let styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'white',
        flexDirection: 'row'
    },
    rightContainer: {
        width: 60,
        backgroundColor: 'white',
    },
    leftContainer: {
        flex: 1,
        width: width - 60,
        backgroundColor: 'white',
    },
	icon: {
		height: 36,
		width: 36,
		borderRadius: 18,
		position: 'absolute',
		left: 14,
		top: 8,
	},
	headerContainer: {
		height: 50,
		width: width - 60,
		backgroundColor: 'white',
        alignItems: 'center',
        flexDirection: 'row',
        justifyContent: 'space-between',

	},
	name: {
		textAlign: 'left',
		backgroundColor: 'white',
		fontSize: 15,
        fontWeight: 'bold',
        width: width - 60 - 100,
	},
    thumbsUp: {
        height: 50,
        width: 100,
        backgroundColor: 'white',
        alignItems: 'center',
        justifyContent: 'flex-end',
        flexDirection: 'row',
        marginRight: 10,
    },
    thumbsUpIcon: {
        height: 24,
        width: 24,
    },
    thumbsUpNum: {
        marginLeft: 5,
        textAlign: 'left',
        backgroundColor: 'white',
        fontSize: 12,
        color: 'gray',
        width: 35,
    },
    time: {
        position: 'absolute',
        textAlign: 'left',
        backgroundColor: 'white',
        fontSize: 11,
        color: 'gray',
        bottom: 0,
    },
    commentView: {
		width: width - 60 - 10,
		backgroundColor: 'white',
        marginTop: 10,
    },
    commentText: {
        textAlign: 'left',
		backgroundColor: 'white',
		fontSize: 15,
    },
    replayName: {
        textAlign: 'left',
		backgroundColor: 'white',
		fontSize: 15,
        fontWeight: 'bold',
    },
    line: {
        marginTop: 15,
        width: width-80,
        height: 1,
        backgroundColor: '#e0e0e0',
    },
});