home.js 5.22 KB
/**
 * Created by Cassie on 2018/05/14
 */
import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    Image,
    Text,
    StatusBar,
    TouchableOpacity,
} from 'react-native';
import QRCode from 'react-native-qrcode';
import {zoomW,zoomH} from '../utils/getSize';
import {xnToast,getHeaderPadding} from '../utils/utils';
import AppService from '../service/AppService'
const refresh = require('../img/refresh.png');
const backImg = require('../img/backImg.png');
export default class Home extends Component {
    constructor(props) {
        super(props);
        this.state = {
            AnnounceList:[],
            ownCount:0,
            loading:true,
            loadMore:false,
            key:'',
            type:'',
            imageAvatar:{},
            random:0,
            code:global.code,
            modalShow: true
        };
    }

    componentWillMount() {

    }
    componentDidMount(){
        this.props.navigation.setParams({
            title:'通行码',
            backgroundColor:'#37BF63',
            titleColor:'white',
            isBack:false,
        });
    };

    componentWillUnmount(){
    }
    toGetUnionCode(){
        AppService.getUserCode({}).then((data) => {
            if (data && data.code) {
                this.setState({
                    code:data.code
                });
            }
            this.setState({
                loading: false
            });
        }).catch((error) => {
            this.setState({
                loading: false
            });
            xnToast(error)
        });
    }
    render(){
        return(
            <View style={{flex:1,display:'flex',flexDirection:"column",alignItems:'stretch', justifyContent: 'center',backgroundColor:'#37BF63'}}>
                <StatusBar
                    backgroundColor={'#37BF63'}
                    networkActivityIndicatorVisible
                />
                <View style={{flex:1,display:'flex',flexDirection:"column",alignItems:'stretch', justifyContent: 'center',backgroundColor:'#37BF63'}}>
                    <View style={{ width: '100%', height: getHeaderPadding() }} />
                    <View style={[styles.header,{marginBottom: 39/zoomH,flexDirection:"row",}]}>
                    </View>
                    <View style={{justifyContent: 'center', alignItems: 'center'}}>
                        <View style={{width:330/zoomW, height:389/zoomH,borderRadius: 8, backgroundColor: '#ffffff',alignItems: 'center'}}>
                            <Text style={[styles.textTitleRemind,{marginTop:(39/zoomH)}]}>门禁通行码</Text>
                            <Text style={[styles.textModelRemind,{marginTop:(10/zoomH),marginBottom:(20/zoomH)}]}>请将二维码对准扫描口扫码开门</Text>
                            <TouchableOpacity style={[styles.textCenter,{padding:5,width:185/zoomW,height:193/zoomH}]} onPress={() => {this.toGetUnionCode()}}>
                                <QRCode
                                    value={this.state.code}
                                    size={160/zoomW}
                                    bgColor='black'
                                    fgColor='white'/>
                            </TouchableOpacity>
                            <View style={[styles.textCenter,{flexDirection:"row",marginTop:(20/zoomH)}]}>
                                <Image source={refresh} style={{ width: 11 / zoomW, height: 11 / zoomW }} resizeMode="contain"/><Text style={[styles.textRemind]}> 如超过5分钟有效时间,请点击二维码刷新</Text>
                            </View>
                        </View>
                        <View style={styles.backImgWrap}>
                            <Image source={backImg} style={{ width: 360 / zoomW, height: 178 / zoomH }} resizeMode="contain"/>
                        </View>
                    </View>
                </View>

            </View>
        );
    }

}

const styles = StyleSheet.create({
    textCenter: {
        backgroundColor:'transparent',
        flexDirection:"column",
        display:'flex',
        alignItems:'center',
        justifyContent: 'center',
    },
    backImgWrap: {
        width: '100%',
        height: 178 / zoomH,
        alignItems: 'center',
    },
    header: {
        width: '100%',
        height: 55 / zoomH,
        justifyContent: 'center',
        alignItems: 'center'
    },
    textRemind:{
        opacity: 0.45,
        fontSize: 12,
        color: '#000000',
    },
    textModelRemind:{
        fontSize: 14,
        color: '#888888',
    },
    textTitleRemind:{
        fontSize: 18,
        color: '#000000',
    },
    background:{
        flex:1,
        backgroundColor:'#ececf1',
        display:'flex',
        alignItems:'center'
    },
    itemBackground:{
        flex:1,
        backgroundColor:'#ffffff',
        display:'flex',
        alignItems:'center'
    },
    loadingBg:{
        width:'100%',
        height:'100%',
        position:'absolute',
        display:'flex',
        alignItems:'center',
        justifyContent:'center'
    },
    loadingBox:{
        width:(100/zoomW),
        height:(120/zoomH),
        backgroundColor:'rgba(0,0,0,.5)',
        borderRadius:8,
        display:'flex',
        alignItems:'center',
        justifyContent:'center'
    },

})