VipUserFloor.js 5.67 KB
/**
 * Description:
 * vipUse:VIP专享
 * Author:  Bruce.Lu
 * Version: 1.0
 * Created on 2017/2/14.
 */
import React, {Component} from 'react';
import ReactNative, {
    Image,
    Text,
    StyleSheet,
    ListView,
    View,
    TouchableOpacity,
    Dimensions,
} from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';
import Immutable from 'immutable';
import SlicedImage from '../../../common/components/SlicedImage';
import HeadTitleCell from '../cell/HeadTitleCell';
import ImageSlider from '../cell/ImageSlider';
import YH_Image from '../../../common/components/YH_Image';

export default class VipUserFloor extends Component {
    constructor(props) {
        super(props);
        this.renderRow = this.renderRow.bind(this);
        this.dataSource = new ListView.DataSource({
            rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
        });
    }

    renderRow(rowData, sectionID, rowID, highlightRow) {
        let data = this.props.data;
        let banner = data.get("banner_image");
        let bannerLength = banner.toJS().length;
        let index = parseInt(rowID)+bannerLength;

        let productName = rowData.get('product_name');;
        let productPrice = '¥'+rowData.get('vip1_price').toFixed(2);
        let orginPrice = '¥'+rowData.get('market_price').toFixed(2);
        let productId = rowData.get('product_id');
        let productSkn = rowData.get('product_skn');
        let imgUrl = SlicedImage.getSlicedUrl(rowData.get('default_images'),cellWidth,120,2);

        let yh_exposureData = rowData.get('yh_exposureData') ? rowData.get('yh_exposureData').toJS() : null;

        return (
            <TouchableOpacity style={styles.row} yh_exposureData={yh_exposureData}
              onPress={()=>this.props.onPressVipProduct && this.props.onPressVipProduct(rowData, imgUrl, index + rowID)}>
                <YH_Image style={styles.image}
                       url={imgUrl}
                       />
                <Text style={styles.vipText} numberOfLines={1}>{productPrice}</Text>
                <View style={styles.vipContainer}>
                    <Text style={styles.discountText} numberOfLines={1}>{orginPrice}</Text>
                    <Image style={{width:33,height:12,marginLeft:2}}
                           source={require('../../images/yh_home_vipUser_vip_icon.png')}/>
                </View>
            </TouchableOpacity>);
    }

    render() {
        let data = this.props.data;
        let title = data.get('title').get('title');
        let moreUrl = data.get('title').get('more_url');
        let bgUrl = data.get('background').get('src');
        let visible = bgUrl ? true : false;
        let bannerData = data.get('banner_image');
        let productData = data.get('list');

        let yh_exposureDataTitle = (data.get('title') && data.get('title').get('yh_exposureData')) ? data.get('title').get('yh_exposureData').toJS() : null;

        return (
            <View style={styles.container}>
                <HeadTitleCell title={title} moreUrl={moreUrl} 
                    onPressTitleMore={this.props.onPressTitleMore} yh_exposureData={yh_exposureDataTitle}/>
                <ImageSlider
                    resource={bannerData}
                    sliderWidth={width}
                    sliderHeight={bannerHeight}
                    onPressSlideItem={this.props.onPressVipBannerItem}
                />

                <View style={styles.listContianer}>
                    {visible ?
                        <YH_Image style={styles.listBg}
                               url={SlicedImage.getSlicedUrl(bgUrl,width,cellHeight,2)}
                               /> : null}
                    <ListView
                        style={{position:'absolute',left:0,top:5,paddingTop:12,paddingBottom:12}}
                        contentContainerStyle={styles.listContent}
                        horizontal={true}
                        dataSource={this.dataSource.cloneWithRows(productData.toArray())}
                        renderRow={this.renderRow}
                        showsHorizontalScrollIndicator={false}
                    />
                </View>

            </View>
        );
    }
}

let {width, height} = Dimensions.get('window');
let bannerHeight = Math.ceil((234 / 750) * width);
let sectionHeight = Math.ceil((419 / 750) * width);
let cellWidth = 90;
let cellHeight = 210;

const styles = StyleSheet.create({
    container: {
        backgroundColor: 'white',
        width:width,
        height:40+bannerHeight+cellHeight
    },
    listContianer: {
        width:width,
        height: cellHeight,
        alignItems: 'center',
    },
    listBg: {
        width: width,
        height: cellHeight,
    },
    listContent: {
        backgroundColor: 'transparent',
        flexDirection: 'row',
        flexWrap: 'nowrap',
        justifyContent: 'flex-start',
        paddingHorizontal: 5,
    },
    row: {
        flexDirection: 'column',
        width: cellWidth,
        backgroundColor: '#f0f0f0',
        borderRadius: 3,
        justifyContent: 'center',
        marginLeft: 6,
        marginRight: 6
    },
    vipContainer: {
        width: cellWidth,
        height: 18,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'center',
        marginBottom: 10
    },
    discountText: {
        fontSize: 10,
        textAlign: 'center',
        color: '#b0b0b0',
        textDecorationLine: 'line-through',
        textDecorationStyle: 'solid',
        textDecorationColor: '#d0021b'
    },
    vipText: {
        color: '#d0021b',
        flex: 1,
        marginTop: 7,
        marginBottom: 7,
        textAlign: 'center',
        fontSize: 12,
    },
    image: {
        width: cellWidth,
        height: 120,
    },
});