SingleImage.js
4.41 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
import YH_Image from '../../../common/components/YH_Image';
const {
View,
Text,
TouchableOpacity,
Dimensions,
StyleSheet,
Platform,
} = ReactNative;
export default class SingleImage extends React.Component {
constructor(props) {
super (props);
}
shouldComponentUpdate(nextProps,nextState){
if (Immutable.is(nextProps.resource, this.props.resource)) {
return false;
} else {
return true;
}
}
render() {
let {resource} = this.props;
if (!resource) {
return null;
}
let list = resource.get('module_data').get('data').toJS();
let data = list?list[0]:null;
let backgroundImage = data.pic;
let linkType = data.linkType;
let showProductInfo = true;
if (data.showProductInfo && !data.showProductInfo) {
showProductInfo = false;
}
let properties = resource.get('module_data').get('properties').toJS();
let imageW = properties.width;
let imageH = properties.height;
imageW = imageW ? imageW : width;
imageH = imageH ? imageH : 200
let isModuleMargin = properties.isModuleMargin;
let imageHeight = (imageH*width)/(imageW==0?1:imageW);//根据返回信息计算出高度
let backgroundHeight =isModuleMargin=='1'?(imageHeight+10):imageHeight;
let product = data.product;
if (!product) {
showProductInfo = false;
}
let salePrice = product?parseFloat(product.sales_price):0;
let originPrice = product?parseFloat(product.market_price):0;
let name = product?product.product_name:'';
let price = '¥' + salePrice.toFixed(2);
let sale = '¥' + originPrice.toFixed(2);
let saleAble = false;//salePrice>0?true:false;
let linkReource = data.resource;
let moduleOrder = resource.get('module_order') + 1;
let moduleType = resource.get('module_type');
let yh_exposureData = this.props.yh_exposureData?this.props.yh_exposureData:null;
let url = '';
if (linkType == '0') {
url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.poollist","params":{"productPool":"${linkReource}"}}`;
} else if (linkType == '1') {
url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${linkReource}"}}`;
} else if (linkType == '2') {
url = linkReource;
}
if (yh_exposureData) {
yh_exposureData = {
I_INDEX: 0,
ACTION_URL: url,
...yh_exposureData,
};
}
return (
<TouchableOpacity yh_exposureData={yh_exposureData} activeOpacity={1.0} style={{width: backgroundWidth, height:backgroundHeight,backgroundColor:'#f0f0f0'}} onPress={() => {
this.props.onPressProduct && this.props.onPressProduct(linkType,linkReource,moduleOrder,moduleType,1);
}}>
<View style={{width: backgroundWidth, height:backgroundHeight,backgroundColor: '#f0f0f0'}}>
<YH_Image
url={backgroundImage}
style={{width: backgroundWidth, height: imageHeight, backgroundColor: '#f5f7f6', resizeMode: 'contain'}}
/>
{linkType=='1' && showProductInfo?<View style={{ width: width, height: 35,position: 'absolute',backgroundColor: 'rgba(0,0,0,0.3)',top: imageHeight-35,flexDirection: 'row',alignItems: 'center',justifyContent: 'space-around'}}>
<Text style={styles.text1}>{name}</Text>
<Text style={{marginRight: 10,fontSize: 15,backgroundColor: 'transparent',color: saleAble?'red':'white'}}>{price}</Text>
{saleAble?<Text style={styles.deleteSale}>{sale}</Text>:null}
</View>:null}
</View>
</TouchableOpacity>
);
}
}
let {width, height} = Dimensions.get('window');
let backgroundWidth = width;
let styles = StyleSheet.create({
text1: {
width: width- 100,
fontSize: 15,
fontWeight: 'bold',
backgroundColor: 'transparent',
color: 'white',
marginLeft: 10,
},
text2: {
marginRight: 10,
fontSize: 15,
backgroundColor: 'transparent',
color: 'white',
},
deleteSale: {
marginRight: 10,
fontSize: 12,
backgroundColor: 'transparent',
color: 'white',
textDecorationLine: 'line-through',
}
});