//
//  AddDetailInfoViewController.m
//  ALand
//
//  Created by Z on 16/5/5.
//  Copyright © 2016年 Z. All rights reserved.
//

#import "AddDetailInfoViewController.h"
#import "MyBankClass.h"

@interface AddDetailInfoViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UILabel *labelBankName;
@property (weak, nonatomic) IBOutlet UILabel *labelBankCardID;
@property (weak, nonatomic) IBOutlet UITextField *labelName;
@property (weak, nonatomic) IBOutlet UIButton *btnNext;
@property (weak, nonatomic) IBOutlet UIButton *btnAgree;


@end

@implementation AddDetailInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setDefauts];
    [self machineStrings];
    
    
    // Do any additional setup after loading the view from its nib.
}

//设置默认的一些信息
- (void)setDefauts {
    self.title = @"添加银行卡";
    self.btnNext.enabled = NO;
    self.labelName.delegate = self;
    
}


//对文字进行加工并赋值
- (void)machineStrings {
    self.labelBankName.text = [MyBankClass returnBankName:self.bankCardID];
    self.labelBankCardID.text = [NSString stringWithFormat:@"***************%@",[self.bankCardID substringWithRange:NSMakeRange(self.bankCardID.length - 4, 4)]];
}




//检测下一步是否可以点
- (void)checkNextBtnIsEnabledWithName:(NSString *)name {
    
    if (self.btnAgree.isSelected == YES && name.length > 0) {
        self.btnNext.enabled = YES;
    }else{
        self.btnNext.enabled = NO;
    }
}


#pragma mark *********** UITextFiedDelegate ***********

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *name = [textField.text stringByReplacingCharactersInRange:range withString:string];//变化后的字符串
    
    [self checkNextBtnIsEnabledWithName:name];
    
    return YES;
}

- (BOOL)textFieldShouldClear:(UITextField *)textField {
    self.btnNext.enabled = NO;
    return YES;
}

- (IBAction)actionAgree:(UIButton *)btn {
    self.btnAgree.selected = !self.btnAgree.selected;
    [self checkNextBtnIsEnabledWithName:self.labelName.text];
}




- (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
