home.js 12.7 KB
/**
 * Created by Cassie on 2018/03/21
 */
import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    Text,
    TouchableOpacity,
    Image,
    TextInput,
    Animated
} from 'react-native';

import {zoomW,zoomH} from '../utils/getSize';
import {clock} from '../utils/utils';

const address = require('../img/address.png');
const circle = require('../img/circle.png');
const circleBtn = require('../img/circleBtn.png');
const addressG = require('../img/addressG.png');

export default class Home extends Component {
    static navigationOptions = ({navigation}) => ({
        title:'安全护航员',
    });

    constructor(props){
        super(props);
        this.state = {
            auto:true,
            left:new Animated.Value(14/zoomW),
            switchBg:'#1fbe6e',
            time:clock(),
            canEdit:false
        };
    };

    componentWillMount(){
        this.setState({
            timer:setInterval(() => {
               this.setState({
                   time:clock()
               })
            },1000)
        })
    };

    /*修正上岗地点*/
    changeAddress(){
        this.setState({
            canEdit:!this.state.canEdit
        })
    };
    /*自动上下岗*/
    switch(){
        if(this.state.switchBg == '#1fbe6e'){ //如果是打开状态
            this.setState({
                switchBg:'#c9c7c7',
                auto:false
            });
            Animated.timing(
                this.state.left,
                {toValue:(2/zoomW),duration:200}
            ).start();
        }else if(this.state.switchBg == '#c9c7c7'){ //如果是关闭状态
            this.setState({
                switchBg:'#1fbe6e',
                auto:true
            });
            Animated.timing(
                this.state.left,
                {toValue:(14/zoomW),duration:200}
            ).start();
        }
    };
    /*清除定时器*/
    componentWillUnmount(){
        clearInterval(this.state.timer)
    };

    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'}}>
                            {/*<Text style={{fontSize:18,color:'#3e6db7'}}>已上岗</Text>*/}
                            <Text style={{fontSize:18,color:'#a0a0a0'}}>待上岗</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.switchBg}]} onPress={() => this.switch()}>
                            <Animated.View style={[styles.circle,{left:this.state.left}]} />
                        </TouchableOpacity>
                    </View>
                </View>
                <View style={styles.content}>
                    {/*<View style={styles.errorTip}>*/}
                        {/*<Image style={{width:(18/zoomW),height:(18/zoomW)}} source={circle} 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.auto && <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.time}</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.auto && <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'}}>00:08:34</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'}}>3715小时45分钟23</Text>
                        </View>
                    </View>
                </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)
    }
});