ActivityCell.js
7.02 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
import YH_Image from '../../../common/components/YH_Image';
import {getSlicedUrl} from '../../../classify/utils/Utils';
import DeviceInfo from 'react-native-device-info';
const {
View,
Text,
TouchableOpacity,
Dimensions,
StyleSheet,
Platform,
} = ReactNative;
export default class ActivityCell extends React.Component {
constructor(props) {
super (props);
this.getStartTimeString = this.getStartTimeString.bind(this);
this.getEndTimeString = this.getEndTimeString.bind(this);
let {resource} = this.props;
if (!resource) {
return null;
}
let data = resource.toJS();
let startLeftTime = data.startLeftTime;
let endLeftTime = data.endLeftTime;
let startTime = data.startTime;
let endTime = data.endTime;
let showString = '';
if (startLeftTime <= 0) {
if (endLeftTime <= 0) {
showString = '活动已结束'
}else {
showString = this.getEndTimeString(endLeftTime);
}
this.state= {
timerCount: endLeftTime,
showString: showString,
};
this.interval=setInterval(() =>{
let timer=this.state.timerCount-1;
if(timer===0){
this.interval&&clearInterval(this.interval);
this.setState({timerCount:0,showString: '活动已结束'})
} else{
this.setState({
timerCount: timer,
showString: this.getEndTimeString(timer),
})
}
},1000)
} else {
if (startTime <= 0) {
return null;
}else {
showString = this.getStartTimeString(startTime);
}
this.state= {
timerCount: startTime,
showString: showString,
};
}
}
componentWillUnmount() {
this.interval && clearInterval(this.interval);
}
getStartTimeString(startTime){
let startDate = new Date(startTime);
return startDate.getMonth()+'月'+startDate.getDate()+'日'+startDate.getHours()+'时'+'开始';
}
getEndTimeString(timeTick){
let showString = '';
let day = 0;
let hour = 0;
let minute = 0;
let second = 0;
let minuteFloat = 0;
if (timeTick >= kTimeDay) {
day = parseInt(timeTick/kTimeDay);
hour = parseInt(timeTick%kTimeDay/kTimeHour);
minute = parseInt(timeTick%kTimeHour/kTimeMinute);
second = parseInt(timeTick%kTimeMinute);
} else if (timeTick >= kTimeHour) {
hour = parseInt(timeTick/kTimeHour);
minuteFloat= parseInt(timeTick%kTimeHour);
if (minuteFloat >= kTimeMinute) {
minute = parseInt(minuteFloat/kTimeMinute);
second = parseInt(minuteFloat%kTimeMinute);
} else {
second = minuteFloat;
}
} else if (timeTick >= kTimeMinute){
minute = parseInt(timeTick/kTimeMinute);
second = parseInt(timeTick%kTimeMinute);
} else {
second = timeTick;
}
if (day > 0) {
showString = day+'天';
}
return '还剩'+showString+hour+'小时'+minute+'分'+second+'秒';
}
render() {
let {resource} = this.props;
if (!resource) {
return null;
}
let fontFamilyStyle1 = {};
if (Platform.OS === 'ios') {
let systemVersion = DeviceInfo.getSystemVersion();
systemVersion = parseFloat(systemVersion);
if (systemVersion >= 9.0) {
fontFamilyStyle1 = {fontFamily: 'Helvetica Bold'};
}
}
let data = resource.toJS();
let newSrc = getSlicedUrl(data.coverUrl, backgroundWidth, backgroundHeight);
let title = data.title;
let promotionName = data.promotionName;
let isShow = data.isShow;
let id = data.id;
let price = promotionName&&promotionName.length>2?promotionName.substring(0,promotionName.length-2):''
let priceString = promotionName&&promotionName.length>2?promotionName.substring(promotionName.length-2,promotionName.length):''
return (
<View style={styles.container}>
<TouchableOpacity
activeOpacity={1}
style={{width: backgroundWidth, height: backgroundHeight}}
onPress={() => {
let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.outletactivity","params":{"activity_id":"${id}"}}`;
this.props.onPressProduct && this.props.onPressProduct(url);
}}
>
<YH_Image
url={newSrc}
style={{ width: backgroundWidth, height: backgroundHeight}}
/>
<View style={styles.detailV}>
<Text style={[styles.title, fontFamilyStyle1]}>{title}</Text>
<View style={styles.priceV}>
<Text style={[styles.price1, fontFamilyStyle1]}>{price}</Text>
<Text style={[styles.price2, fontFamilyStyle1]}>{priceString}</Text>
</View>
<Text style={[styles.time, fontFamilyStyle1]}>{this.state.showString}</Text>
</View>
</TouchableOpacity>
<View style={styles.space} />
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let backgroundWidth = width;
let backgroundHeight = Math.ceil((300 / 640) * width);
let spaceH = Math.ceil((30 / 640) * width);
let kTimeDay = 3600*24;
let kTimeHour = 3600;
let kTimeMinute = 60;
let styles = StyleSheet.create({
container: {
width: width,
height: backgroundHeight + spaceH,
},
detailV: {
position: 'absolute',
top: Math.ceil((130 / 640) * width),
width: width,
height: Math.ceil((170 / 640) * width),
backgroundColor: 'transparent',
},
title: {
width: width,
height: Math.ceil((30 / 640) * width),
textAlign: 'center',
fontSize: 14,
},
priceV: {
flexDirection: 'row',
marginTop: Math.ceil((10 / 640) * width),
height: Math.ceil((30 / 640) * width),
alignSelf: 'center',
},
price1: {
height: Math.ceil((30 / 640) * width),
textAlign: 'right',
fontSize: 16,
color: '#d0021b'
},
price2: {
height: Math.ceil((20 / 640) * width),
marginTop: Math.ceil((5 / 640) * width),
textAlign: 'left',
fontSize: 10,
color: '#d0021b'
},
time: {
width: width,
height: Math.ceil((20 / 640) * width),
marginTop: Math.ceil((12 / 640) * width),
backgroundColor: 'transparent',
textAlign: 'center',
fontSize: 10,
},
space: {
width: width,
height: spaceH,
backgroundColor: 'white',
},
});