Comments.js 4.54 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;
        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'):0;
        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/sc_icon.png') : require('../../image/wsc_icon.png');

		return (
			<View style={styles.container}>
				<View style={styles.rightContainer}>
					<YH_Image url={avator} style={styles.icon}/>
				</View>
				<View style={styles.leftContainer}>
					<View style={styles.headerContainer}>
						<Text style={styles.name}>{username}</Text>
                        <TouchableOpacity onPress={()=>{
                            this.props.onThumbsUp&&this.props.onThumbsUp(id,isPraise=='Y'?'N':'Y')
                        }}>
                            <View style={styles.thumbsUp}>
                                <Image style={styles.thumbsUpIcon} source={thumbsUpIcon}/>
                                <Text style={styles.thumbsUpNum}>{praiseNum}</Text>
                            </View>
                        </TouchableOpacity>
                        <Text style={styles.time}>{create_time}</Text>
					</View>
                    <View style={styles.commentView}>
                        <TouchableOpacity onPress={()=>{this.props.onComment&&this.props.onComment(id)}}>
                            {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',
	},
    thumbsUp: {
        height: 50,
        width: 150,
        backgroundColor: 'white',
        alignItems: 'center',
        justifyContent: 'flex-end',
        flexDirection: 'row',
        marginRight: 10,
    },
    thumbsUpIcon: {
        height: 20,
        width: 20,
    },
    thumbsUpNum: {
        marginLeft: 5,
        textAlign: 'left',
        backgroundColor: 'white',
        fontSize: 12,
        color: 'gray',
        width: 25,
    },
    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',
    },
});