InfoCell.js 4.11 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';
import DeviceInfo from 'react-native-device-info';

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);
        let fontFamilyStyle = {};
		if (Platform.OS === 'ios') {
			let systemVersion = DeviceInfo.getSystemVersion();
			systemVersion = parseFloat(systemVersion);
			if (systemVersion >= 9.0) {
				fontFamilyStyle = {fontFamily: 'PingFang SC'};
			}
		}
       // 商品缩略图
        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, fontFamilyStyle]}>
                        {dataSource.get('title')}
                    </Text>
                    <View style={styles.contentContainer}>
                        {dataSource.get('id') == 'VIPLevel'?
                            null
                            :<Text style={[styles.content,fontFamilyStyle]}>
                                {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');
const DEVICE_WIDTH_RATIO = width / 320;

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

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