setting.js 4.62 KB
/**
 * Created by DEV005 on 2017/10/27.
 */
/**
 * Created by tdzl2003 on 12/18/16.
 */

import React, {Component, PropTypes} from 'react';
import {
    StyleSheet,
    Image,
    TouchableOpacity,
    TouchableHighlight,
    ScrollView,
    Button,
    TextInput,
    Text,
    View,
    Alert,
    NativeModules,
    ListView,
    RefreshControl,
    DeviceEventEmitter,
    AsyncStorage
} from 'react-native';
import {xnToast} from "./../utils/utils";
import AppService from "./../service/AppService";
import mainCss from "./../css/css";
import Loading from '../components/Loading'
import { NavigationActions } from 'react-navigation'
import Verification from "./publish/verification";
import Password from "./publish/password";
import MD5 from "md5";

let  passwordOne="";
let  passwordTwo="";

export default class password extends Component {

    static navigationOptions = ({ navigation, screenProps })=>({
        title: '设置密码',
        headerLeft:(<View style={{flexDirection: 'row',flex: 1}}>
            <TouchableOpacity style={{flexDirection: 'column',justifyContent: 'center',paddingRight:10,paddingLeft:10}} onPress={navigation.state.params?navigation.state.params._goBack:null}>
                <Image style={{  width:20,height:20}}  source={require('../img/back.png')}  resizeMode="contain"/>
            </TouchableOpacity>
            <TouchableOpacity  style={{flexDirection: 'column',justifyContent: 'center',paddingLeft:10}} onPress={navigation.state.params?navigation.state.params._close:null}>
                <Image   style={{ width:20,height:20}}  source={require('../img/close.png')}  resizeMode="contain"/>
            </TouchableOpacity>
        </View>)
    });

    constructor(props){
        super(props);
        this.state = {
            title:"输入交易密码",
            isVerification:false,
            isLoading:false
        };
    }


    componentWillMount(){
        //设置头部
        this.props.navigation.setParams({
            _goBack:()=>{
                this.props.navigation.goBack();
            },
            _close:()=>{
                NativeModules.system.navTo("BACK")
            }
        });
        let _this=this;
        //获取列表
        this._init();

    }
    _init=()=>{


    };

    //跳转
    verification=(status)=>{
        console.log(status);
        if(status){
            this.setState({
                isVerification:true
            })
        }
    };

    _password=(pass)=>{
        console.log(pass);
        let  _this=this;
        if(passwordOne==""){
            passwordOne=pass;
            this.setState({
                title:"确认交易密码"
            });
            DeviceEventEmitter.emit("initPassword","init");
            return;
        }else {
            passwordTwo=pass;
        }

        if(passwordOne!=passwordTwo){
            passwordOne="";
            passwordTwo="";
            xnToast("两次密码不一致,请重新输入!");
            this.setState({
                title:"输入交易密码"
            });
            DeviceEventEmitter.emit("initPassword","init");
            return
        }

        if(passwordOne==passwordTwo){
            let  vm={
                id:global.userId,
                tenantId:global.tenantId,
                transactionPassword:MD5(passwordOne)
            };
            this.setState({
                isLoading:true
            });
            AppService.userTransactionPasswordUpdate(vm).then(data=>{
                this.setState({
                    isLoading:false
                });
                if (data.errors == null || data.errors.length > 0) {
                    xnToast(data.errors[0].message);
                    return
                }
                xnToast("设置成功!");
                passwordOne="";
                passwordTwo="";

                setTimeout(function () {
                    if(_this.props.navigation.state.params){
                        _this.props.navigation.state.params.callBack()
                    }
                    _this.props.navigation.goBack();
                },2000)

            });
        }else {

        }
    };

    render() {
        return (
            <View style={mainCss.body}>
                <View style={mainCss.main}>
                    {!this.state.isVerification&&<Verification toForget={this.toForget}  callBack={this.verification}></Verification>}
                    {this.state.isVerification&&<Password title={this.state.title}  callBack={this._password} ></Password>}
                    <Loading  visible={this.state.isLoading} content="验证中"  ></Loading>
                </View>
            </View>
        );
    };

}