SingleImage.js
3.24 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
'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 properties = resource.get('module_data').get('properties').toJS();
let imageW = properties.width;
let imageH = properties.height;
let isModuleMargin = properties.isModuleMargin;
let imageHeight = (imageH*width)/(imageW==0?1:imageW);//根据返回信息计算出高度
let backgroundHeight =isModuleMargin?((imageH*width)/(imageW==0?1:imageW)+10):(imageH*width)/(imageW==0?1:imageW);
let product = data.product;
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;
return (
<TouchableOpacity activeOpacity={0.5} style={{width: backgroundWidth, height:backgroundHeight,backgroundColor: 'white'}} onPress={() => {
this.props.onPressProduct && this.props.onPressProduct(linkType,linkReource);
}}>
<View style={{width: backgroundWidth, height:backgroundHeight,backgroundColor: 'white'}}>
<YH_Image
url={backgroundImage}
style={{width: backgroundWidth, height: imageHeight}}
/>
{linkType=='1'?<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',
}
});