|
| 1 | +// |
| 2 | +// Close2FAViewController.m |
| 3 | +// Coding_iOS |
| 4 | +// |
| 5 | +// Created by Ease on 16/3/15. |
| 6 | +// Copyright © 2016年 Coding. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "Close2FAViewController.h" |
| 10 | +#import "Coding_NetAPIManager.h" |
| 11 | +#import "TPKeyboardAvoidingTableView.h" |
| 12 | +#import "Input_OnlyText_Cell.h" |
| 13 | + |
| 14 | +@interface Close2FAViewController ()<UITableViewDataSource, UITableViewDelegate> |
| 15 | +@property (strong, nonatomic) NSString *phone, *phoneCode; |
| 16 | +@property (copy, nonatomic) void (^sucessBlock)(); |
| 17 | + |
| 18 | +@property (strong, nonatomic) TPKeyboardAvoidingTableView *myTableView; |
| 19 | +@property (strong, nonatomic) UIButton *footerBtn; |
| 20 | +@property (strong, nonatomic) NSString *phoneCodeCellIdentifier; |
| 21 | +@end |
| 22 | + |
| 23 | +@implementation Close2FAViewController |
| 24 | ++ (id)vcWithPhone:(NSString *)phone sucessBlock:(void (^)())block{ |
| 25 | + Close2FAViewController *vc = [self new]; |
| 26 | + vc.phone = [phone isPhoneNo]? phone: nil; |
| 27 | + vc.sucessBlock = block; |
| 28 | + return vc; |
| 29 | +} |
| 30 | + |
| 31 | +- (void)viewDidLoad { |
| 32 | + [super viewDidLoad]; |
| 33 | + // Do any additional setup after loading the view. |
| 34 | + self.title = @"关闭两步验证"; |
| 35 | + self.phoneCodeCellIdentifier = [Input_OnlyText_Cell randomCellIdentifierOfPhoneCodeType]; |
| 36 | + |
| 37 | + // 添加myTableView |
| 38 | + _myTableView = ({ |
| 39 | + TPKeyboardAvoidingTableView *tableView = [[TPKeyboardAvoidingTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; |
| 40 | + [tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell_Text]; |
| 41 | + [tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:self.phoneCodeCellIdentifier]; |
| 42 | + tableView.backgroundColor = kColorTableSectionBg; |
| 43 | + tableView.dataSource = self; |
| 44 | + tableView.delegate = self; |
| 45 | + tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
| 46 | + [self.view addSubview:tableView]; |
| 47 | + [tableView mas_makeConstraints:^(MASConstraintMaker *make) { |
| 48 | + make.edges.equalTo(self.view); |
| 49 | + }]; |
| 50 | + tableView; |
| 51 | + }); |
| 52 | + self.myTableView.tableHeaderView = [self customHeaderView]; |
| 53 | + self.myTableView.tableFooterView=[self customFooterView]; |
| 54 | +} |
| 55 | + |
| 56 | +- (void)viewWillAppear:(BOOL)animated{ |
| 57 | + [super viewWillAppear:animated]; |
| 58 | + [self.navigationController setNavigationBarHidden:NO animated:YES]; |
| 59 | +} |
| 60 | + |
| 61 | +#pragma mark - Table view Header Footer |
| 62 | +- (UIView *)customHeaderView{ |
| 63 | + UIView *headerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 100)]; |
| 64 | + headerV.backgroundColor = [UIColor clearColor]; |
| 65 | + UILabel *tipL = [UILabel new]; |
| 66 | + tipL.font = [UIFont systemFontOfSize:14]; |
| 67 | + tipL.textColor = [UIColor colorWithHexString:@"0x999999"]; |
| 68 | + tipL.text = @"关闭两步验证,请先验证您的注册手机"; |
| 69 | + [headerV addSubview:tipL]; |
| 70 | + [tipL mas_makeConstraints:^(MASConstraintMaker *make) { |
| 71 | + make.center.equalTo(headerV); |
| 72 | + }]; |
| 73 | + return headerV; |
| 74 | +} |
| 75 | +- (UIView *)customFooterView{ |
| 76 | + UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 150)]; |
| 77 | + _footerBtn = [UIButton buttonWithStyle:StrapSuccessStyle andTitle:@"关闭两步验证" andFrame:CGRectMake(kLoginPaddingLeftWidth, 20, kScreen_Width-kLoginPaddingLeftWidth*2, 45) target:self action:@selector(footerBtnClicked:)]; |
| 78 | + [footerV addSubview:_footerBtn]; |
| 79 | + RAC(self, footerBtn.enabled) = [RACSignal combineLatest:@[RACObserve(self, phone), |
| 80 | + RACObserve(self, phoneCode)] |
| 81 | + reduce:^id(NSString *phone, NSString *phoneCode){ |
| 82 | + return @([phone isPhoneNo] && phoneCode.length > 0); |
| 83 | + }]; |
| 84 | + return footerV; |
| 85 | +} |
| 86 | +#pragma mark - Table view data source |
| 87 | +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ |
| 88 | + return 2; |
| 89 | +} |
| 90 | + |
| 91 | +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 92 | + NSString *cellIdentifier = indexPath.row == 1? self.phoneCodeCellIdentifier: kCellIdentifier_Input_OnlyText_Cell_Text; |
| 93 | + Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; |
| 94 | + |
| 95 | + __weak typeof(self) weakSelf = self; |
| 96 | + if (indexPath.row == 0) { |
| 97 | + [cell setPlaceholder:@" 手机号" value:self.phone]; |
| 98 | + cell.textField.keyboardType = UIKeyboardTypeNumberPad; |
| 99 | + cell.textValueChangedBlock = ^(NSString *valueStr){ |
| 100 | + weakSelf.phone = valueStr; |
| 101 | + }; |
| 102 | + }else{ |
| 103 | + cell.textField.keyboardType = UIKeyboardTypeNumberPad; |
| 104 | + [cell setPlaceholder:@" 手机验证码" value:self.phoneCode]; |
| 105 | + cell.textValueChangedBlock = ^(NSString *valueStr){ |
| 106 | + weakSelf.phoneCode = valueStr; |
| 107 | + }; |
| 108 | + cell.phoneCodeBtnClckedBlock = ^(PhoneCodeButton *btn){ |
| 109 | + [weakSelf phoneCodeBtnClicked:btn]; |
| 110 | + }; |
| 111 | + } |
| 112 | + [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kLoginPaddingLeftWidth]; |
| 113 | + return cell; |
| 114 | +} |
| 115 | + |
| 116 | +#pragma mark Btn Clicked |
| 117 | +- (void)phoneCodeBtnClicked:(PhoneCodeButton *)sender{ |
| 118 | + if (![_phone isPhoneNo]) { |
| 119 | + [NSObject showHudTipStr:@"手机号码格式有误"]; |
| 120 | + return; |
| 121 | + } |
| 122 | + sender.enabled = NO; |
| 123 | + [[Coding_NetAPIManager sharedManager] post_Close2FAGeneratePhoneCode:self.phone block:^(id data, NSError *error) { |
| 124 | + if (data) { |
| 125 | + [NSObject showHudTipStr:@"验证码发送成功"]; |
| 126 | + [sender startUpTimer]; |
| 127 | + }else{ |
| 128 | + [sender invalidateTimer]; |
| 129 | + } |
| 130 | + }]; |
| 131 | +} |
| 132 | +- (void)footerBtnClicked:(id)sender{ |
| 133 | + [self.footerBtn startQueryAnimate]; |
| 134 | + [[Coding_NetAPIManager sharedManager] post_Close2FAWithPhone:self.phone code:self.phoneCode block:^(id data, NSError *error) { |
| 135 | + [self.footerBtn stopQueryAnimate]; |
| 136 | + if (data) { |
| 137 | + [NSObject showHudTipStr:@"两步验证已关闭"]; |
| 138 | + if (self.sucessBlock) { |
| 139 | + self.sucessBlock(); |
| 140 | + } |
| 141 | + } |
| 142 | + }]; |
| 143 | +} |
| 144 | +@end |
0 commit comments