//
//  LoginViewModel.m
//  HDMall
//
//  Created by Javen on 2017/7/27.
//  Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//

#import "LoginViewModel.h"
#import "RootNavigationController.h"
#import "LoginViewController.h"
@implementation LoginViewModel

- (void)login:(void (^)(id responseObject, NSError *error))complete {
    WS(weakSelf);
    [ZJHttpManager POST:@"hdmall/authenticates/authen" parameters:self.loginRequest.toDictionary complete:^(id responseObject, NSError *error) {
        if (kIsResponse) {
            AppGlobal.user = [UserInfo modelWithDic:responseObject[@"data"]];
            
            complete(responseObject, error);
            [weakSelf openMain];
        }else{
            kFalseHttpTips;
        }
    }];
}

- (void)openMain {
    RootNavigationController *main = [RootNavigationController viewControllerWithStoryBoardType:(STORYBOARD_TYPE_MAIN)];
    [self open:main];
}

- (void)openLogin {
    LoginViewController *login = [LoginViewController viewControllerWithStoryBoardType:(STORYBOARD_TYPE_MAIN)];
    [self open:login];
}

- (void)open:(UIViewController *)viewController {
    viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [UIView transitionWithView:kWindow duration:0.7 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
        BOOL oldState = [UIView areAnimationsEnabled];
        [UIView setAnimationsEnabled:NO];
        kWindow.rootViewController = viewController;
        [UIView setAnimationsEnabled:oldState];
    } completion:nil];
}

ZJLazy(LoginRequest, loginRequest);

@end
