GroupDetailHeader.js
10.3 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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
'use strict';
import React from 'react';
import Immutable, {Map} from 'immutable';
import YH_Image from '../../common/components/YH_Image';
import {getSlicedUrl} from '../../classify/utils/Utils';
import GroupDetailProduct from './GroupDetailProduct';
import HeaderList from './HeaderList';
import TimerMixin from 'react-timer-mixin';
import ReactNative, {
View,
Text,
Image,
StyleSheet,
Dimensions,
TouchableOpacity,
Platform,
} from 'react-native';
export default class GroupDetailHeader extends React.Component {
constructor(props) {
super(props);
this._renderTip = this._renderTip.bind(this);
this._renderTime = this._renderTime.bind(this);
this.startTimer = this.startTimer.bind(this);
this.stopTimer = this.stopTimer.bind(this);
this.formatDate = this.formatDate.bind(this);
this.format = this.format.bind(this);
this.state = {
formatTime : null,
};
}
componentDidMount() {
this.startTimer();
}
componentWillUnmount() {
this.stopTimer();
}
startTimer() {
this.stopTimer();
this.timer = TimerMixin.setInterval(() => {
diffTime = diffTime-1;
this.props.updateTime && this.props.updateTime(diffTime)
if (diffTime < 0) {
this.stopTimer();
}
if (diffTime > 0) {
let formatTime = this.formatDate(diffTime);
this.setState({
formatTime,
});
}
}, 1000);
}
stopTimer() {
this.timer && TimerMixin.clearTimeout(this.timer);
}
_renderTip(tipTitle) {
return(
<View style={styles.container}>
<Text style={styles.tipTitle}>{tipTitle}</Text>
</View>
);
}
_renderTime(lackNum,formatTime) {
if(!formatTime || diffTime <= 0)return null;
return(
<View style={styles.container}>
<View style={styles.productdetailTimeCountView}>
<Text style={styles.productdetailTimeCount}>还差</Text>
<Text style={styles.productdetailTimeRedCount}>{lackNum}</Text>
<Text style={styles.productdetailTimeCount}>人拼团成功,剩余时间</Text>
</View>
<View style={styles.productdetailTimeCountView1}>
<Text style={styles.timeItem}>{formatTime.h1 ? formatTime.h1 : 0}</Text>
<Text style={styles.timeItem}>{formatTime.h2 ? formatTime.h2 : 0}</Text>
<Text style={styles.timeSp}>:</Text>
<Text style={styles.timeItem}>{formatTime.m1 ? formatTime.m1 : 0}</Text>
<Text style={styles.timeItem}>{formatTime.m2 ? formatTime.m2 : 0}</Text>
<Text style={styles.timeSp}>:</Text>
<Text style={styles.timeItem}>{formatTime.s1 ? formatTime.s1 : 0}</Text>
<Text style={styles.timeItem}>{formatTime.s2 ? formatTime.s2 : 0}</Text>
</View>
</View>
);
}
render() {
let { groupDetail, activityId} = this.props;
let resource = groupDetail ? groupDetail.toJS():null;
if(!resource){
return null;
}
let groupId = resource.groupId;
let leftTime = resource.leftTime;
let isNewCustomer = resource.isNewCustomer;
let pageGo = resource.pageGo;
let groupRole = resource.groupRole;
let lackNum = resource.lackNum;
let openerJoinItem = resource.openerJoinItem;
let yourJoinItem = resource.yourJoinItem;
let membershipItems = resource.membershipItems;
let productDetail = membershipItems ? membershipItems[0]: '';
let joinLimit = resource.joinLimit;
let perpleNum = membershipItems.length + lackNum;
let productSkn = productDetail ? productDetail.productSkn : '';
let buttonText = '';
let tipTitle = '';
let tipTitlecolor = '#D0021B';
if(diffTime == 0 ){
diffTime = parseInt(leftTime);
}
if(pageGo == 1 || pageGo == 2 || pageGo == 3){
this.startTimer();
}else {
this.stopTimer();
}
if(pageGo == 1) {
let subtext = joinLimit==1 ? '(仅限新人)' : '';
buttonText = '邀请小伙伴拼团' + subtext;
}else if (pageGo == 2) {
buttonText = '去参团';
}else if (pageGo == 3) {
let subtext = joinLimit==1 ? '(仅限新人)' : '';
buttonText = '邀请小伙伴拼团' + subtext;
}else if (pageGo == 4) {
tipTitle = '拼团成功';
buttonText = '查看更多拼团活动';
tipTitlecolor = '#000000';
}else if (pageGo == 5) {
tipTitle = '你来晚了';
buttonText = '查看更多拼团活动';
tipTitlecolor = '#000000';
}else if (pageGo == 6) {
tipTitle = '拼团失败';
buttonText = '查看更多拼团活动';
}else if (pageGo == 7) {
tipTitle = '拼团失败';
buttonText = '查看更多拼团活动';
tipTitlecolor = '#000000';
}else {
tipTitle = '';
buttonText = '去参团';
}
return (
<View style={styles.container}>
<View style={styles.detail}>
<View style={Platform.OS === 'ios' ? styles.subdetail : styles.subDetailA}>
<View style={styles.headerList}>
<HeaderList resource={membershipItems} lackNum={lackNum}/>
</View>
{pageGo == 1 || pageGo == 2 || pageGo == 3
?
this._renderTime(lackNum,this.state.formatTime)
:
this._renderTip(tipTitle)
}
<TouchableOpacity activeOpacity={0.5} style={[styles.button,{backgroundColor: tipTitlecolor}]} onPress={() => {
this.props.didTouchButton && this.props.didTouchButton(resource);
}}>
<Text style={styles.buttonText}>{buttonText}</Text>
</TouchableOpacity>
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.goComment && this.props.goComment();
}}>
<Text style={styles.tip}>支付开团-支付参团-凑齐人数发货-凑不齐退款 玩法介绍》</Text>
</TouchableOpacity>
</View>
</View>
<TouchableOpacity activeOpacity={0.8} style={styles.product} onPress={() => {
this.props.didTouchProduct && this.props.didTouchProduct(productSkn,activityId);
}}>
<GroupDetailProduct joinLimit={joinLimit} resource={productDetail} pageGo={pageGo} perpleNum={perpleNum}/>
</TouchableOpacity>
<View style={styles.bottomLine}/>
</View>
);
}
format(m) {
if (m < 10){
return [0, m];
}else {
var h1 = Math.floor(m / 10);
var h2 = m - h1*10;
return [h1, h2];
}
return [0,0];
}
formatDate(shijianchuo) {
// 秒数
var second = Math.floor(shijianchuo);
// 小时位
var hr = Math.floor(second / 3600);
var hrFormat = this.format(hr);
// 分钟位
var min = Math.floor((second - hr * 3600) / 60);
var minFormat = this.format(min);
// 秒位
var sec = (second - hr * 3600 - min * 60);
var secFormat = this.format(sec);
var tFormat = {
h1: hrFormat[0],
h2: hrFormat[1],
m1: minFormat[0],
m2: minFormat[1],
s1: secFormat[0],
s2: secFormat[1],
};
return tFormat;
}
}
let {width, height} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 375;
let diffTime = 0;
let styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
},
product: {
position: 'absolute',
alignItems: 'center',
top: 20*DEVICE_WIDTH_RATIO,
},
detail: {
width: width,
marginTop: 84*DEVICE_WIDTH_RATIO,
backgroundColor: 'transparent',
alignItems: 'center',
},
subdetail: {
flex: 1,
width: width - 30*DEVICE_WIDTH_RATIO,
shadowColor: 'rgba(0,0,0,0.2)',
shadowOffset: {width: 0, height: 5},
shadowOpacity: 0.5,
shadowRadius: 5,
alignItems: 'center',
backgroundColor: 'white',
},
subDetailA: {
flex: 1,
width: width - 30*DEVICE_WIDTH_RATIO,
borderLeftWidth: 1,
borderRightWidth: 1,
borderBottomWidth: 1,
borderColor: 'rgba(0,0,0,0.1)',
alignItems: 'center',
backgroundColor: 'white',
},
headerList: {
marginTop: 97*DEVICE_WIDTH_RATIO,
width: width - 30*DEVICE_WIDTH_RATIO,
height: 40*DEVICE_WIDTH_RATIO,
},
button: {
height: 40*DEVICE_WIDTH_RATIO,
borderRadius: 20*DEVICE_WIDTH_RATIO,
flex: 1,
justifyContent: 'center',
paddingLeft: 30*DEVICE_WIDTH_RATIO,
paddingRight: 30*DEVICE_WIDTH_RATIO,
marginTop: 20*DEVICE_WIDTH_RATIO,
},
buttonText: {
fontSize: 16,
color: '#FFFFFF',
},
tip: {
fontSize: 12,
color: '#B0B0B0',
marginTop: 18*DEVICE_WIDTH_RATIO,
marginBottom: 20*DEVICE_WIDTH_RATIO,
},
bottomLine: {
width,
height: 8*DEVICE_WIDTH_RATIO,
backgroundColor: '#F0F0F0',
marginTop: 19*DEVICE_WIDTH_RATIO,
},
tipTitle: {
fontSize: 18,
color: '#444444',
marginTop: 23*DEVICE_WIDTH_RATIO,
fontWeight: 'bold',
},
productdetailTimeCountView: {
width,
height: 22,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
marginTop: 19*DEVICE_WIDTH_RATIO,
},
productdetailTimeCountView1: {
width,
height: 22,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
marginTop: 10*DEVICE_WIDTH_RATIO,
},
productdetailTimeRedCount: {
fontSize: 12,
color: '#D0021B',
},
productdetailTimeCount: {
fontSize: 12,
color: '#444444',
},
timeItem: {
width: 18,
height: 22,
lineHeight: 22,
fontSize: 14,
color: 'white',
textAlign: 'center',
marginLeft: 4,
backgroundColor: '#444444',
},
timeSp :{
fontSize: 14,
color: '#444444',
textAlign: 'center',
marginLeft: 4,
},
});