//
//  ResetPasswordViewController.m
//  ALand
//
//  Created by Z on 16/3/18.
//  Copyright © 2016年 Z. All rights reserved.
//

#import "ResetPasswordViewController.h"
#import "NextResetPasswordViewController.h"
#import "NSString+Category.h"
@interface ResetPasswordViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *phoneNumber;
@property (weak, nonatomic) IBOutlet UIButton *btnNext;

@end

@implementation ResetPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"重置密码";

    self.phoneNumber.delegate = self;
    // Do any additional setup after loading the view from its nib.
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *strName = [textField.text stringByReplacingCharactersInRange:range withString:string];
    self.btnNext.enabled = [strName isMobileNumber] == nil;
    
    return YES;
}

- (IBAction)nextAction:(UIButton *)sender {
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    NSDictionary *parameters = @{@"mobilephone":self.phoneNumber.text,
                                 @"template":[NSNull null]};
    WS(weakSelf)
    

        [[HTTPCilent shareCilent] GET:@"app/sendSms" parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
            [MBProgressHUD hideHUDForView:weakSelf.view];

            if (kIsResponseSuccess(responseObject)) {
                NextResetPasswordViewController *nextVC = [[NextResetPasswordViewController alloc] initWithNibName:@"NextResetPasswordViewController" bundle:[NSBundle mainBundle]];
                nextVC.isShowNavigationBar = YES;
                nextVC.mobilePhone = weakSelf.phoneNumber.text;
                [weakSelf.navigationController pushViewController:nextVC animated:YES];
            }else{
                [MBProgressHUD Javen_showError:responseObject[@"message"] onView:kWindow delay:2 complete:nil];
            }
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            
        }];

    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //[self.navigationController setNavigationBarHidden:NO];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
