//
//  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];
    // Do any additional setup after loading the view from its nib.
    
     [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 (self.userName.text.length == 0) {
        
        [self ErrorMBProgressView:@"账户名不能为空"];
    }
    else if (self.oldPassWord.text.length == 0)
    {
        [self ErrorMBProgressView:@"旧密码不能为空"];
    }
    else if (self.NewPassWord.text.length == 0)
    {
        [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;
    
    //修改密码
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/employee/modifyPassword"] WithRequestType:0 WithParameter:modify WithReturnValueBlock:^(id returnValue) {
        
        [self RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            //保存最新的账号信息
            [Shoppersmanager manager].passWordString = self.NewPassWord.text;
            [self SuccessMBProgressView:returnValue[@"message"]];
            if ([self.delegate respondsToSelector:@selector(cancelButtonClick)]) {
                
                [self.delegate cancelButtonClick];
            }
            
        }else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
        
        
    } 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
