home.js
15.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
/**
* Created by Cassie on 2018/03/21
*/
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
TouchableOpacity,
Image,
TextInput,
Animated,
ActivityIndicator,
NativeModule
} from 'react-native';
import {zoomW,zoomH} from '../utils/getSize';
import {clock,xnToast,timeReduce,timePlus} from '../utils/utils';
import xnService from "../service/AppService";
const address = require('../img/address.png');
const circle = require('../img/circle.png');
const circleBtn = require('../img/circleBtn.png');
const addressG = require('../img/addressG.png');
const remind = require('../img/remind.png');
// const nativeBridge = NativeModules.BlueToolManage;
// const NativeModule = new NativeEventEmitter(nativeBridge);
export default class Home extends Component {
static navigationOptions = ({navigation}) => ({
title:'安全护航员',
});
constructor(props){
super(props);
this.state = {
obj:{},
nowTime:clock(),
canEdit:false,
loading:true,
thisTime:'00:00:00',
allTime:'0天0小时0分钟0秒',
deviceCode:'E2C56DB5-DFFB-48D2-B060-D0F5A71096E0|1726|1237',
rss:'-10'
};
};
componentWillMount(){
xnService.isAuto({id:'978091015737315328'}).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({
isAuto:data.safetyEscort.autoLaid,
isLaid:data.safetyEscort.isLaid,
id:data.safetyEscort.id,
todayEscortTime:data.todayEscortTime,
escortTime:data.escortTime
},function(){
this.setState({
timer:setInterval(() => {
this.setState({
nowTime:clock(),
thisTime:timeReduce(1522050677845,this.state.todayEscortTime),
allTime:timePlus(1522050677845,this.state.escortTime)
})
},1000)
});
})
}
});
this.getAddress(this.state.deviceCode,this.state.rss)
};
componentDidMount(){
// this.listener = NativeModule.addListener('BlueToolData',(data) => this.setState({obj:data}));
}
/*获取上岗地点*/
getAddress(deviceCode,RSS){
xnService.getAddress({deviceCode:deviceCode,RSS:RSS}).then((data) => {
if(data.message){
xnToast(data.message);
return;
}
if(data.errors.length > 0){
xnToast(data.errors[0].message);
}else{
alert(data);
}
})
};
/*修正上岗地点*/
changeAddress(){
this.setState({
canEdit:!this.state.canEdit
})
};
/*自动上下岗*/
switch(){
if(this.state.isAuto){
this.changeAuto(false);
}else{
this.changeAuto(true);
}
};
changeAuto(type){
this.setState({
loading:true
});
xnService.changeAuto({id:this.state.id,autoLaid:type}).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({
isAuto:!this.state.isAuto
})
}
})
};
/*清除定时器*/
componentWillUnmount(){
clearInterval(this.state.timer);
// this.listener.remove()
};
render(){
return (
<View style={styles.background}>
<View style={styles.top}>
<View style={styles.topLeft}>
<Text style={{fontSize:13,color:'#616161'}}>当前状态:</Text>
<View style={{flex:1,flexDirection:'row',justifyContent:'center'}}>
{this.state.isLaid && <Text style={{fontSize:18,color:'#3e6db7'}}>{this.state.isLaid ? '已上岗':'待上岗'}</Text>}
</View>
</View>
<View style={styles.topRight}>
<View style={{width:(96/zoomW),height:(25/zoomH),display:'flex',justifyContent:'center',alignItems:'center'}}>
<Text style={{fontSize:13,color:'#616161'}}>自动上、下岗</Text>
</View>
<TouchableOpacity activeOpacity={0.8} style={[styles.topBtn,{backgroundColor:this.state.isAuto ? '#1fbe6e':'#c9c7c7'}]} onPress={() => this.switch()}>
<Animated.View style={[styles.circle,{left:this.state.isAuto ? new Animated.Value(14/zoomW):new Animated.Value(2/zoomW)}]} />
</TouchableOpacity>
</View>
</View>
<View style={styles.content}>
{/*<View style={styles.errorTip}>*/}
{/*<Image style={{width:(18/zoomW),height:(18/zoomW)}} source={remind} resizeMode="cover" />*/}
{/*<Text style={{fontSize:14,color:'#f26e6e',marginLeft:(17/zoomW)}}>请确认已进入车厢</Text>*/}
{/*</View>*/}
<View style={[styles.contentItem,{height:(94/zoomH)}]}>
<Image style={styles.contentCircle} source={circle} resizeMode="cover" />
<View style={{height:(28/zoomH),display:'flex',flexDirection:'row',alignItems:'center'}}>
<View style={styles.contentTip}>
<Text style={{fontSize:14,color:'#636363'}}>上岗</Text>
</View>
<Text style={{fontSize:14,color:'#707070'}}>03-20 08:38:42</Text>
</View>
<View style={{height:(28/zoomH),display:'flex',flexDirection:'row',alignItems:'center'}}>
<View style={styles.contentTip}>
<Image style={{width:(17/zoomW),height:(17/zoomW)}} source={address} resizeMode="center" />
</View>
{!this.state.canEdit && <Text style={{fontSize:14,color:'#707070'}}>1号线00018号车厢</Text>}
{this.state.canEdit && <View style={{display:'flex',flexDirection:'row',alignItems:'center'}}>
<View style={[styles.canEdit,{width:(20/zoomW)}]}>
<TextInput autoFocus={true} maxLength={2} underlineColorAndroid="transparent" style={{padding:0,width:(16/zoomW)}} />
</View>
<Text style={{fontSize:14,color:'#707070'}}>号线</Text>
<View style={[styles.canEdit,{width:(50/zoomW)}]}>
<TextInput maxLength={5} underlineColorAndroid="transparent" style={{padding:0,width:(40/zoomW)}} />
</View>
<Text style={{fontSize:14,color:'#707070'}}>号车厢</Text>
</View>}
<TouchableOpacity style={{marginLeft:(20/zoomW)}} onPress={() => this.changeAddress()}>
<Text style={{fontSize:12,color:'#4b85e0'}}>修正</Text>
</TouchableOpacity>
</View>
</View>
{!this.state.isAuto && <View style={[styles.contentItem,{height:(246/zoomH),borderBottomWidth:0}]}>
<Image style={styles.contentCircle} source={circle} resizeMode="cover" />
<View style={{height:(28/zoomH),display:'flex',flexDirection:'row',alignItems:'center'}}>
<View style={styles.contentTip}>
<Text style={{fontSize:14,color:'#636363'}}>上岗</Text>
</View>
</View>
<View style={{height:(30/zoomH),display:'flex',flexDirection:'row',alignItems:'flex-end',justifyContent:'center',marginLeft:-(35/zoomW)}}>
<Text style={{fontSize:12,color:'#4b85e0'}}>点击下岗</Text>
</View>
<View style={styles.circleBtnBox}>
<TouchableOpacity style={{width:(110/zoomW),height:(110/zoomW),display:'flex',alignItems:'center',justifyContent:'center'}} activeOpacity={0.8}>
<Image style={styles.circleBtn} source={circleBtn} resizeMode="center" />
<Text style={{fontSize:14,color:'#fff'}}>下岗</Text>
<Text style={{fontSize:14,color:'#fff'}}>{this.state.nowTime}</Text>
</TouchableOpacity>
</View>
<View style={{marginLeft:-(35/zoomW),display:'flex',flexDirection:'row',justifyContent:'center',alignItems:'center'}}>
<Image style={{width:(17/zoomW),height:(17/zoomW),marginRight:(7/zoomW)}} source={addressG} resizeMode="center" />
<Text style={{fontSize:12,color:'#a0a0a0'}}>当前下岗位置:1号线00018号车厢</Text>
{/*<Text style={{fontSize:14,color:'#f26e6e'}}>请确认已进入车厢</Text>*/}
</View>
</View>}
{this.state.isAuto && <View style={[styles.contentItem,{height:(94/zoomH),borderBottomWidth:0}]}>
<Image style={styles.contentCircle} source={circle} resizeMode="cover" />
<View style={{height:(28/zoomH),display:'flex',flexDirection:'row',alignItems:'center'}}>
<View style={styles.contentTip}>
<Text style={{fontSize:14,color:'#636363'}}>在岗</Text>
</View>
<Text style={{fontSize:14,color:'#707070'}}>03-20 08:38:42</Text>
</View>
<View style={{height:(28/zoomH),display:'flex',flexDirection:'row',alignItems:'center'}}>
<View style={styles.contentTip}>
<Image style={{width:(17/zoomW),height:(17/zoomW)}} source={addressG} resizeMode="center" />
</View>
<Text style={{fontSize:14,color:'#707070'}}>1号线00018号车厢</Text>
</View>
</View>}
</View>
<View style={styles.bottom}>
<View style={styles.bottomItem}>
<View style={{width:(124/zoomW)}}>
<Text style={{fontSize:14,color:'#9f9f9f'}}>今日累计在岗时间:</Text>
</View>
<View style={{flex:1}}>
<Text style={{fontSize:14,color:'#4b85e0'}}>{this.state.thisTime}</Text>
</View>
</View>
<View style={[styles.bottomItem,{borderBottomWidth:0}]}>
<View style={{width:(124/zoomW)}}>
<Text style={{fontSize:14,color:'#9f9f9f'}}>总公益时间:</Text>
</View>
<View style={{flex:1}}>
<Text style={{fontSize:14,color:'#4b85e0'}}>{this.state.allTime}</Text>
</View>
</View>
</View>
{this.state.loading && <View style={styles.loadingBg}>
<ActivityIndicator size="large" />
</View>}
</View>
);
}
}
const styles = StyleSheet.create({
background:{
flex:1,
backgroundColor:'#f6f6f6',
display:'flex',
alignItems:'center',
paddingLeft:(15/zoomW),
paddingRight:(15/zoomW)
},
top:{
width:'100%',
height:(44/zoomH),
backgroundColor:'#fff',
borderRadius:8,
marginTop:(15/zoomH),
marginBottom:(15/zoomH),
paddingLeft:(15/zoomW),
paddingRight:(15/zoomW),
elevation:2,
shadowColor:'#a9a9a9',
shadowOffset:{width:0,height:2},
shadowOpacity:0.5,
shadowRadius:4,
display:'flex',
flexDirection:'row',
alignItems:'center'
},
topLeft:{
width:(190/zoomW),
height:(25/zoomH),
display:'flex',
flexDirection:'row',
alignItems:'center',
borderRightWidth:1,
borderColor:'#f6f6f6',
borderStyle:'solid'
},
topRight:{
flex:1,
height:(25/zoomW),
display:'flex',
flexDirection:'row',
alignItems:'center'
},
topBtn:{
width:(30/zoomW),
height:(16/zoomH),
borderRadius:(8/zoomH),
display:'flex',
justifyContent:'center'
},
circle:{
width:(14/zoomH),
height:(14/zoomH),
borderRadius:(7/zoomH),
backgroundColor:'#fff',
position:'absolute'
},
content:{
width:'100%',
backgroundColor:'#fff',
paddingLeft:(15/zoomW),
paddingRight:(15/zoomW)
},
contentItem:{
width:'100%',
borderBottomWidth:1,
borderColor:'#f6f6f6',
borderStyle:'solid',
paddingTop:(20/zoomH),
paddingLeft:(35/zoomW)
},
contentTip:{
width:(28/zoomW),
display:'flex',
alignItems:'center',
marginRight:(15/zoomW)
},
contentCircle:{
width:(18/zoomW),
height:(18/zoomW),
position:'absolute',
top:(35/zoomH)
},
circleBtnBox:{
height:(110/zoomH),
marginLeft:-(35/zoomW),
marginBottom:(6/zoomH),
display:'flex',
alignItems:'center'
},
circleBtn:{
width:'100%',
height:'100%',
position:'absolute',
top:0
},
bottom:{
width:'100%',
backgroundColor:'#fff',
marginTop:(15/zoomH),
paddingLeft:(15/zoomW),
paddingRight:(15/zoomW)
},
bottomItem:{
width:'100%',
height:(44/zoomH),
borderBottomWidth:1,
borderColor:'#f6f6f6',
borderStyle:'solid',
display:'flex',
flexDirection:'row',
alignItems:'center'
},
canEdit:{
display:'flex',
alignItems:'center'
},
errorTip:{
display:'flex',
flexDirection:'row',
alignItems:'center',
paddingTop:(20/zoomH)
},
loadingBg:{
width:'100%',
height:'100%',
position:'absolute',
display:'flex',
alignItems:'center',
justifyContent:'center'
}
});