index.js
28.2 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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
import React, { PureComponent } from 'react';
import {
StyleSheet,
Text,
TextInput,
TouchableWithoutFeedback,
Image,
View,
ScrollView,
TouchableOpacity,
Switch,
DeviceEventEmitter,
NativeModules,
ActivityIndicator,
} from 'react-native';
import _ from 'lodash';
import moment from 'moment';
import Picker from 'react-native-picker';
import DatePicker from 'react-native-datepicker';
import { width, height, zoomW, zoomH } from '../../utils/getSize';
import { xnToast, NoDoublePress } from "../../utils/utils";
import AppService from "../../service/AppService";
import IMG_PersonOutline from '../../assets/personOutline.png';
import IMG_PeopleOutline from '../../assets/peopleOutline.png';
import IMG_ChevronForwardOutline from '../../assets/chevronForwardOutline.png';
import IMG_LocationOutline from '../../assets/locationOutline.png';
// import IMG_NotificationsOutline from '../../assets/notificationsOutline.png';
import IMG_AttachOutline from '../../assets/attachOutline.png';
import IMG_AddCircleOutline from '../../assets/addCircleOutline.png';
import IMG_CloseOutline from '../../assets/closeOutline.png';
import IMG_ReaderOutline from '../../assets/readerOutline.png';
import 'moment/locale/zh-cn';
// const noticeOptions = ['不提醒', '5分钟前', '15分钟前', '30分钟前', '1小时前', '2小时前', '1天前'];
// const repeatOptions = ['默认不重复', '每个工作日(周一至周五)', '每天', '每周', '每月', '每年', '自定义'];
export default class AddSchedule extends PureComponent {
constructor(props) {
super(props);
const currentDate = moment();
this.state = {
title: '',
isFullDay: false,
startDate: currentDate.format('YYYY-MM-DD'),
endDate: currentDate.format('YYYY-MM-DD'),
startTime: currentDate.format('HH:mm'),
endTime: currentDate.format('HH:mm'),
userList: [],
location: '',
desc: '',
// noticeRule: noticeOptions[1],
// repeatRule: repeatOptions[0],
attachFileList: [],
submitting: false,
};
}
componentDidMount() {
this.props.navigation.setParams({
title: '新建日程',
backgroundColor: 'white',
titleColor: 'black',
isBack: true,
});
let that = this;
this.reloaAddEmployee = DeviceEventEmitter.addListener('reloaAddEmployee', function () {
that.setState({
userList: global.linkDoEmployee,
});
});
}
componentWillUnmount() {
if (this.reloaAddEmployee) {
this.reloaAddEmployee.remove();
}
};
toggleFullDay = (value) => {
this.setState({
isFullDay: value,
});
};
handleSelectPeopleList = () => {
this.props.navigation.navigate('AddPeople', { from2: 'addSchedule', from: 'doEmployee', target: 'link', });
}
onChangeTitle = (value) => {
this.setState({
title: value,
});
};
showStartTimePicker = () => {
this.startDatePicker.onPressDate();
};
onChangeStartDateTime = (date) => {
const [startDate, startTime] = date.split(' ');
this.setState({
startDate,
startTime,
});
};
showEndTimePicker = () => {
this.endDatePicker.onPressDate();
};
onChangeEndDateTime = (date) => {
const [endDate, endTime] = date.split(' ');
this.setState({
endDate,
endTime,
});
};
onChangeLocation = (value) => {
this.setState({
location: value,
});
};
onChangeDesc = (value) => {
this.setState({
desc: value,
});
};
// showNoticePicker = () => {
// Picker.init({
// pickerData: noticeRuleOptions,
// pickerTitleText: '选择提醒时间',
// pickerCancelBtnText: '取消',
// pickerConfirmBtnText: '确定',
// onPickerConfirm: (data) => {
// this.setState({
// noticeRule: data,
// });
// },
// });
// Picker.show();
// };
handleAttachFileSelector = () => {
const that = this;
setTimeout(() => {
const picLength = 9 - that.state.attachFileList.length;
NativeModules.system.choosePic(picLength).then((data) => {
if (data == '' || !!!data) {
return;
}
let path = data;
let nameList = [];
for (let i = 0; i < data.length; i++) {
let filePath = data[i].filePath.substring(path.lastIndexOf('/') + 1);
filePath = global.userId + filePath;
nameList.push(filePath);
}
that.setState({
loading: true,
});
AppService.getAccess({ nameList: nameList, }).then((res) => {
if (res.message) {
xnToast(res.message);
that.setState({
loading: false,
});
return;
}
if (res.errors.length > 0) {
xnToast(res.errors[0].message);
} else {
NativeModules.system.batchUpload(res.accessKeyId, res.accessKeySecret, res.securityToken, res.infoList, path).then((data2) => {
const fileList = that.state.attachFileList;
for (let i = 0;i < data2.length; i++) {
const temp = data2[i];
const id = that.getUrlFileName(temp);
fileList.push({ id, url: temp, });
}
that.setState({
loading: false,
imgList: fileList,
});
});
}
}).catch((error) => {
that.setState({
loading: false,
}, () => {
xnToast(error.message);
});
});
});
}, 500);
}
getUrlFileName = (url) => {
if (url) {
var match = url.toString().match(/.*\/(.+?)\./);
if (match && match.length > 1) {
return match[1];
}
}
return "";
}
removeAttachFileItem = (id) => {
const newAttachFileList = [];
const { attachFileList } = this.state;
if (attachFileList.length > 0) {
for (let i = 0; i < attachFileList.length; i++) {
const item = attachFileList[i];
if (item.id !== id) {
newAttachFileList.push(item);
}
}
}
this.setState({ attachFileList: newAttachFileList, });
}
renderAttachFileItem = (item, index) => {
const { id, url } = item;
return (
<View key={index} style={[styles.flex_row_space_between, styles.attachFileItem]}>
<View style={[styles.flex_row]}>
<Image source={{ uri: url, }} style={styles.attachImage} />
<Text style={[styles.defaultText, styles.attachFileText]}>{id}</Text>
</View>
<TouchableOpacity onPress={() => this.removeAttachFileItem(id)}>
<View style={[styles.iconWrap, { height: 50 / zoomH, width: 50 / zoomW, }]}>
<Image source={IMG_CloseOutline} style={[styles.iconStyle]} />
</View>
</TouchableOpacity>
</View>
);
}
handleSubmit = () => {
NoDoublePress.onPress(() => {
// 调用接口保存数据
const {
title,
isFullDay,
startDate,
endDate,
startTime,
endTime,
userList,
location,
desc,
attachFileList,
} = this.state;
if(!title) return xnToast('日程标题不能为空');
if(isFullDay && startDate > endDate) return xnToast('开始日期不能大于结束日期');
if(!isFullDay && startDate <= endDate && startTime > endTime) return xnToast('开始时间不能大于结束时间');
const params = {
title,
address: location,
description: desc,
userId: global.userId,
isAllDay: isFullDay,
beginTime: `${startDate} ${startTime}:00`,
endTime: `${endDate} ${endTime}:00`,
scheduleUserCreateRequestList: _.map(userList, user=>_.pick(user, 'userId')),
attachmentList: _.map(attachFileList, attachFile=>{
return {
storagePath: attachFile.url,
sourceType: 'NORMAL',
type: 'IMAGE'
}
})
}
AppService.createSchedule(params).then((data)=>{
xnToast('新建成功');
DeviceEventEmitter.emit('reloadPlanList');
this.props.navigation.goBack();
})
});
};
render() {
const {
title,
isFullDay,
startDate, startTime,
endDate, endTime,
userList,
location,
desc,
attachFileList,
} = this.state;
const datePickerMode = isFullDay === true ? 'date' : 'datetime';
let attachFileItems;
if (attachFileList.length > 0) {
attachFileItems = (
<View style={{ flex: 1, backgroundColor: '#fff', paddingTop: 14 / zoomW, }}>
{attachFileList.map((item, index) => this.renderAttachFileItem(item, index))}
</View>
);
}
return (
<View style={[{ flex: 1, backgroundColor: '#f3f3f3', }]}>
<ScrollView
showsVerticalScrollIndicator={false}
keyboardShouldPersistTaps="always">
<View style={styles.dividingLine}></View>
<View style={[styles.flex_row, styles.flex_row_padding, styles.titleWrap]}>
<TextInput
placeholder="添加日程标题"
multiline
placeholderTextColor="#999"
maxLength={128}
style={[styles.textInputStyle, { fontSize: 18, }]}
underlineColorAndroid="transparent"
onChangeText={this.onChangeTitle}
defaultValue={title}
blurOnSubmit={false}
/>
</View>
<View style={styles.dividingLine}></View>
<View style={[styles.flex_column, styles.timeSelectorWrap]}>
<View style={[styles.flex_row, styles.flex_row_padding]}>
<View style={[styles.dateSelector]}>
<TouchableOpacity onPress={this.showStartTimePicker}>
<View style={{ flex: 1, }}>
<View style={[styles.flex_row, { height: 24/zoomH, alignItems: 'center', }]}>
<Text style={styles.defaultText}>
{ isFullDay === true
? moment(startDate).locale('zh-cn').format('M月D日')
: moment(startDate).locale('zh-cn').format('M月D日 ddd')
}
</Text>
</View>
<View style={[styles.flex_row, { height: 24/zoomH, alignItems: 'center', }]}>
<Text style={styles.defaultText}>
{ isFullDay === true
? moment(startDate).locale('zh-cn').format('ddd')
: startTime
}
</Text>
</View>
</View>
</TouchableOpacity>
</View>
<View style={styles.arrowWrap}>
</View>
<View style={[styles.dateSelector]}>
<TouchableOpacity onPress={this.showEndTimePicker}>
<View style={{ flex: 1, }}>
<View style={[styles.flex_row, { height: 24/zoomH, alignItems: 'center', }]}>
<Text style={styles.defaultText}>
{ isFullDay === true
? moment(endDate).locale('zh-cn').format('M月D日')
: moment(endDate).locale('zh-cn').format('M月D日 ddd')
}
</Text>
</View>
<View style={[styles.flex_row, { height: 24/zoomH, alignItems: 'center', }]}>
<Text style={styles.defaultText}>
{ isFullDay === true
? moment(endDate).locale('zh-cn').format('ddd')
: endTime
}
</Text>
</View>
</View>
</TouchableOpacity>
</View>
</View>
<View style={[styles.dividingLine, { height: 1 / zoomH, }]}></View>
<View style={[styles.flex_row_space_between, styles.flex_row_padding]}>
<Text style={styles.defaultText}>全天</Text>
<Switch
trackColor={{ false: '#ccc', true: '#4dd865' }}
value={isFullDay}
onValueChange={this.toggleFullDay}
/>
</View>
</View>
<View style={styles.dividingLine}></View>
<TouchableOpacity onPress={this.handleSelectPeopleList}>
<View style={[styles.flex_row, styles.flex_row_padding]}>
<View style={styles.iconWrap}>
<Image source={IMG_PersonOutline} style={[styles.iconStyle]} />
</View>
{ userList.length > 0
? <View style={[styles.flex_column, styles.inputOrTextWrap]}>
<Text style={[styles.defaultText]}>我(组织人)</Text>
</View>
: <View style={[styles.flex_column, styles.inputOrTextWrap]}>
<Text style={[styles.defaultText, styles.placeholderText]}>添加参与人</Text>
</View>
}
{ userList.length == 0
? <View style={styles.iconWrap}>
<Image source={IMG_ChevronForwardOutline} style={[styles.iconStyle]} />
</View>
: undefined
}
</View>
</TouchableOpacity>
{ userList.length > 0 ? <View style={[styles.dividingLine, { height: 1 / zoomH, }]}></View> : undefined }
{ userList.length > 0 ?
<TouchableOpacity onPress={this.handleSelectPeopleList}>
<View style={[styles.flex_row, styles.flex_row_padding]}>
<View style={styles.iconWrap}>
<Image source={IMG_PeopleOutline} style={[styles.iconStyle]} />
</View>
<View style={[styles.flex_column, styles.inputOrTextWrap]}>
<Text style={[styles.defaultText]}>邀请 {userList[0].userName} 等 {userList.length}人</Text>
</View>
<View style={styles.iconWrap}>
<Image source={IMG_ChevronForwardOutline} style={[styles.iconStyle]} />
</View>
</View>
</TouchableOpacity> : undefined }
<View style={styles.dividingLine}></View>
<View style={[styles.flex_row, styles.flex_row_padding]}>
<View style={styles.iconWrap}>
<Image source={IMG_LocationOutline} style={[styles.iconStyle]} />
</View>
<View style={[styles.flex_column, styles.inputOrTextWrap]}>
<TextInput
placeholder="输入日程地点"
multiline
placeholderTextColor="#999"
maxLength={128}
style={[styles.textInputStyle, { textAlignVertical: 'center', }]}
underlineColorAndroid="transparent"
onChangeText={this.onChangeLocation}
defaultValue={location}
blurOnSubmit={false}
/>
</View>
</View>
{/* <View style={styles.dividingLine}></View>
<TouchableOpacity onPress={this.showNoticePicker}>
<View style={[styles.flex_row, styles.flex_row_padding]}>
<View style={styles.iconWrap}>
<Image source={IMG_NotificationsOutline} style={[styles.iconStyle]} />
</View>
<View style={[styles.flex_column, styles.inputOrTextWrap]}>
<Text style={[styles.defaultText]}>5分钟前</Text>
</View>
<View style={styles.iconWrap}>
<Image source={IMG_ChevronForwardOutline} style={[styles.iconStyle]} />
</View>
</View>
</TouchableOpacity> */}
<View style={styles.dividingLine}></View>
<TouchableOpacity onPress={() => {
// if (attachFileList.length == 0) {
this.handleAttachFileSelector();
// }
}}>
<View style={[styles.flex_row, styles.flex_row_padding]}>
<View style={styles.iconWrap}>
<Image source={IMG_AttachOutline} style={[styles.iconStyle, { width: 24 / zoomW, height: 24 / zoomH, }]} />
</View>
<View style={[styles.flex_column, styles.inputOrTextWrap]}>
{ attachFileList.length > 0
? <Text style={[styles.defaultText]}>附件</Text>
: <Text style={[styles.defaultText, styles.placeholderText]}>上传附件</Text>
}
</View>
{ attachFileList.length > 0
? <View style={styles.iconWrap}>
<Image source={IMG_AddCircleOutline} style={[styles.iconStyle]} />
</View>
: <View style={styles.iconWrap} onPress={() => {
if (attachFileList.length > 0) {
this.handleAttachFileSelector();
}
}}>
<Image source={IMG_ChevronForwardOutline} style={[styles.iconStyle]} />
</View>
}
</View>
</TouchableOpacity>
{ attachFileList.length > 0 ? <View style={[styles.dividingLine, { height: 1 / zoomH, }]}></View> : undefined }
{ attachFileList.length > 0 ? attachFileItems : undefined }
<View style={styles.dividingLine}></View>
<View style={[styles.flex_row, styles.flex_row_padding, { height: 100 / zoomH, }]}>
<View style={[styles.iconWrap, { justifyContent: "flex-start", }]}>
<Image source={IMG_ReaderOutline} style={[styles.iconStyle]} />
</View>
<View style={[styles.flex_column, styles.inputOrTextWrap]}>
<TextInput
placeholder="输入描述"
multiline
placeholderTextColor="#999"
maxLength={512}
style={[styles.textInputStyle]}
underlineColorAndroid="transparent"
onChangeText={this.onChangeDesc}
defaultValue={desc}
blurOnSubmit={false}
/>
</View>
</View>
<View style={styles.dividingLine}></View>
<View style={[styles.submitWrap]}>
{ this.state.submitting === false ?
<TouchableOpacity style={[styles.flex_column_center, styles.submitButton]} onPress={this.handleSubmit}>
<View>
<Text style={styles.submitButtonText}>完 成</Text>
</View>
</TouchableOpacity> :
<TouchableOpacity style={[styles.flex_column_center, styles.submitButtonDisabled]}>
<View>
<Text style={styles.submitButtonText}>提 交 中</Text>
</View>
</TouchableOpacity>
}
</View>
<View style={styles.dividingLine}></View>
<DatePicker
mode={datePickerMode}
format="YYYY-MM-DD HH:mm"
confirmBtnText="完成"
cancelBtnText="取消"
showIcon={false}
hideText={true}
is24Hour={true}
onDateChange={this.onChangeStartDateTime}
ref={(v) => (this.startDatePicker = v)}
/>
<DatePicker
mode={datePickerMode}
format="YYYY-MM-DD HH:mm"
confirmBtnText="完成"
cancelBtnText="取消"
showIcon={false}
hideText={true}
is24Hour={true}
onDateChange={this.onChangeEndDateTime}
ref={(v) => (this.endDatePicker = v)}
/>
</ScrollView>
{ this.state.loading &&
<View style={styles.loadingWrap}>
<View style={styles.loadingBox}>
<ActivityIndicator size='large' color='#fff'/>
<Text style={{ fontSize: 16, color: '#fff', marginTop: (6 / zoomH), }}>
加载中...
</Text>
</View>
</View>
}
</View>
);
}
}
const styles = StyleSheet.create({
flex_row: {
display: 'flex',
flexDirection: 'row',
backgroundColor: '#fff',
},
flex_row_space_between: {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: "space-between",
backgroundColor: '#fff',
},
flex_row_padding: {
paddingTop: 14 / zoomW,
paddingBottom: 12 / zoomW,
paddingLeft: 14 / zoomW,
paddingRight: 14 / zoomW,
},
flex_column: {
display: 'flex',
flexDirection: 'column',
backgroundColor: '#fff',
},
flex_column_center: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: "center",
},
dividingLine: {
height: 12 / zoomH,
backgroundColor: '#f3f3f3',
},
textInputStyle: {
flex: 1,
fontSize: 16,
height: '100%',
paddingLeft: 0,
paddingTop: 2 / zoomW,
paddingBottom: 2 / zoomW,
textAlignVertical: 'top',
},
defaultText: {
color: '#555',
fontSize: 16,
fontWeight: '400',
},
placeholderText: {
color: '#999999',
fontSize: 16,
fontWeight: '300',
},
iconWrap: {
alignItems: 'center',
justifyContent: "center",
width: 40 / zoomW,
height: '100%',
minHeight: 28 / zoomH,
},
iconStyle: {
width: 22 / zoomW,
height: 22 / zoomH,
},
inputOrTextWrap: {
flex: 1,
justifyContent: 'center',
paddingLeft: 12 / zoomW,
},
titleWrap: {
height: 80 / zoomH,
},
timeSelectorWrap: { },
dateSelector: {
flex: 1,
},
arrowWrap: {
width: 20 / zoomW,
},
submitWrap: {
paddingTop: 2 / zoomW,
paddingBottom: 2 / zoomW,
paddingLeft: 14 / zoomW,
paddingRight: 14 / zoomW,
},
submitButton: {
height: 40 / zoomH,
backgroundColor: '#28C35A',
},
submitButtonDisabled: {
height: 40 / zoomH,
backgroundColor: '#999999',
},
submitButtonText: {
color: '#fff',
fontSize: 16,
},
loadingWrap: {
position: "absolute",
top: 0,
width: "100%",
height: "100%",
display: "flex",
justifyContent: "center",
alignItems: "center"
},
loadingBox: {
width: 100 / zoomW,
height: 120 / zoomH,
backgroundColor: "rgba(0,0,0,.5)",
borderRadius: 8,
display: "flex",
alignItems: "center",
justifyContent: "center",
},
attachFileItem: {
paddingBottom: 12 / zoomW,
paddingLeft: 24 / zoomW,
paddingRight: 10 / zoomW,
},
attachImage: {
height: 44 / zoomH,
width: 44 / zoomW,
marginRight: 6 / zoomW,
borderWidth: 1 / zoomH,
borderColor: '#c3c3c3',
borderRadius: 4 / zoomW,
},
attachFileText: {
height: 44 / zoomH,
textAlignVertical: 'center',
},
});