Sale1T1L4R.js
8.77 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
'use strict';
import React, {Component} from 'react';
import ReactNative, {
View,
Image,
Text,
TouchableOpacity,
StyleSheet,
Dimensions,
} from 'react-native';
import Immutable, {Map} from 'immutable';
import TimerMixin from 'react-timer-mixin';
import SlicedImage from '../../../common/components/SlicedImage';
import YH_Image from '../../../common/components/YH_Image';
import HeadTitleCell from '../cell/HeadTitleCell';
import ImageSlider from '../cell/ImageSlider';
/**
* 首页 sale 楼层,
* 这个楼层是标题、banner、左带倒计时大图,右四小图
**/
export default class Sale1T1L4R extends Component{
constructor(props) {
super(props);
this._caculateTimerState = this._caculateTimerState.bind(this);
this.state = {
remainHour : "00",
remainMinute : "00",
remainSecond : "00",
timeOut: true,
};
}
componentDidMount() {
this.timer = TimerMixin.setInterval(() => {
if(diffTime > 0){
diffTime = diffTime - 1;
this._caculateTimerState();
}
}, 1000);
}
componentWillUnmount() {
this.timer && TimerMixin.clearInterval(this.timer);
}
_caculateTimerState() {
if(diffTime > 0){
let hour = parseInt(diffTime / (60 * 60), 10);
let minute = parseInt(diffTime % (60 * 60) / 60, 10);
let second = diffTime % 60;
this.setState({
remainHour: hour < 0 ? '00' : (hour < 10 ? ('0' + hour) : hour),
remainMinute: minute < 0 ? '00' : (minute < 10 ? ('0' + minute) : minute),
remainSecond: second < 0 ? '00' : (second < 10 ? ('0' + second) : second),
timeOut: false,
});
}
else{
this.setState({
remainHour: '00',
remainMinute: '00',
remainSecond: '00',
timeOut: true,
});
this.timer && TimerMixin.clearInterval(this.timer);
}
}
render(){
let data = this.props.data;
let banner = data.get("big_image");
let title = data.get("title");
let imglst = data.get("list");
//剩余时间
time = imglst.get(0).get("end_time");
diffTime = time - Date.parse(new Date()) / 1000;
let leftBigImageUrl = SlicedImage.getSlicedUrl(imglst.get(0).get("src"), leftBigImageWidth, leftBigImageHeight, 2);
let rightTopBigImageUrl = SlicedImage.getSlicedUrl(imglst.get(1).get("src"), rightBigImageWidth, rightBigImageHeight, 2);
let rightTopSmallImageUrl = SlicedImage.getSlicedUrl(imglst.get(2).get("src"), rightSmallImageWidth, rightSmallImageHeight, 2);
let rightBottomBigImageUrl = SlicedImage.getSlicedUrl(imglst.get(3).get("src"), rightBigImageWidth, rightBigImageHeight, 2);
let rightBottomSmallImageUrl = SlicedImage.getSlicedUrl(imglst.get(4).get("src"), rightSmallImageWidth, rightSmallImageHeight, 2);
let containerHeight = 40 + leftBigImageHeight;
if(banner.toJS().length > 0){
containerHeight = containerHeight + bannerHeight;
}
return(
<View style={[styles.container, {height: containerHeight}]}>
<HeadTitleCell title={title.get('title')} moreUrl={title.get('more_url')} onPressTitleMore={this.props.onPressTitleMore} />
<ImageSlider
resource={banner}
sliderWidth={width}
sliderHeight={bannerHeight}
onPressSlideItem={this.props.onPressSlideItem}
/>
<View style={styles.imageContainer}>
<TouchableOpacity style={styles.leftBigImageContainer} activeOpacity={1}
onPress={() => this.props.onPressImageItem && this.props.onPressImageItem(imglst.get(0).toJS())}>
<YH_Image style={styles.leftBigImage} url={leftBigImageUrl}/>
<View style={styles.timerImageContainer}>
<Image style={styles.timerImage} source={require("../../images/home_sale_time.png")}/>
<Image source={require("../../images/home_sale_time_text.png")}/>
</View>
<View style={styles.timerTextContainer}>
<Text style={styles.timerText}>{this.state.remainHour}</Text>
<Text style={styles.timerTextSymbol}>:</Text>
<Text style={styles.timerText}>{this.state.remainMinute}</Text>
<Text style={styles.timerTextSymbol}>:</Text>
<Text style={styles.timerText}>{this.state.remainSecond}</Text>
</View>
</TouchableOpacity>
<TouchableOpacity style={styles.rightTopBigImageContainer} activeOpacity={1}
onPress={() => this.props.onPressImageItem && this.props.onPressImageItem(imglst.get(1).toJS())}>
<YH_Image style={styles.rightTopBigImage} url={rightTopBigImageUrl}/>
</TouchableOpacity>
<TouchableOpacity style={styles.rightTopSmallImageContainer} activeOpacity={1}
onPress={() => this.props.onPressImageItem && this.props.onPressImageItem(imglst.get(2).toJS())}>
<YH_Image style={styles.rightTopSmallImage} url={rightTopSmallImageUrl}/>
</TouchableOpacity>
<TouchableOpacity style={styles.rightBottomBigImageContainer} activeOpacity={1}
onPress={() => this.props.onPressImageItem && this.props.onPressImageItem(imglst.get(3).toJS())}>
<YH_Image style={styles.rightBottomBigImage} url={rightBottomBigImageUrl}/>
</TouchableOpacity>
<TouchableOpacity style={styles.rightBottomSmallImageContainer} activeOpacity={1}
onPress={() => this.props.onPressImageItem && this.props.onPressImageItem(imglst.get(4).toJS())}>
<YH_Image style={styles.rightBottomSmallImage} url={rightBottomSmallImageUrl}/>
</TouchableOpacity>
</View>
</View>
);
}
};
let time = 0;
let diffTime = 0;
let {width} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 320;
let bannerHeight = Math.floor(width / 3);
let leftBigImageWidth = width * 310 / 740;
let leftBigImageHeight = leftBigImageWidth * 422 / 310;
let rightBigImageWidth = width * 330 / 740;
let rightBigImageHeight = rightBigImageWidth * 210 / 330;
let rightSmallImageWidth = width * 100 / 740;
let rightSmallImageHeight = rightSmallImageWidth * 210 / 100;
let styles = StyleSheet.create({
container: {
width: width,
backgroundColor: "#e5e5e5",
},
imageContainer: {
width: width,
height: 422 * DEVICE_WIDTH_RATIO,
},
leftBigImageContainer: {
position: 'absolute',
top: 0,
left: 0,
width: leftBigImageWidth,
height: leftBigImageHeight,
},
leftBigImage: {
width: leftBigImageWidth,
height: leftBigImageHeight,
},
timerImageContainer:{
width: leftBigImageWidth,
position: 'absolute',
top: 20,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
timerImage:{
paddingRight: 10,
},
timerTextContainer:{
width: leftBigImageWidth,
position: 'absolute',
top: 50,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
timerText:{
backgroundColor: '#ffffff',
padding: 1,
borderRadius: 2,
color: '#444444',
fontWeight: 'bold',
},
timerTextSymbol:{
paddingLeft: 4,
paddingRight: 4,
color: '#ffffff',
fontWeight: 'bold',
},
rightTopBigImageContainer: {
position: 'absolute',
top: 0,
left: leftBigImageWidth,
width: rightBigImageWidth,
height: rightBigImageHeight,
},
rightTopBigImage: {
width: rightBigImageWidth,
height: rightBigImageHeight,
},
rightTopSmallImageContainer: {
position: 'absolute',
top: 0,
left: leftBigImageWidth,
width: rightSmallImageWidth,
height: rightSmallImageHeight,
},
rightTopSmallImage: {
width: rightSmallImageWidth,
height: rightSmallImageHeight,
},
rightBottomBigImageContainer: {
position: 'absolute',
top: rightBigImageHeight,
left: leftBigImageWidth,
width: rightBigImageWidth,
height: rightBigImageHeight,
marginTop: 2,
},
rightBottomBigImage: {
width: rightBigImageWidth,
height: rightBigImageHeight,
},
rightBottomSmallImageContainer: {
position: 'absolute',
top: rightBigImageHeight,
left: leftBigImageWidth + rightBigImageWidth,
width: rightSmallImageWidth,
height: rightSmallImageHeight,
marginTop: 2,
},
rightBottomSmallImage: {
width: rightSmallImageWidth,
height: rightSmallImageHeight,
},
});