ShopRecommend.js
3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'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';
import SlicedImage from '../../../common/components/SlicedImage';
/**
* 好店推荐楼层,
* 这个楼层是滚动的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;
let realIndex = 0;
if (type == 'favorite') {
let shopId = event.nativeEvent.shopId;
this.props.onPressShopFavorite && this.props.onPressShopFavorite(shopId, index);
} else {
let {list} = this.props.data.toJS();
let url = event.nativeEvent.url;
let shopId = event.nativeEvent.shopId;
let type = event.nativeEvent.type;
let imageUrl = '';
for (var i = 0; i < list.length; i++) {
let shopItem = list[i];
if (shopId == shopItem.shopId) {
if (type == 'top') {
realIndex = i * 4 + 1;
imageUrl = shopItem.src && SlicedImage.getSlicedUrl(shopItem.src, 240*DEVICE_WIDTH_RATIO, 116*DEVICE_WIDTH_RATIO, 2);
} else if (type == 'left') {
realIndex = i * 4 + 2;
imageUrl = shopItem.goods0 && shopItem.goods0.src && SlicedImage.getSlicedUrl(shopItem.goods0.src, 80*DEVICE_WIDTH_RATIO, 106*DEVICE_WIDTH_RATIO, 2);
} else if (type == 'right') {
realIndex = i * 4 + 4;
imageUrl = shopItem.goods2 && shopItem.goods2.src && SlicedImage.getSlicedUrl(shopItem.goods2.src, 80*DEVICE_WIDTH_RATIO, 106*DEVICE_WIDTH_RATIO, 2);
} else if (type == 'center') {
realIndex = i * 4 + 3;
imageUrl = shopItem.goods1 && shopItem.goods1.src && SlicedImage.getSlicedUrl(shopItem.goods1.src, 80*DEVICE_WIDTH_RATIO, 106*DEVICE_WIDTH_RATIO, 2);
}
break;
}
}
this.props.onPressShopRecommendItem && this.props.onPressShopRecommendItem(url, imageUrl, realIndex);
}
}
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_exposureData={title.yh_exposureData}/>
<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,
},
});