//
//  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]) {
        
        [XBLoadingView showHUDViewWithText:@"账户名不能为空"];
    }
    else if ([BaseViewController isBlankString:self.oldPassWord.text])
    {
        [XBLoadingView showHUDViewWithText:@"旧密码不能为空"];
    }
    else if ([BaseViewController isBlankString:self.NewPassWord.text])
    {
        [XBLoadingView showHUDViewWithText:@"新密码不能为空"];
    }
    
    [XBLoadingView showHUDViewWithDefault];
    ModifyPasswordRequest *modify = [[ModifyPasswordRequest alloc]init];
    modify.oldPassword = self.oldPassWord.text;
    modify.fnewPassword = self.NewPassWord.text;
    modify.employeeId = [Shoppersmanager manager].shoppers.employee.fid;
    
    //修改密码
    WS(weakSelf);
    [HTTP networkRequestWithURL:SERVERREQUESTURL(MODIFYPASSWORD)  withRequestType:ZERO withParameter:modify withReturnValueBlock:^(id returnValue) {
        
        [XBLoadingView hideHUDViewWithDefault];
        if (RESULT(returnValue)) {
            //保存最新的账号信息
            [Shoppersmanager manager].passWordString = weakSelf.NewPassWord.text;
            if ([weakSelf.delegate respondsToSelector:@selector(cancelButtonClick)]) {
                [weakSelf.delegate cancelButtonClick];
            }
        }else{
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
        }
    }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
