home.js 6.17 KB
/**
 * Created by Cassie on 2018/05/14
 */
import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    Image,
    Text,
    Modal,
    TouchableOpacity,
    InteractionManager,
    NativeModules,
    StatusBar
} 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 back = require('../img/back.png');
const refresh = require('../img/refresh.png');
const backImg = require('../img/backImg.png');
export default class Home extends Component {
    static navigationOptions = ({ navigation, screenProps }) => ({
        header:null
    });
    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({
            close:()=>{
                InteractionManager.runAfterInteractions(() => {NativeModules.system.navTo("BACK");})
            }
        });
    };

    componentWillUnmount(){
        this.setState = (state,callback)=>{
            return;
        };

    }

    back(){
        // this.props.navigation.goBack();
    };
    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>
                <StatusBar
                    backgroundColor={'#37BF63'}
                    networkActivityIndicatorVisible
                />
                <Modal
                    animationType={'none'}
                    visible={this.state.modalShow}
                    transparent
                    onRequestClose={() => {}}
                >
                    <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: 53/zoomH,flexDirection:"row",}]}>
                            <TouchableOpacity style={[styles.topIcon,{position:"absolute",left:23/zoomW}]}  onPress = {() => NativeModules.system.navTo("BACK")}>
                                <Image source={back} style={{width:(16/zoomH),height:(16/zoomH)}} resizeMode="contain" />
                            </TouchableOpacity>
                            <Text style={{fontSize: 18, color: '#ffffff'}}>通行码</Text>
                        </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={180}
                                        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>
                </Modal>
            </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: 48 / zoomH,
        justifyContent: 'center',
        alignItems: 'center'
    },
    textRemind:{
        opacity: 0.35,
        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'
    },

})