ShopRecommend.js 2.12 KB
'use strict';

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

import Immutable, {Map} from 'immutable';
import HeadTitleCell from '../cell/HeadTitleCell';
import YH_GoodsStore from '../../../common/components/YH_GoodsStore';


/**
 *   好店推荐楼层,
 *   这个楼层是滚动的3D大图
 **/
export default class ShopRecommend extends Component{

	constructor(props) {
	   super(props);

       this.onClick = this.onClick.bind(this);
	}

    shouldComponentUpdate(nextProps){
        if (Immutable.is(nextProps.data, this.props.data) 
            && Immutable.is(nextProps.favoriteState, this.props.favoriteState)) {
            return false;
        } else {
            return true;
        }
    }

    onClick(event: Event) { 
        let type = event.nativeEvent.type;
        let index = event.nativeEvent.index;
        if (type == 'favorite') {
            let shopId = event.nativeEvent.shopId;
            this.props.onPressShopFavorite && this.props.onPressShopFavorite(shopId, index);
        } else {
            let url = event.nativeEvent.url;;
            this.props.onPressShopRecommendItem && this.props.onPressShopRecommendItem(url, index);
        }
    }
    
	render(){
        let {title, list} = this.props.data.toJS();
        let state = this.props.favoriteState.toJS();
		return (
            <View style={styles.container}>
                <HeadTitleCell title={title.name} moreUrl={title.more_url} onPressTitleMore={this.props.onPressTitleMore} />
                <YH_GoodsStore style={styles.store} dataSource={list} favoriteState={state} onClick={this.onClick}/>
            </View>
        );
	}

};

let {width} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 375;

let storeHeight = Math.ceil(239 * DEVICE_WIDTH_RATIO + 10);
let containerHeight = 40 + storeHeight;

let styles = StyleSheet.create({
    container: {
        width,
        height: containerHeight,
        backgroundColor: '#f0f0f0',
    },
	store: {
        width: width,
        height: storeHeight,
    },



});