InfoCell.js 3.67 KB
'use strict'

import React, {Component} from 'react';
import {
    StyleSheet,
    Dimensions,
    Platform,
    View,
    Text,
    Image,
    TouchableOpacity,
} from 'react-native';

import {Map} from 'immutable';
import YH_Image from '../../common/components/YH_Image';

export default class PersonalInfo extends Component {
    constructor(props) {
        super(props);
    }

    render() {
        let {dataSource} = this.props;
        let cellHeight = 44;
        if (dataSource.get('id') == 'portrait') {
            cellHeight = 60;
        }
        let withoutBottomLine = dataSource.get('withoutBottomLine');
        let imageUrl = '';
        if (dataSource.get('id') == 'portrait' && dataSource.get('url') == '') {
            imageUrl = require('../image/avatar_icon.png');
        } else if (dataSource.get('id') == 'VIPLevel') {
            switch (dataSource.get('content')) {
                case '1':
                    imageUrl = require('../image/VIP1.png');
                    break;
                case '2':
                    imageUrl = require('../image/VIP2.png');
                    break;
                case '3':
                    imageUrl = require('../image/VIP3.png');
                    break;
                default:
                    imageUrl = '';
            }
        } else if (dataSource.get('id') == 'mineQRCode') {
            imageUrl = require('../image/mine_qr.png');
        }
        let url = YH_Image.getSlicedUrl(dataSource.get('url'), 40, 40, 2);   // 商品缩略图
        return (
            <TouchableOpacity activeOpacity={1.0} onPress={() => {
				this.props.onPressInfoCell && this.props.onPressInfoCell(dataSource);
			}}>
            <View style={[styles.container,{height: cellHeight + (withoutBottomLine?0.0:0.5)}]}>
                <View style={[styles.contentContainer,{height: cellHeight}]}>

                    <Text style={styles.title}>
                        {dataSource.get('title')}
                    </Text>
                    <View style={styles.contentContainer}>
                        {dataSource.get('id') == 'VIPLevel'?
                            null
                            :<Text style={styles.content}>
                                {dataSource.get('content')}
                            </Text>
                        }
                        {dataSource.get('id') == 'portrait' && dataSource.get('url') != '' ?
                            <YH_Image url={url} style={styles.userImage} />
                            :null
                        }
                        {imageUrl==''?null:
                        <Image style={styles.arrow}
                            source={imageUrl}
                        />}
                        <Image style={styles.arrow}
                            source={require('../image/cell_indicator.png')}
                        />
                    </View>
                </View>
                {withoutBottomLine ? null:
                    <View style={{width: width,height: 0.5,backgroundColor: '#e5e5e5',}}/>
                }
            </View>
            </TouchableOpacity>
        );
    }
}

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

let styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'white',
    },
    title: {
        marginLeft: 15,
    },
    userImage: {
        width: 40,
        height: 40,
        borderRadius: 20,
        marginRight: 15,
    },
    content:{
        color: '#b0b0b0',
        marginRight: 14,
        fontSize: 12,
    },
    contentContainer: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',

    },
    arrow: {
        marginRight: 15,
    }
});