volunteerService.js
13.1 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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
/**
* Created by xiniu on 2018/5/7.
*/
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
TouchableOpacity,
Image,
ActivityIndicator,
ScrollView,
} from 'react-native';
import { width, height, zoomW, zoomH } from '../../utils/getSize';
import { xnToast } from '../../utils/utils';
import AppService from '../../service/AppService';
export default class myContribution extends Component {
static navigationOptions = ({ navigation, screenProps }) => ({
title: '志愿服务',
headerLeft: (
<TouchableOpacity style={styles.backWrap} onPress={() => navigation.goBack()}>
<Image source={require('../../img/back_gray.png')} resizeMode="contain" />
</TouchableOpacity>
),
headerRight: (
<TouchableOpacity style={styles.backWrap}>
<Text style={{ fontSize: 13, color: '#4B85E0' }}>查看详情</Text>
</TouchableOpacity>
),
});
constructor(props) {
super(props);
this.state = {
currentYear: new Date().getFullYear(),
currentMonth: new Date().getMonth(),
selectedMonth: new Date().getMonth(),
topMonthList: [],
dateList: [],
loading: false,
};
}
componentWillMount() {
this.initTopMonth(this.state.currentMonth);
this.initDate(this.state.currentYear, this.state.currentMonth);
}
// 获取某年某月的天数
mGetDate(year, month) {
return new Date(year, month + 1, 0).getDate();
}
// 初始化展示月份
initTopMonth(currentMonth) {
const monthList = [];
if (currentMonth <= 4) {
for (var i = 0; i <= 4; i++) {
if (i === currentMonth) {
monthList.push({ number: i, select: true });
} else {
monthList.push({ number: i, select: false });
}
}
this.setState({
topMonthList: monthList,
});
}
if (currentMonth > 4 && currentMonth <= 9) {
for (var i = 5; i <= 9; i++) {
if (i === currentMonth) {
monthList.push({ number: i, select: true });
} else {
monthList.push({ number: i, select: false });
}
}
this.setState({
topMonthList: monthList,
});
}
if (currentMonth > 9 && currentMonth <= 11) {
for (var i = 10; i <= 11; i++) {
if (i === currentMonth) {
monthList.push({ number: i, select: true });
} else {
monthList.push({ number: i, select: false });
}
}
this.setState({
topMonthList: monthList,
});
}
}
// 初始化日历
initDate(currentYear, currentMonth) {
const list = [];
const cutList = [];
// 每个月的第一天
const firstDay = new Date(currentYear, currentMonth, 1);
const dayInMonth = this.mGetDate(currentYear, currentMonth);
// 每个月的最后一天
const lastDay = new Date(currentYear, currentMonth, dayInMonth);
// 第一天星期几(0-6)
const firstDayWeekDay = firstDay.getDay();
// 最后一天星期几(0-6)
const lastDayWeekDay = lastDay.getDay();
// 补齐前面的日期
for (let i = 0; i < firstDayWeekDay; i++) {
list.push(' ');
}
for (let date = 1; date <= dayInMonth; date++) {
list.push(date);
}
// 补齐后面的日期
for (let j = lastDayWeekDay + 1; j < 7; j++) {
list.push(' ');
}
// 将要显示的所有天分成小数组
for (let d = 0; d < list.length; d += 7) {
cutList.push(list.slice(d, d + 7));
if (d === list.length - 7) {
this.setState({
dateList: cutList,
});
}
}
}
// 选择月份
selectTopMonth(v, i) {
if (!v.select) {
this.initDate(this.state.currentYear, v.number);
this.setState({
selectedMonth: v.number,
});
const list = this.state.topMonthList;
for (let m = 0; m < list.length; m++) {
if (m === i) {
list[m].select = true;
} else {
list[m].select = false;
}
if (m === list.length - 1) {
this.setState({
topMonthList: list,
});
}
}
}
}
// 要显示的月份
renderTopMonth(v, i) {
return (
<TouchableOpacity activeOpacity={0.8} style={styles.monthBtn} onPress={() => this.selectTopMonth(v, i)} key={i}>
<View style={[styles.monthWrap, { backgroundColor: v.select ? '#4B85E0' : 'transparent' }]}>
<Text style={{ fontSize: 14, color: v.select ? '#fff' : '#686868' }}>{v.number + 1} 月</Text>
</View>
</TouchableOpacity>
);
}
// 选择日期
selectDate(value, index) {
}
// 要显示的日期
renderDateCell(value, index) {
return (
<TouchableOpacity activeOpacity={0.8} style={styles.dateBtn} onPress={() => this.selectDate(value, index)} key={index}>
{/* {value !== ' ' && <View style={styles.redWrap}>*/}
{/* <Text style={{ fontSize: 12, color: '#F5F5F5' }}>待参加</Text>*/}
{/* </View>}*/}
{this.state.selectedMonth < this.state.currentMonth && <Text style={{ fontSize: 14, color: '#C3C3C3' }}>{value}</Text> }
{this.state.selectedMonth === this.state.currentMonth && value < new Date().getDate() && <Text style={{ fontSize: 14, color: '#C3C3C3' }}>{value}</Text>}
{this.state.selectedMonth === this.state.currentMonth && value >= new Date().getDate() && <Text style={{ fontSize: 14, color: '#7B7B7B' }}>{value}</Text>}
{this.state.selectedMonth > this.state.currentMonth && <Text style={{ fontSize: 14, color: '#7B7B7B' }}>{value}</Text>}
{/* {value !== ' ' && <View style={styles.greenDot} />}*/}
</TouchableOpacity>
);
}
// 要显示的日期行
renderDateRow(v, i) {
return (
<View style={{ flexDirection: 'row', alignItems: 'center' }} key={i}>
{v.map((value, index) => this.renderDateCell(value, index))}
</View>
);
}
render() {
return (
<View style={styles.background}>
<ScrollView style={{ flex: 1 }} showsVerticalScrollIndicator={false}>
<View style={styles.dateWrap}>
<View style={styles.topWrap}>
<Text style={{ fontSize: 16, color: '#4B85E0', marginLeft: 15 / zoomW, marginRight: 14 / zoomW }}>{this.state.currentYear} 年</Text>
<View style={styles.gap} />
{this.state.topMonthList.map((v, i) => this.renderTopMonth(v, i))}
</View>
<View style={{ paddingLeft: 15 / zoomW, paddingRight: 15 / zoomW }}>
<View style={{ width: '100%', height: 1 / zoomH, backgroundColor: '#F6F6F6' }} />
</View>
<View style={styles.bottomWrap}>
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<View style={styles.weekWrap}>
<Text style={{ fontSize: 14, color: '#C3C3C3' }}>日</Text>
</View>
<View style={styles.weekWrap}>
<Text style={{ fontSize: 14, color: '#C3C3C3' }}>一</Text>
</View>
<View style={styles.weekWrap}>
<Text style={{ fontSize: 14, color: '#C3C3C3' }}>二</Text>
</View>
<View style={styles.weekWrap}>
<Text style={{ fontSize: 14, color: '#C3C3C3' }}>三</Text>
</View>
<View style={styles.weekWrap}>
<Text style={{ fontSize: 14, color: '#C3C3C3' }}>四</Text>
</View>
<View style={styles.weekWrap}>
<Text style={{ fontSize: 14, color: '#C3C3C3' }}>五</Text>
</View>
<View style={styles.weekWrap}>
<Text style={{ fontSize: 14, color: '#C3C3C3' }}>六</Text>
</View>
</View>
{this.state.dateList.map((v, i) => this.renderDateRow(v, i))}
</View>
</View>
<View style={styles.infoWrap}>
<View style={styles.timeSlotWrap}>
<Text style={{ fontSize: 14, color: '#686868', marginTop: 10 / zoomH }}>时间段:</Text>
<View style={{ marginLeft: 11 / zoomW }}>
<View style={styles.timeRange}>
<Text style={{ fontSize: 14, color: '#747474' }}>08 : 30 - 10 : 00</Text>
</View>
<View style={styles.timeRange}>
<Text style={{ fontSize: 14, color: '#747474' }}>13 : 30 - 14 : 00</Text>
</View>
</View>
</View>
<View style={styles.positionWrap}>
<Text style={{ fontSize: 14, color: '#686868' }}>位置:</Text>
<View style={{ marginLeft: 26 / zoomW, flexDirection: 'row' }}>
<TouchableOpacity activeOpacity={0.8} style={{ height: '100%', flexDirection: 'row', alignItems: 'center', marginRight: 14 / zoomW }}>
<Text style={{ fontSize: 14, color: '#000' }}>1<Text style={{ color: '#424242' }}> 号线</Text></Text>
</TouchableOpacity>
<TouchableOpacity activeOpacity={0.8} style={{ height: '100%', flexDirection: 'row', alignItems: 'center' }}>
<Text style={{ fontSize: 14, color: '#000' }}>徐家汇<Text style={{ color: '#424242' }}> 站台</Text></Text>
</TouchableOpacity>
</View>
</View>
<View style={styles.positionWrap}>
<Text style={{ fontSize: 14, color: '#686868' }}>服务岗位:</Text>
<View style={{ marginLeft: 4 / zoomW }}>
<TouchableOpacity activeOpacity={0.8} style={{ height: '100%', justifyContent: 'center' }}>
<Text style={{ fontSize: 14, color: '#2C2C2C' }}>1号向下自动扶梯</Text>
</TouchableOpacity>
</View>
</View>
</View>
<View style={styles.btnWrap}>
<TouchableOpacity activeOpacity={0.8} style={styles.signUpBtn}>
<Text style={{ fontSize: 18, color: '#fff' }}>报名</Text>
</TouchableOpacity>
</View>
</ScrollView>
{this.state.loading && <View style={styles.loadingBg}>
<ActivityIndicator size="large" />
</View>}
</View>
);
}
}
const styles = StyleSheet.create({
backWrap: {
justifyContent: 'center',
paddingLeft: 15 / zoomW,
paddingRight: 15 / zoomW,
height: 44 / zoomH,
},
background: {
flex: 1,
backgroundColor: '#F6F6F6',
position: 'relative',
},
dateWrap: {
width: '100%',
marginTop: 10 / zoomH,
backgroundColor: '#fff',
},
topWrap: {
width: '100%',
height: 44 / zoomH,
paddingLeft: 15 / zoomW,
flexDirection: 'row',
alignItems: 'center',
},
gap: {
width: 1 / zoomW,
height: 20 / zoomH,
backgroundColor: '#E6E6E6',
},
monthBtn: {
height: '100%',
justifyContent: 'center',
paddingLeft: 9 / zoomW,
paddingRight: 9 / zoomW,
},
monthWrap: {
paddingLeft: 5 / zoomW,
paddingRight: 5 / zoomW,
borderRadius: 4 / zoomW,
},
bottomWrap: {
width: '100%',
paddingBottom: 8 / zoomH,
},
weekWrap: {
paddingTop: 7 / zoomH,
paddingBottom: 7 / zoomH,
width: 375 / 7 / zoomW,
justifyContent: 'center',
alignItems: 'center',
},
dateBtn: {
paddingTop: 10 / zoomH,
paddingBottom: 10 / zoomH,
width: 375 / 7 / zoomW,
justifyContent: 'center',
alignItems: 'center',
position: 'relative',
},
greenDot: {
width: 5 / zoomW,
height: 5 / zoomW,
borderRadius: 5 / 2 / zoomW,
backgroundColor: '#40D06C',
position: 'absolute',
bottom: 5 / zoomH,
},
redWrap: {
height: 37 / zoomH,
borderRadius: 4 / zoomW,
backgroundColor: '#FF1818',
paddingLeft: 1 / zoomW,
paddingRight: 1 / zoomW,
paddingBottom: 4 / zoomH,
justifyContent: 'flex-end',
alignItems: 'center',
position: 'absolute',
bottom: -5 / zoomH,
},
infoWrap: {
width: '100%',
paddingLeft: 15 / zoomW,
paddingRight: 15 / zoomW,
paddingTop: 10 / zoomH,
},
timeSlotWrap: {
width: '100%',
minHeight: 80 / zoomH,
paddingLeft: 14 / zoomW,
paddingBottom: 14 / zoomH,
backgroundColor: '#fff',
borderRadius: 4 / zoomW,
flexDirection: 'row',
},
timeRange: {
width: 140 / zoomW,
height: 20 / zoomH,
borderWidth: 1,
borderColor: '#D1D1D1',
borderRadius: 4 / zoomW,
marginTop: 13 / zoomH,
justifyContent: 'center',
alignItems: 'center',
},
positionWrap: {
width: '100%',
height: 44 / zoomH,
paddingLeft: 14 / zoomW,
backgroundColor: '#fff',
borderRadius: 4 / zoomW,
flexDirection: 'row',
alignItems: 'center',
marginTop: 10 / zoomH,
},
btnWrap: {
width: '100%',
height: 49 / zoomH,
paddingLeft: 30 / zoomW,
paddingRight: 30 / zoomW,
marginTop: 15 / zoomH,
marginBottom: 15 / zoomH,
},
signUpBtn: {
width: '100%',
height: '100%',
backgroundColor: '#538AE1',
borderRadius: 4 / zoomW,
justifyContent: 'center',
alignItems: 'center',
},
loadingBg: {
width: '100%',
height: '100%',
position: 'absolute',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
},
});