userLogoutReasonActions.js 3.5 KB
/**
 * sub app userLogout
 * @author: lixia.zhang
 * @date: 2018/04/13
 */


'use strict';

import ReactNative from 'react-native';
import UserLogoutReasonService from '../../services/UserLogoutReasonService';

const {
    ENABLE_SUBMIT_BTN,
    SHOW_LOGOUT_REASON_MODAL,
    SET_IMAGE_CHECK_SWITCH_STATE,
    IMAGE_CHECK_CODE_URL,
    UPDATE_TIP_MESSAGE,
} = require('../../constants/actionTypes').default;

export function enableSubmitBtn(flag) {
    return{
        type:ENABLE_SUBMIT_BTN,
        payload: flag
    }
}

export function showLogoutReasonModal(state) {
    return{
        type:SHOW_LOGOUT_REASON_MODAL,
        payload: state
    }
}

export function setImageCheckSwitchState(state) {
    return {
        type: SET_IMAGE_CHECK_SWITCH_STATE,
        payload: state
    }
}

export function imgeCheckCodeUrl(url) {
    return {
        type: IMAGE_CHECK_CODE_URL,
        payload: url
    }
}

export function updateTipMessage(tipMesage) {
    return {
        type: UPDATE_TIP_MESSAGE,
        payload: tipMesage
    }
}

export function fetchImageCheckSwitchState() {
    return (dispatch, getState) => {
        let {app} = getState();
        let udid = ReactNative.NativeModules.RNNativeConfig.udid;
        return new UserLogoutReasonService('http://api-test3.yohops.com:9999/').fetchImageCheckSwitchState(udid)
            .then(json => {
                dispatch(setImageCheckSwitchState(json));
            })
            .catch(error => {
                console.log(error);
            });
    }
}

export function fetchCanleCode(mobile, degrees) {
    return (dispatch, getState) => {
        let {app} = getState();
        let udid = ReactNative.NativeModules.RNNativeConfig.udid;
        return new UserLogoutReasonService('http://api-test3.yohops.com:9999/').fetchCancleCode(mobile, degrees, udid)
            .then(json => {
                dispatch(fetchImageCheckSwitchState());
                dispatch(updateTipMessage('验证短信已发送,请注意查收'));
            })
            .catch(error => {
                if(error.message != '') {
                    dispatch(updateTipMessage(error.message));
                }
            });
    }
}

export function confirmLogout(code, reason) {
    return (dispatch, getState) => {
        let {app} = getState();
        let udid = ReactNative.NativeModules.RNNativeConfig.udid;
        return new UserLogoutReasonService('http://api-test3.yohops.com:9999/').confirmLogout(code, reason, udid)
            .then(json => {
                dispatch(showLogoutReasonModal(false));
                dispatch(gotoLogoutStatus());
            })
            .catch(error => {
                if(error.message != '') {
                    dispatch(updateTipMessage(error.message));
                }
            });
    }
}

export function generateCheckImageUrl() {
    return (dispatch, getState) => {
        let {app} = getState();
        let udid = ReactNative.NativeModules.RNNativeConfig.udid;
        var timeStamp = Date.parse(new Date());
        let imageUrl = 'http://api-test3.yohops.com:9999' + '/passport/img-check' + '?business_line=yohobuy' + '&udid=' + udid + '&fromPage=' + 'UserLogoutReason' + '&timeStamp=' + timeStamp;
        dispatch(imgeCheckCodeUrl(imageUrl));
    }
}



export function gotoLogoutStatus() {
    return (dispatch, getState) => {
        let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.userLogout","params":{"title":"申请状态","type":"userLogoutStatus"}}`;
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
    }
}