ProductListCell.js
10.4 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
'use strict';
import React, {Component} from 'react';
import ReactNative, {
View,
Text,
Image,
Platform,
ListView,
StyleSheet,
Dimensions,
TouchableOpacity,
} from 'react-native';
import Tags from './Tags';
import GPTags from './GPTags';
import DeleteLineText from '../DeleteLineText';
import YH_Image from '../YH_Image';
import Immutable, {Map} from 'immutable';
import DeviceInfo from 'react-native-device-info';
export default class ProductListCell extends Component {
constructor(props) {
super(props);
this._renderTags = this._renderTags.bind(this);
this._renderImages = this._renderImages.bind(this);
this._renderPrice = this._renderPrice.bind(this);
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.data, this.props.data)
&& nextProps.similarIndex == this.props.similarIndex
&& nextProps.rowID == this.props.rowID) {
return false;
} else {
return true;
}
}
_renderTags() {
let {data, sourceType} = this.props;
let isGlobalProduct = data.get('is_global') && data.get('is_global') == 'Y'; // 是否全球购商品
return <Tags items={data.get('tags')}/>;
if (isGlobalProduct) {
let showGPLimitTag = data.get('is_limited') && data.get('is_limited') == 'Y'; // 全球购限量商品
let countryName = data.get('country_name'); // 全球购国家名称
return <GPTags title={countryName} limit={showGPLimitTag}/>;
} else {
return <Tags items={data.get('tags')}/>;
}
}
_renderImages() {
let {data, sourceType, similarIndex, rowID, showSimilarGuider} = this.props;
let url = data.get('default_images', '').replace('{mode}', 2)
.replace(/{width}/g, 290)
.replace(/{height}/g, 386);
// if (Platform.OS === 'ios') {
// let systemVersion = DeviceInfo.getSystemVersion();
// let versionArray = systemVersion.split('.');
// let version = versionArray[0];
// if (version == 9) {
// url = data.get('default_images', '').replace('{mode}', 2)
// .replace(/{width}/g, 290/2)
// .replace(/{height}/g, 386/2);
// }
// }
let isGlobalProduct = data.get('is_global') && data.get('is_global') == 'Y'; // 是否全球购商品
if (isGlobalProduct) {
let showGPSoldOut = isGlobalProduct && data.get('is_stock') && data.get('is_stock') == 'Y'; // 全球购售罄
return (
<View style={styles.imageContainer}>
<YH_Image style={styles.image} url={url}>
{showGPSoldOut ? <Image style={styles.gpSoldOutImage} source={require('../../images/tag/gp_tip_SQ.png')}/> : null}
</YH_Image>
</View>
);
} else {
let showAlmostSoldOut = data.get('tags', []).indexOf('is_soon_sold_out') !== -1; // 非全球购的即将售罄
let showSoldOut = data.get('tags', []).indexOf('is_solded') !== -1; // 非全球购的即将售罄
let showOutletSoldOut = sourceType == 2 && data.get('storage_num') && data.get('storage_num') == 0; // 数据源是奥莱才显示
return (
<View style={styles.imageContainer}>
<YH_Image style={styles.image} url={url}>
{showAlmostSoldOut ? <Image style={styles.almostSoldOutImage} source={require('../../images/tag/tip_jjsq.png')}/> : null}
{showOutletSoldOut ? <Image style={styles.soldOutImage} source={require('../../images/tag/outlet_sellout_bg.png')}/> : null}
{showSoldOut ? <Image style={styles.almostSoldOutImage} source={require('../../images/tag/tip_ysq.png')}/> : null}
</YH_Image>
</View>
);
}
}
_renderPrice() {
let {data, sourceType, fromPage} = this.props;
let isGlobalProduct = data.get('is_global') && data.get('is_global') == 'Y'; // 是否全球购商品
let salePrice = 0; // 售卖价
let originPrice = 0; // 原价
let salePriceStr = ''; // 拼接的售卖价
let originPriceStr = ''; // 拼接的原价
let showOriginPrice = true; // 是否显示原价
let salePriceColor = '#d0021b'; // 不显示原价时,售卖价颜色
if (isGlobalProduct) {
salePrice = parseFloat(data.get('final_price'));
originPrice = parseFloat(data.get('orign_price'));
salePriceStr = data.get('formart_final_price');
originPriceStr = data.get('formart_orign_price');
} else {
salePrice = parseFloat(data.get('sales_price'));
originPrice = parseFloat(data.get('market_price'));
salePriceStr = '¥' + salePrice.toFixed(2);
originPriceStr = '¥' + originPrice.toFixed(2);
}
if (!originPrice || (salePrice == originPrice)) {
showOriginPrice = false;
salePriceColor = '#444444';
}
//新品到着升级为sectionList后价格会被遮挡
let priceMarginTop = Math.ceil(-4 * DEVICE_WIDTH_RATIO);
return (
<View style={[styles.priceContainer, {marginTop: priceMarginTop,} ]}>
<Text style={[styles.nowPrice, {color: salePriceColor}]} numberOfLines={1}>{salePriceStr}</Text>
{showOriginPrice ? <DeleteLineText
style={styles.oldPriceContainer}
textStyle={styles.oldPrice}
lineStyle={styles.deleteLine}
text={originPriceStr}
/> : null}
</View>
);
}
render() {
let {data, sourceType, similarIndex, rowID, style, needShopCar} = this.props;
let name = data.get('product_name') ? data.get('product_name') : '';
let yh_exposureData = data && data.get('yh_exposureData') ? data.get('yh_exposureData').toJS() : {};
let is_limitbuy = data.get('is_limitbuy') && data.get('is_limitbuy') == 'Y';
let prd_id = data.get('product_id') ? data.get('product_id') : '';
let isGlobal = data.get('is_global') && data.get('is_global') == 'Y'; // 是否全球购商品
let product_skn = data.get('product_skn') ? data.get('product_skn') : '';
return (
<TouchableOpacity
style={[styles.container, style]}
activeOpacity={1}
yh_exposureData={yh_exposureData}
onPress={() => {
this.props.onPressProduct && this.props.onPressProduct(data, rowID);
}}
>
<View style={{overflow: 'hidden'}} >
{this._renderTags()}
{this._renderImages()}
<View style={styles.nameContainer}>
<Text style={styles.name} numberOfLines={2}>{name}</Text>
</View>
{this._renderPrice()}
</View>
{!is_limitbuy && needShopCar ?
<TouchableOpacity style={[styles.typeShopCar,style]} activeOpacity={0.5} onPress={() => {
let pos_id = 106;
this.props.onPressShopCar && this.props.onPressShopCar(product_skn,prd_id,pos_id,isGlobal);
}}>
<Image source={require('../../../guang/image/jgwc_bt.png')} style={styles.button} resizeMode={'contain'}></Image>
</TouchableOpacity>
:
null
}
</TouchableOpacity>
);
}
}
let {width, height} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 320;
let rowWidth = Math.ceil(137.5 * DEVICE_WIDTH_RATIO);
let rowHeight = Math.ceil(260 * DEVICE_WIDTH_RATIO);
let rowMarginTop = Math.ceil(4 * DEVICE_WIDTH_RATIO);
let rowMarginBottom = Math.ceil(4 * DEVICE_WIDTH_RATIO);
const IMAGE_WIDTH = 145;
const IMAGE_HEIGHT = 193;
const IMAGE_RATIO = IMAGE_HEIGHT / IMAGE_WIDTH;
let imageTop = 14 * DEVICE_WIDTH_RATIO;
let imageHeight = rowWidth * IMAGE_RATIO;
let almostSoldOutImageHeight = Math.ceil(14 * DEVICE_WIDTH_RATIO);
let almostSoldOutImageTop = imageHeight - almostSoldOutImageHeight;
let nameMarginTop = Math.ceil(12 * DEVICE_WIDTH_RATIO);
let nameHeight = Math.ceil(36 * DEVICE_WIDTH_RATIO);
let gpSoldOutImageHeight = Math.ceil(25 * DEVICE_WIDTH_RATIO);
let styles = StyleSheet.create({
container: {
width: rowWidth,
height: Platform.OS === 'ios'?rowHeight+2:rowHeight+4,
marginTop: rowMarginTop,
marginBottom: rowMarginBottom,
overflow: 'hidden',
},
rowContainer: {
width: rowWidth,
height: Platform.OS === 'ios'?rowHeight:rowHeight+4,
},
imageContainer: {
width: rowWidth,
height: imageHeight,
backgroundColor: '#f0f0f0',
},
image: {
width: rowWidth,
height: imageHeight,
backgroundColor: '#f0f0f0',
},
soldOutImage: {
position: 'absolute',
top: 0,
left: 0,
width: rowWidth,
height: imageHeight,
},
almostSoldOutImage: {
top: almostSoldOutImageTop,
width: rowWidth,
height: almostSoldOutImageHeight,
backgroundColor: '#ff9e0d',
},
nameContainer: {
// justifyContent: 'center',
marginTop: nameMarginTop,
width: rowWidth,
height: nameHeight,
},
name: {
fontFamily: 'STHeitiSC-Light',
fontSize: 12,
color: '#444444',
},
priceContainer: {
flexDirection: 'row',
},
nowPrice: {
fontSize: 12,
color: '#d0021b',
},
oldPriceContainer: {
flexDirection: 'row',
marginLeft: 5,
},
oldPrice: {
fontSize: 12,
color: '#b0b0b0',
height: 16,
},
deleteLine: {
position: 'absolute',
top: (16 / 2) - 0.8,
left: 0,
right: 0,
height: 1,
backgroundColor: '#b0b0b0',
},
gpSoldOutImage: {
position: 'absolute',
top: 5,
right: 5,
width: gpSoldOutImageHeight,
height: gpSoldOutImageHeight,
},
typeShopCar: {
position: 'absolute',
bottom: 0,
left: rowWidth - 40,
width: 40,
height: 23,
},
button: {
width: 40,
height: 23,
},
});