GoodsCell.js
6.54 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
const {
AppRegistry,
StyleSheet,
Text,
View,
Image,
Dimensions,
TouchableOpacity,
Platform,
} = ReactNative;
export default class GoodsCell extends React.Component {
constructor(props) {
super(props);
this.state = {
moreProduct: true,
};
}
shouldComponentUpdate(nextProps,nextState){
if (Immutable.is(nextProps.resource, this.props.resource) && nextState.moreProduct == this.state.moreProduct) {
return false;
} else {
return true;
}
}
render() {
let {resource} = this.props;
let originList = resource.get('productList');
let listSize = originList?originList.size:0;
if (!originList || listSize == 0) {
return null;
}
let list = originList;
if (this.state.moreProduct && listSize > 2) {
list = originList.slice(0,2);
}
let surplusSize = listSize-2;
let moreStr = '展开剩余'+ surplusSize + '个商品';
let backgroundWidth = width;
let showMoreViewHeigth = (this.state.moreProduct && listSize > 2)?60:0;
let backgroundHeight = Math.ceil(list.size) * (rowHeight+1) + showMoreViewHeigth;
return(
<View style={{width: backgroundWidth, height:backgroundHeight, backgroundColor:'white'}}>
{list.map((value, i) => {
let product = value?value.toJS():null;
if (!product) {
return null;
}
let default_images = product.default_images;
let product_name = product.product_name;
let originPrice = parseFloat(product.sales_price);
let originPriceStr = '¥ ' + originPrice.toFixed(2); // 拼接的原价
let product_skn = product.product_skn;
let prd_id = product.product_id;
return (
<TouchableOpacity
key={product_skn + '_key_' + i}
style={styles.content_View}
activeOpacity={0.5}
onPress={() => {
let pos_id = 103;
this.props.onPressProduct && this.props.onPressProduct(value,i,pos_id);
}}
>
<View style={styles.content_View}>
<View style={styles.line}/>
<View style={styles.single_View}>
<Image source={{uri: default_images}} style={styles.icon} resizeMode={'contain'}></Image>
<View style={styles.nameView}>
<Text style={styles.name} numberOfLines={2}>{product_name}</Text>
<Text style={styles.nowPrice} numberOfLines={1}>{originPriceStr}</Text>
</View>
<TouchableOpacity
style={styles.touchableOpacityButton}
activeOpacity={0.5}
onPress={() => {
let pos_id = 106;
this.props.onPressShopCar && this.props.onPressShopCar(product.product_skn,prd_id,pos_id);
}}
>
<Image source={require('../../image/jgwc_bt.png')} style={styles.button} resizeMode={'contain'}></Image>
</TouchableOpacity>
</View>
</View>
</TouchableOpacity>
);
})}
{(this.state.moreProduct && listSize > 2) ? <TouchableOpacity style={styles.more} activeOpacity={0.5} onPress={() => {
this.setState({moreProduct: !this.state.moreProduct});
}}>
<View style={styles.more}>
<Text style={styles.moreText} numberOfLines={1}>{moreStr}</Text>
<View style={styles.arrowView}>
<Image source={require('../../image/arrow_ic.png')} style={styles.arrow_icon} resizeMode={'contain'}></Image>
</View>
</View>
</TouchableOpacity>:null}
</View>
);
}
};
let {width, height} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 750;
let rowHeight = Math.ceil(254 * DEVICE_WIDTH_RATIO);
let imageWidth = Math.ceil((rowHeight - 20) * (235/314));
let styles = StyleSheet.create({
content_View: {
height: rowHeight + 1,//+1 分隔线
width:width,
backgroundColor: 'white',
},
single_View: {
height: rowHeight,
width:width,
backgroundColor: 'white',
flexDirection: 'row',
},
icon: {
marginTop: 10,
marginLeft: 20,
height: rowHeight - 20,
width: imageWidth,
},
nameView: {
height: rowHeight,
width: width - imageWidth - 20,
},
name: {
marginTop: 30,
marginLeft:15,
fontSize: 13,
width: width - imageWidth - 35,
},
nowPrice: {
fontSize: 15,
marginTop: 20,
marginLeft:15,
color: '#d0021b',
},
touchableOpacityButton: {
height: 23,
width: 40,
right: 15,
bottom: 10,
position: 'absolute',
},
button: {
height: 23,
width: 40,
},
more: {
height: 60,
width:width,
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
backgroundColor: 'white',
},
moreText: {
height: Platform.OS === 'ios' ? 22 : 24,
paddingLeft: 10,
paddingRight: 2,
paddingTop: 2,
paddingBottom: 2,
fontSize: 15,
color: 'white',
backgroundColor: 'rgb(68, 68, 68)',
},
line: {
width: width-20,
height: 1,
marginLeft: 20,
backgroundColor: '#e5e5e5',
},
arrowView: {
width: 25,
height: Platform.OS === 'ios' ? 22 : 24,
justifyContent: 'center',
backgroundColor: 'rgb(68, 68, 68)',
},
arrow_icon: {
width: 15,
height: 7,
}
});