myEvents.js 8.69 KB
/**
 * Created by Cassie on 2018/03/21
 */
import React, { Component } from 'react';
import {
    StyleSheet,
    ScrollView,
    View,
    Text,
    TouchableOpacity,
    Image,
    TextInput,
    ActivityIndicator,
    Keyboard
} from 'react-native';

import {width,height,zoomW,zoomH} from '../../utils/getSize';
import {getHeaderPadding,xnToast,MD5} from "../../utils/utils";
import xnService from "../../service/AppService";
import md5 from 'md5';
import { NavigationActions } from 'react-navigation';

const bgImg = require('../../img/bgImg.png');
const logo = require('../../img/logo.png');
const phone = require('../../img/phone.png');
const pwd = require('../../img/pwd.png');
const bitmap = require('../../img/bitmap.png');

const phoneRule = /^1[3456789]\d{9}$/;

export default class myEvents extends Component {
    static navigationOptions = ({navigation,screenProps}) => ({
        header:null
    });

    constructor(props){
        super(props);
        this.state = {

        };
    };

    /*登录*/
    logoIn(){
        Keyboard.dismiss();
        if(this.state.mobile.length ==0 || !phoneRule.test(this.state.mobile)){
            xnToast('请输入正确的手机号!');
            return;
        }
        if(this.state.password.length == 0){
            xnToast('请输入密码!');
            return;
        }
        if(this.state.password.length < 6 || this.state.password.length > 16){
            xnToast('密码为6到16位!');
            return;
        }
        let params = {
            account:this.state.mobile,
            password:md5(this.state.password).toLocaleLowerCase(),
        };
        this.setState({
            loading:true
        });
        xnService.loginIn(params).then((data) => {
            this.setState({
                loading:false
            });
            if(data.message){
                xnToast(data.message);
                return;
            }
            if(data.errors.length > 0){
                xnToast(data.errors[0].message);
            }else{
                global.user = data.user;
                const resetAction = NavigationActions.reset({
                    index: 0,
                    actions: [
                        NavigationActions.navigate({ routeName: 'Root'})
                    ]
                })

                this.props.navigation.dispatch(resetAction)
            }
        });
    };

    /*跳转到忘记密码页面*/
    toforgetPwd(){
        this.props.navigation.navigate('ForgetPwd',{})
    };
    /*跳转到注册页面*/
    toRegister(){
        this.props.navigation.navigate('Register',{})
    };

