//
//  ChangePasswordViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/5/9.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ChangePasswordViewController.h"

@interface ChangePasswordViewController ()

@end

@implementation ChangePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
     [self uiConfigAction];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}


#pragma mark - UI
- (void)uiConfigAction
{
    self.userNameBack.layer.masksToBounds = YES;
    self.userNameBack.layer.cornerRadius = kCornerRadius;
    self.oldPasswordBack.layer.masksToBounds = YES;
    self.oldPasswordBack.layer.cornerRadius = kCornerRadius;
    self.NewPasswrodBack.layer.masksToBounds = YES;
    self.NewPasswrodBack.layer.cornerRadius = kCornerRadius;
    self.cancelButton.layer.masksToBounds = YES;
    self.cancelButton.layer.cornerRadius = kCornerRadius;
    self.sureChangeButton.layer.masksToBounds = YES;
    self.sureChangeButton.layer.cornerRadius = kCornerRadius;
    self.userName.text = [Shoppersmanager manager].userNameString;
    
}

#pragma mark -取消按钮
- (IBAction)cancelButtonClick:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(cancelButtonClick)]) {
        
        [self.delegate cancelButtonClick];
    }
    
}


#pragma amrk -确认修改按钮
- (IBAction)sureChangeButtonClick:(UIButton *)sender {
    
    [self.view endEditing:YES];
    if ([BaseViewController isBlankString:self.userName.text]) {
        
        [self ErrorMBProgressView:@"账户名不能为空"];
    }
    else if ([BaseViewController isBlankString:self.oldPassWord.text])
    {
        [self ErrorMBProgressView:@"旧密码不能为空"];
    }
    else if ([BaseViewController isBlankString:self.NewPassWord.text])
    {
        [self ErrorMBProgressView:@"新密码不能为空"];
    }
    
    [self CreateMBProgressHUDLoding];
    ModifyPasswordRequest *modify = [[ModifyPasswordRequest alloc]init];
    modify.oldPassword = self.oldPassWord.text;
    modify.fnewPassword = self.NewPassWord.text;
    modify.employeeId = [Shoppersmanager manager].Shoppers.employee.fid;
    
    //修改密码
    WS(weakSelf);
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(MODIFYPASSWORD) WithCallClass:weakSelf WithRequestType:0 WithParameter:modify WithReturnValueBlock:^(id returnValue) {
        
        [weakSelf RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            //保存最新的账号信息
            [Shoppersmanager manager].passWordString = weakSelf.NewPassWord.text;
            [weakSelf SuccessMBProgressView:returnValue[@"message"]];
            if ([weakSelf.delegate respondsToSelector:@selector(cancelButtonClick)]) {
                
                [weakSelf.delegate cancelButtonClick];
            }
            
        }else
        {
            [weakSelf ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
        [weakSelf RemoveMBProgressHUDLoding];
        [weakSelf ErrorMBProgressView:@"无网络"];
        
    } WithFailureBlock:^(id error) {
        
        NSLog(@"%@",error);
    }];
    
    
}




/*
#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
