RecommentProducts.js
4.15 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
'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('pic_url'), 140, 100, 2);
let salePrice = rowData?parseFloat(rowData.get('sales_price')):0;
let price = '¥' + salePrice.toFixed(2);
let product_id = rowData.get('product_id')?rowData.get('product_id'):0;
let rec_id = rowData.get('rec_id')?rowData.get('rec_id'):'';
let yh_exposureData = rowData && rowData.get('yh_exposureData') ? rowData.get('yh_exposureData').toJS() : {};
return (
<TouchableOpacity activeOpacity={0.5} yh_exposureData={yh_exposureData} onPress={() => {
let pos_id = 104;
let params = {
REC_POSE: 100023,
PRD_ID: product_id,
PRD_NUM: rowID,
ACTION_ID: 1,
REC_ID: rec_id,
};
ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_CHOOSE_FOR_YOU', params);
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 data = resource.get('data');
let dataGlobal = resource.get('dataGlobal');
let dataLimit = resource.get('dataLimit');
let productList = data.concat(dataGlobal);
productList = productList.concat(dataLimit);
if (!productList || productList.size == 0) {
return (<View style={{height:1,width:width,backgroundColor:'white'}}/>);
}
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',
},
});