remindSetting.js
15.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
/**
* Created by Cassie on 2018/05/14
*/
import React, {Component} from "react";
import {
StyleSheet,
View,
Text,
TouchableOpacity,
Image,
Animated,
ScrollView,
ActivityIndicator,
Alert
} from "react-native";
import {zoomW, zoomH} from "../../utils/getSize";
import {NoDoublePress, xnToast} from "../../utils/utils";
import AppService from "../../service/AppService";
const back = require('../../img/returnB.png');
const selected = require('../../img/selectedG.png');
export default class RemindSetting extends Component {
static navigationOptions = ({navigation, screenProps}) => ({
title: '提醒',
headerLeft: (<View style={{flex: 1, display: 'flex', flexDirection: 'row'}}>
<TouchableOpacity style={styles.topIcon}
onPress={navigation.state.params ? navigation.state.params.back : null}>
<Image source={back} style={{width: (16 / zoomH), height: (16 / zoomH)}} resizeMode="contain"/>
</TouchableOpacity>
</View>),
headerRight: (<View style={{flex: 1, display: 'flex', flexDirection: 'row'}}/>)
});
constructor(props) {
super(props);
this.state = {
left: new Animated.Value(2 / zoomH),
timeLeft: new Animated.Value(2 / zoomH),
background: '#c6c6c6',
timeBackground: '#c6c6c6',
setting: [{name: '全部提醒', value: 'ALL'}, {name: '回复我的', value: 'COMMENT_TO_ME'}],
timeSetting: [{name: '结束时', value: 0}, {name: '结束前5分钟', value: 5}, {
name: '结束前10分钟',
value: 10
}, {name: '结束前15分钟', value: 15}, {name: '结束前30分钟', value: 30}, {name: '结束前1小时', value: 60}, {
name: '结束前2小时',
value: 120
}, {name: '结束前一天', value: 1440}],
typeIndex: -1,
timeIndex: -1
};
};
componentWillMount() {
this.taskId = this.props.navigation.state.params.taskId
};
componentDidMount() {
this.props.navigation.setParams({
back: () => {
NoDoublePress.onPress(() => {
if (global.isConnected) {
if (this.state.isDynamicNotification && !this.state.alarmType) {
Alert.alert(
'提示',
'请选择推送方式',
[
{
text: '确定', onPress: () => {
return
}
}
],
{cancelable: false}
);
return;
}
if (this.state.isTimeAlarm && !this.state.aheadTimeCount) {
Alert.alert(
'提示',
'请选择提醒方式',
[
{
text: '确定', onPress: () => {
return
}
}
],
{cancelable: false}
);
return;
}
let params = {
taskId: this.taskId,
isDynamicNotification: this.state.isDynamicNotification,
alarmType: this.state.alarmType,
isTimeAlarm: this.state.isTimeAlarm,
aheadTimeCount: this.state.aheadTimeCount ? this.state.aheadTimeCount : null,
};
this.setState({
returnLoading: true
});
AppService.updateRemind(params).then((data) => {
this.setState({
returnLoading: false
});
if (data.message) {
xnToast(data.message);
return;
}
if (data.errors.length > 0) {
xnToast(data.errors[0].message);
} else {
xnToast('设置成功');
this.props.navigation.goBack();
}
}).catch((error) => {
this.setState({
loading: false
});
xnToast(error)
})
} else {
xnToast('暂无网络连接,请稍后重试!')
}
})
}
});
this.getCurrrentStatus();
};
/*获取当前提醒设置*/
getCurrrentStatus() {
if (global.isConnected) {
this.setState({
loading: true
});
AppService.getRemind({taskId: this.taskId}).then((data) => {
this.setState({
loading: false
});
if (data.message) {
xnToast(data.message);
return;
}
if (data.errors.length > 0) {
xnToast(data.errors[0].message);
} else {
this.setState({
isDynamicNotification: data.taskUser.isDynamicNotification,
alarmType: data.taskUser.alarmType ? data.taskUser.alarmType : null,
isTimeAlarm: data.taskUser.isTimeAlarm,
aheadTimeCount: data.taskUser.aheadTimeCount ? data.taskUser.aheadTimeCount : null,
});
if (data.taskUser.isDynamicNotification) {
this.setState({
background: '#00be3c',
left: new Animated.Value(32 / zoomH)
});
} else {
this.setState({
background: '#c6c6c6',
left: new Animated.Value(2 / zoomH)
});
}
if (data.taskUser.isTimeAlarm) {
this.setState({
timeBackground: '#00be3c',
timeLeft: new Animated.Value(32 / zoomH)
});
} else {
this.setState({
timeBackground: '#c6c6c6',
timeLeft: new Animated.Value(2 / zoomH)
});
}
}
}).catch((error) => {
this.setState({
loading: false
});
xnToast(error)
})
} else {
xnToast('暂无网络连接,请稍后重试!')
}
};
/*是否打开提醒*/
isTop(type) {
if (type == 'top') {
if (!this.state.isDynamicNotification) {
this.setState({
background: '#00be3c',
isDynamicNotification: true
});
Animated.timing(
this.state.left,
{toValue: (32 / zoomH), duration: 200}
).start();
} else {
this.setState({
background: '#c6c6c6',
alarmType: null,
isDynamicNotification: false
});
Animated.timing(
this.state.left,
{toValue: (2 / zoomH), duration: 200}
).start();
}
} else if (type == 'time') {
if (!this.state.isTimeAlarm) {
this.setState({
timeBackground: '#00be3c',
isTimeAlarm: true
});
Animated.timing(
this.state.timeLeft,
{toValue: (32 / zoomH), duration: 200}
).start();
} else {
this.setState({
timeBackground: '#c6c6c6',
aheadTimeCount: null,
timeIndex: -1,
isTimeAlarm: false
});
Animated.timing(
this.state.timeLeft,
{toValue: (2 / zoomH), duration: 200}
).start();
}
}
};
/*渲染方式列表*/
renderTypeList(item, index) {
return (
<TouchableOpacity activeOpacity={0.8} key={index} style={styles.settingItem}
onPress={() => this.selectType(item)}>
<View style={{flex: 1}}>
<Text style={{fontSize: 17, color: '#000'}}>{item.name}</Text>
</View>
{!!this.state.alarmType && this.state.alarmType == item.value &&
<View style={{width: (50 / zoomW), display: 'flex', justifyContent: 'center', alignItems: 'center'}}>
<Image source={selected} style={{width: (16 / zoomH), height: (16 / zoomH)}} resizeMode="contain"/>
</View>}
</TouchableOpacity>
)
};
/*渲染提醒列表*/
renderTimeList(item, index) {
return (
<TouchableOpacity activeOpacity={0.8} key={index} style={styles.settingItem}
onPress={() => this.selectTime(item)}>
<View style={{flex: 1}}>
<Text style={{fontSize: 17, color: '#000'}}>{item.name}</Text>
</View>
{(!!this.state.aheadTimeCount || this.state.aheadTimeCount == 0) && this.state.aheadTimeCount == item.value &&
<View style={{width: (50 / zoomW), display: 'flex', justifyContent: 'center', alignItems: 'center'}}>
<Image source={selected} style={{width: (16 / zoomH), height: (16 / zoomH)}} resizeMode="contain"/>
</View>}
</TouchableOpacity>
)
};
/*设置提醒方式*/
selectType(item) {
if (this.state.alarmType == item.value) {
this.setState({
alarmType: null,
})
} else {
this.setState({
alarmType: item.value
})
}
};
/*设置提醒时间*/
selectTime(item) {
if (this.state.aheadTimeCount == item.value) {
this.setState({
aheadTimeCount: null,
})
} else {
this.setState({
aheadTimeCount: item.value
})
}
};
componentWillUnmount() {
this.setState = (state, callback) => {
return;
};
};
render() {
return (
<View style={styles.background}>
{!this.state.loading && <ScrollView style={{width: '100%'}}>
<View style={styles.settingItem}>
<View style={{flex: 1}}>
<Text style={{fontSize: 17, color: '#000'}}>任务动态推送</Text>
</View>
<TouchableOpacity activeOpacity={0.8}
style={[styles.topBtn, {backgroundColor: this.state.background}]}
onPress={() => NoDoublePress.onPress(() => {
this.isTop('top')
})}>
<Animated.View style={[styles.circleDot, {left: this.state.left}]}/>
</TouchableOpacity>
</View>
{this.state.isDynamicNotification && this.state.setting && this.state.setting.map((item, index) => this.renderTypeList(item, index))}
<View style={[styles.settingItem, {marginTop: (20 / zoomH)}]}>
<View style={{flex: 1}}>
<Text style={{fontSize: 17, color: '#000'}}>时间提醒</Text>
</View>
<TouchableOpacity activeOpacity={0.8}
style={[styles.topBtn, {backgroundColor: this.state.timeBackground}]}
onPress={() => NoDoublePress.onPress(() => {
this.isTop('time')
})}>
<Animated.View style={[styles.circleDot, {left: this.state.timeLeft}]}/>
</TouchableOpacity>
</View>
{this.state.timeSetting && this.state.isTimeAlarm && this.state.timeSetting.map((item, index) => this.renderTimeList(item, index))}
</ScrollView>}
{(this.state.loading || this.state.returnLoading) && <View style={styles.loadingBg}>
<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({
topIcon: {
paddingLeft: (10 / zoomW),
paddingRight: (10 / zoomW),
height: '100%',
display: 'flex',
justifyContent: 'center'
},
background: {
flex: 1,
backgroundColor: '#ececf1',
display: 'flex',
alignItems: 'center'
},
settingItem: {
width: '100%',
height: (50 / zoomH),
backgroundColor: '#fff',
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: '#eee',
borderStyle: 'solid',
paddingLeft: (15 / zoomW),
paddingRight: (15 / zoomW)
},
topBtn: {
width: (60 / zoomH),
height: (30 / zoomH),
borderRadius: (15 / zoomH),
display: 'flex',
justifyContent: 'center'
},
circleDot: {
width: (26 / zoomH),
height: (26 / zoomH),
backgroundColor: '#fff',
borderRadius: (13 / zoomH),
position: 'absolute'
},
loadingBg: {
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'
}
});