DoubleImage.js
6.83 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
'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 DoubleImage 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 properties = resource.get('module_data').get('properties').toJS();
let isModuleMargin = properties.isModuleMargin;
let backgroundHeight =isModuleMargin=='1'?(width/2+10):width/2;
let data1 = list?list[0]:null;
let backgroundImage1 = data1.pic;
let linkType1 = data1.linkType;
let showProductInfo1 = true;
if (data1.showProductInfo && !data1.showProductInfo) {
showProductInfo1 = false;
}
let product1 = data1.product;
if (!product1) {
showProductInfo1 = false;
}
let salePrice1 = product1?parseFloat(product1.sales_price):0;
let originPrice1 = product1?parseFloat(product1.market_price):0;
let name1 = product1?product1.product_name:'';
let price1 = '¥' + salePrice1.toFixed(2);
let sale1 = '¥' + originPrice1.toFixed(2);
let saleAble1 = false;//salePrice1>0?true:false;
let linkReource1 = data1.resource;
let data2 = list?list[1]:null;
let backgroundImage2 = data2.pic;
let linkType2 = data2.linkType;
let showProductInfo2 = true;
if (data2.showProductInfo && !data2.showProductInfo) {
showProductInfo2 = false;
}
let product2 = data2.product;
if (!product2) {
showProductInfo2 = false;
}
let salePrice2 = product2?parseFloat(product2.sales_price):0;
let originPrice2 = product2?parseFloat(product2.market_price):0;
let name2 = product2?product2.product_name:'';
let price2 = '¥' + salePrice2.toFixed(2);
let sale2 = '¥' + originPrice2.toFixed(2);
let saleAble2 = false;//salePrice2>0?true:false;
let linkReource2 = data2.resource;
let moduleOrder = resource.get('module_order') + 1;
let moduleType = resource.get('module_type');
let url1 = '';
let url2 = '';
if (linkType1 == '0') {
url1 = `http://m.yohobuy.com?openby:yohobuy={"action":"go.poollist","params":{"productPool":"${linkReource1}"}}`;
} else if (linkType1 == '1') {
url1 = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${linkReource1}"}}`;
} else if (linkType1 == '2') {
url1 = linkReource1;
}
if (linkType2 == '0') {
url2 = `http://m.yohobuy.com?openby:yohobuy={"action":"go.poollist","params":{"productPool":"${linkReource2}"}}`;
} else if (linkType2 == '1') {
url2 = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${linkReource2}"}}`;
} else if (linkType2 == '2') {
url2 = linkReource2;
}
let yh_exposureData = this.props.yh_exposureData?this.props.yh_exposureData:null;
let yh_exposureData0 = null;
let yh_exposureData1 = null;
if (yh_exposureData) {
yh_exposureData0 = {
I_INDEX: 0,
ACTION_URL: url1,
...yh_exposureData,
};
yh_exposureData1 = {
I_INDEX: 1,
ACTION_URL: url2,
...yh_exposureData,
}
}
return(
<View style={{flexDirection: 'row',width: width,height: backgroundHeight,backgroundColor:'#f0f0f0'}}>
<TouchableOpacity yh_exposureData={yh_exposureData0} activeOpacity={1.0} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType1,linkReource1,moduleOrder,moduleType,1)}} >
<YH_Image
url={backgroundImage1}
style={styles.thumbnail}
></YH_Image>
{linkType1=='1'&& showProductInfo1 ?<View style={styles.titleView}>
<Text style={styles.title} numberOfLines={1}>{name1}</Text>
<View style={styles.saleView}>
<Text style={{marginTop: 2,marginLeft: 10,fontSize: 11,backgroundColor: 'transparent',color: saleAble1?'red':'white',}}>{price1}</Text>
{saleAble1?<Text style={styles.deleteSale}>{sale1}</Text>:null}
</View>
</View>:null}
</TouchableOpacity>
<TouchableOpacity yh_exposureData={yh_exposureData1} activeOpacity={1.0} onPress={() => {this.props.onPressProduct && this.props.onPressProduct(linkType2,linkReource2,moduleOrder,moduleType,2)}} >
<YH_Image
url={backgroundImage2}
style={styles.thumbnail}
></YH_Image>
{linkType2=='1' && showProductInfo2 ?<View style={styles.titleView}>
<Text style={styles.title} numberOfLines={1}>{name2}</Text>
<View style={styles.saleView}>
<Text style={{marginTop: 2,marginLeft: 10,fontSize: 11,backgroundColor: 'transparent',color: saleAble2?'red':'white',}}>{price2}</Text>
{saleAble2?<Text style={styles.deleteSale}>{sale2}</Text>:null}
</View>
</View>:null}
</TouchableOpacity>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
titleView: {
width: width/2,
height: 45,
position: 'absolute',
backgroundColor: 'rgba(0,0,0,0.3)',
top: width/2-45,
},
thumbnail: {
width: width/2,
height: width/2,
backgroundColor: '#f5f7f6',
resizeMode: 'contain',
},
title: {
marginTop: 8,
marginLeft: 10,
width: width/2-20,
fontSize: 11,
backgroundColor: 'transparent',
color: 'white',
fontWeight: 'bold',
},
saleView:{
flexDirection: 'row',
},
deleteSale: {
marginLeft: 2,
marginTop: 4,
fontSize: 10,
backgroundColor: 'transparent',
color: 'white',
textDecorationLine: 'line-through',
}
});