    render(){
        return(
            <View style={styles.background}>
                <View style={styles.bgImg}>
                    <Image style={{width:width,height:height}} source={bgImg} resizeMode="stretch" />
                </View>
                <View style={[styles.bgImg,{backgroundColor:'rgba(0,0,0,.2)'}]} resizeMode="cover" />
                <View style={styles.signTop}>
                    <Image style={styles.logoImg} source={logo} />
                    <Text style={{color:'#fff',fontSize:18,fontWeight:'bold',backgroundColor:'rgba(0,0,0,0)'}}>平安地铁</Text>
                </View>
                <ScrollView style={styles.signMiddle} keyboardShouldPersistTaps="handled">
                    <View style={styles.inputItem}>
                        <View style={{width:(60/zoomW),display:'flex',justifyContent:'center',alignItems:'center'}}>
                            <Image style={{width:(22/zoomW),height:(22/zoomW)}} source={phone} resizeMode="center" />
                        </View>
                        <TextInput keyboardType="numeric" style={styles.input} placeholderTextColor="#fbfbfb" underlineColorAndroid="transparent" placeholder="输入手机号码" onChangeText={(value) => this.setState({mobile:value})} />
                        <View style={{width:(70/zoomW)}} />
                    </View>
                    <View style={styles.inputItem}>
                        <View style={{width:(60/zoomW),display:'flex',justifyContent:'center',alignItems:'center'}}>
                            <Image style={{width:(22/zoomW),height:(22/zoomW)}} source={pwd} resizeMode="center" />
                        </View>
                        <TextInput style={styles.input} placeholderTextColor="#fbfbfb" underlineColorAndroid="transparent" secureTextEntry={true} placeholder="输入密码" onChangeText={(value) => this.setState({password:value})} />
                        <TouchableOpacity style={{paddingLeft:(6/zoomW),paddingRight:(6/zoomW),display:'flex',justifyContent:'center',alignItems:'center'}} onPress={() => {this.toforgetPwd()}}>
                            <Text style={{fontSize:14,color:'#abd9ff',backgroundColor:'rgba(0,0,0,0)'}}>忘记密码?</Text>
                        </TouchableOpacity>
                    </View>
                    <TouchableOpacity activeOpacity={0.8} style={styles.signBtn} onPress={() => this.logoIn()}>
                        <Text style={{fontSize:18,color:'#fff'}}>登录</Text>
                    </TouchableOpacity>
                    <View style={{width:'100%',display:'flex',alignItems:'flex-end'}}>
                        <TouchableOpacity style={styles.registerBtn} onPress={() => this.toRegister()}>
                            <Text style={{fontSize:14,color:'#fff',backgroundColor:'rgba(0,0,0,0)'}}>立即注册</Text>
                        </TouchableOpacity>
                    </View>
                </ScrollView>
                {/*<View style={styles.signBottom}>*/}
                {/*<View style={styles.quickTip}>*/}
                {/*<View style={{flex:1,height:1,backgroundColor:'#f6f6f6'}} />*/}
                {/*<View style={{width:(107/zoomW),display:'flex',justifyContent:'center',alignItems:'center'}}>*/}
                {/*<Text style={{fontSize:14,color:'#fff'}}>快捷登录</Text>*/}
                {/*</View>*/}
                {/*<View style={{flex:1,height:1,backgroundColor:'#f6f6f6'}} />*/}
                {/*</View>*/}
                {/*<TouchableOpacity>*/}
                {/*<Image style={{width:(40/zoomW),height:(40/zoomW)}} source={bitmap} resizeMode="cover" />*/}
                {/*</TouchableOpacity>*/}
                {/*</View>*/}
                {/*<View style={{display:'flex',flexDirection:'row',justifyContent:'center'}}>*/}
                {/*<Text style={{fontSize:13,color:'#fff'}}>登录即代表阅读并同意</Text>*/}
                {/*<TouchableOpacity>*/}
                {/*<Text style={{fontSize:13,color:'#239afa'}}>《平安地铁用户协议》</Text>*/}
                {/*</TouchableOpacity>*/}
                {/*</View>*/}
                {this.state.loading && <View style={styles.loadingBg}>
                    <ActivityIndicator size="large" />
                </View>}
            </View>
        );
    }
}

const styles = StyleSheet.create({
    background:{
        flex:1,
        paddingTop:getHeaderPadding()
    },
    bgImg:{
        width:width,
        height:height,
        position:'absolute',
        top:0,
        bottom:0
    },
    signTop:{
        width:'100%',
        height:(160/zoomH),
        display:'flex',
        justifyContent:'flex-end',
        alignItems:'center',
        marginBottom:(20/zoomH)
    },
    logoImg:{
        width:(84/zoomW),
        height:(84/zoomW),
        marginBottom:(8/zoomH)
    },
    signMiddle:{
        width:'100%',
        paddingLeft:(30/zoomW),
        paddingRight:(30/zoomW)
    },
    inputItem:{
        width:'100%',
        height:(72/zoomH),
        borderBottomWidth:1,
        borderColor:'#f6f6f6',
        borderStyle:'solid',
        display:'flex',
        flexDirection:'row',
    },
    input:{
        flex:1,
        height:'100%',
        color:'#fbfbfb',
        fontSize:16
    },
    signBtn:{
        width:'100%',
        height:(50/zoomH),
        backgroundColor:'#239afa',
        opacity:.7,
        borderRadius:4,
        marginTop:(38/zoomH),
        display:'flex',
        justifyContent:'center',
        alignItems:'center'
    },
    registerBtn:{
        width:(60/zoomW),
        height:(54/zoomH),
        display:'flex',
        justifyContent:'center'
    },
    signBottom:{
        width:'100%',
        display:'flex',
        alignItems:'center',
        paddingLeft:(30/zoomW),
        paddingRight:(30/zoomW),
        marginTop:(40/zoomH),
        marginBottom:(22/zoomH)
    },
    quickTip:{
        width:'100%',
        height:(20/zoomH),
        display:'flex',
        flexDirection:'row',
        alignItems:'center',
        marginBottom:(16/zoomH)
    },
    loadingBg:{
        width:'100%',
        height:'100%',
        position:'absolute',
        display:'flex',
        alignItems:'center',
        justifyContent:'center'
    }
});