NewUserFloor.js
6.62 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
/**
* Description:
* <p> new_user_floor:新人专享
* Author: Bruce.Lu
* Version: 1.0
* Created on 2017/2/9.
*/
import React, {Component} from 'react';
import ReactNative, {
Image,
Text,
StyleSheet,
ListView,
View,
TouchableOpacity,
Dimensions,
} from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';
import Immutable from 'immutable';
import SlicedImage from '../../../common/components/SlicedImage';
import HeadTitleCell from '../cell/HeadTitleCell';
import ImageSlider from '../cell/ImageSlider';
import YH_Image from '../../../common/components/YH_Image';
export default class NewUserFloor extends Component {
constructor(props) {
super(props);
this.renderRow = this.renderRow.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
}
renderRow(rowData, sectionID, rowID, highlightRow) {
let data = this.props.data;
let banner = data.get("banner_image");
let bannerLength = banner.toJS().length;
let index = parseInt(rowID)+bannerLength;
let productName = rowData.get('product_name');
let productPrice = '¥'+rowData.get('sales_price').toFixed(2);
let productId = rowData.get('product_id');
let productSkn = rowData.get('product_skn');
let imgUrl = SlicedImage.getSlicedUrl(rowData.get('default_images'),cellWidth / 2,cellHeight,2);
let yh_exposureData = rowData.get('yh_exposureData') ? rowData.get('yh_exposureData').toJS() : null;
return (
<TouchableOpacity style={styles.row} yh_exposureData={yh_exposureData}
onPress={()=>{this.props.onPressVipProduct&&this.props.onPressVipProduct(rowData, imgUrl, index + rowID)}}>
<YH_Image style={styles.image}
url={imgUrl}/>
<View style={styles.detailContainer}>
<Text style={styles.detail} numberOfLines={2}>{productName}</Text>
<Text style={styles.detail2} numberOfLines={1}>{productPrice}</Text>
<View style={styles.buyContainer}>
<Text style={styles.buy} numberOfLines={1}>立即购买</Text>
<Image style={{width:4,height:7,marginLeft:2}}
source={require('../../images/yh_home_new_user_arrow.png')}/>
</View>
</View>
</TouchableOpacity>);
}
render() {
let data = this.props.data?this.props.data:{};
let title = data.get('title').get('title');
let moreUrl = data.get('title').get('more_url');
let bgUrl = '';
let visible = bgUrl ? true : false;
let bannerData = data.get('banner_image');
let productData = data.get('list');
let floorH = 130 + 40 + bannerHeight;
let yh_exposureDataTitle = (data.get('title') && data.get('title').get('yh_exposureData')) ? data.get('title').get('yh_exposureData').toJS() : null;
return (
<View style={{backgroundColor:'white',width:width,height:floorH}}>
<HeadTitleCell title={title} moreUrl={moreUrl}
onPressTitleMore={this.props.onPressTitleMore} yh_exposureData={yh_exposureDataTitle}/>
<ImageSlider
resource={bannerData}
sliderWidth={width}
sliderHeight={bannerHeight}
onPressSlideItem={this.props.onPressVipBannerItem}
/>
<View style={styles.listContianer}>
{visible ?
<YH_Image style={styles.listBg}
url={SlicedImage.getSlicedUrl(bgUrl,width,130,2)}
/> : null}
<ListView
style={{position:'absolute',left:0,top:0,paddingTop:12,paddingBottom:12}}
contentContainerStyle={styles.listContent}
horizontal={true}
dataSource={this.dataSource.cloneWithRows(productData.toArray())}
renderRow={this.renderRow}
showsHorizontalScrollIndicator={false}
/>
<View style={{position:'absolute',left:0,top:12,alignItems:'center'}}>
<Image source={require('../../images/yh_home_new_user.png')}
style={{width:20,height:cellHeight}}/>
<Text
style={{color:'white',fontSize:11,textAlignVertical:"center",height:90,position:'absolute',left:0,top:0}}>
新{'\n'}人{'\n'}专{'\n'}享{'\n'}
</Text>
</View>
</View>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let bannerHeight = Math.ceil((234 / 750) * width);
let sectionHeight = Math.ceil((419 / 750) * width);
let cellWidth = 150;
let cellHeight = 100;
const styles = StyleSheet.create({
listContianer: {
width:width,
height: 130,
alignItems: 'center',
},
listBg: {
width: width,
height: 130,
},
listContent: {
backgroundColor: 'transparent',
flexDirection: 'row',
flexWrap: 'nowrap',
justifyContent: 'flex-start',
paddingRight: 5,
paddingLeft:18
},
row: {
flexDirection: 'row',
height: cellHeight,
width:cellWidth,
backgroundColor: 'white',
justifyContent: 'center',
marginLeft: 6,
marginRight: 6
},
detailContainer: {
width: cellWidth / 2,
height: cellHeight,
flexDirection: 'column',
alignItems: 'flex-start',
padding: 4
},
detail: {
fontSize: 11,
textAlign: 'center',
color: '#444444',
width: cellWidth / 2 - 8,
marginTop:8
},
detail2: {
fontSize: 11,
textAlign: 'center',
color: '#444444',
width: cellWidth / 2,
marginTop:12
},
buyContainer: {
flexDirection: 'row',
justifyContent: 'center',
width: cellWidth / 2,
height: 20,
justifyContent: 'center',
alignItems: 'center',
marginTop: 12,
},
buy: {
fontSize: 11,
textAlign: 'center',
color: '#b0b0b0',
},
image: {
width: cellWidth / 2,
height: cellHeight,
},
text: {
width: cellWidth / 2,
fontSize: 12,
color: 'gray',
textAlign: 'center',
}
});