RecommentProducts.js
3.29 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import {getSlicedUrl} from '../../../classify/utils/Utils';
import Immutable, {Map} from 'immutable';
import YH_Image from '../../../common/components/YH_Image';
import DeviceInfo from 'react-native-device-info';
const {
AppRegistry,
StyleSheet,
Text,
View,
Image,
ListView,
Dimensions,
TouchableOpacity,
PixelRatio,
Platform,
} = ReactNative;
export default class RecommentProducts extends React.Component {
constructor(props) {
super(props);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.resource, this.props.resource)) {
return false;
} else {
return true;
}
}
renderRow(rowData,sectionID,rowID,highlightRow) {
let newSrc = getSlicedUrl(rowData.get('default_images'), 140, 100, 2);
let salePrice = rowData?parseFloat(rowData.get('sales_price')):0;
let price = '¥' + salePrice.toFixed(2);
return (
<TouchableOpacity activeOpacity={0.5} onPress={() => {
let pos_id = 104;
this.props.onPressProduct && this.props.onPressProduct(rowData,rowID,pos_id);
}}>
<View style={styles.thumbnailV}>
<YH_Image
url={newSrc}
style={styles.thumbnail}
/>
<View style={styles.titleView}>
<Text style={styles.price}>{price}</Text>
</View>
</View>
</TouchableOpacity>
);
}
render() {
let {resource} = this.props;
let productList = resource.get('productList');
if (!productList || productList.size == 0) {
return null;
}
return (
<View style={styles.cellList}>
<View style={{width: width,height: 15,backgroundColor: '#f0f0f0'}}/>
<ListView
dataSource={this.dataSource.cloneWithRows(productList.toArray())}
horizontal={true}
renderRow={this.renderRow.bind(this)}
showsHorizontalScrollIndicator={false}
/>
</View>
);
}
};
let {width, height} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 750;
let imageHeight = Math.ceil(225 * DEVICE_WIDTH_RATIO);
let imageWidth = Math.ceil(175 * DEVICE_WIDTH_RATIO);
let itemHeight = imageHeight + 30 + 15;
let styles = StyleSheet.create({
cellList:{
justifyContent: 'center',
width: Dimensions.get('window').width,
height: itemHeight,
backgroundColor: 'white',
},
thumbnailV: {
marginLeft: 15,
marginTop: 15,
width: imageWidth,
height: imageHeight,
backgroundColor: 'white',
},
thumbnail: {
width: imageWidth,
height: imageHeight,
backgroundColor: 'white',
},
titleView: {
width: imageWidth,
height: 20,
position: 'absolute',
backgroundColor: 'rgba(0,0,0,0.5)',
top: imageHeight - 20,
justifyContent: 'center',
},
price: {
width: imageWidth,
fontSize: 15,
backgroundColor: 'transparent',
color: 'white',
textAlign: 'center',
},
});