|
| 1 | +// |
| 2 | +// SettingPhoneViewController.m |
| 3 | +// Coding_iOS |
| 4 | +// |
| 5 | +// Created by Ease on 15/12/28. |
| 6 | +// Copyright © 2015年 Coding. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "SettingPhoneViewController.h" |
| 10 | +#import "Input_OnlyText_Cell.h" |
| 11 | +#import "TPKeyboardAvoidingTableView.h" |
| 12 | +#import "Coding_NetAPIManager.h" |
| 13 | +#import "Login.h" |
| 14 | + |
| 15 | +@interface SettingPhoneViewController ()<UITableViewDataSource, UITableViewDelegate> |
| 16 | +@property (strong, nonatomic) TPKeyboardAvoidingTableView *myTableView; |
| 17 | +@property (strong, nonatomic) NSString *phone, *code; |
| 18 | +@property (strong, nonatomic) NSString *phoneCodeCellIdentifier; |
| 19 | + |
| 20 | +@end |
| 21 | + |
| 22 | +@implementation SettingPhoneViewController |
| 23 | + |
| 24 | +- (void)viewDidLoad { |
| 25 | + [super viewDidLoad]; |
| 26 | + // Do any additional setup after loading the view. |
| 27 | + self.title = @"绑定手机号码"; |
| 28 | + self.phone = [Login curLoginUser].phone; |
| 29 | + |
| 30 | + // 添加myTableView |
| 31 | + self.phoneCodeCellIdentifier = [Input_OnlyText_Cell randomCellIdentifierOfPhoneCodeType]; |
| 32 | + _myTableView = ({ |
| 33 | + TPKeyboardAvoidingTableView *tableView = [[TPKeyboardAvoidingTableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; |
| 34 | + tableView.backgroundColor = kColorTableSectionBg; |
| 35 | + tableView.dataSource = self; |
| 36 | + tableView.delegate = self; |
| 37 | + tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
| 38 | + [tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell_Text]; |
| 39 | + [tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:self.phoneCodeCellIdentifier]; |
| 40 | + [self.view addSubview:tableView]; |
| 41 | + [tableView mas_makeConstraints:^(MASConstraintMaker *make) { |
| 42 | + make.edges.equalTo(self.view); |
| 43 | + }]; |
| 44 | + tableView; |
| 45 | + }); |
| 46 | + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(doneBtnClicked:)]; |
| 47 | + |
| 48 | +} |
| 49 | +#pragma mark TableM |
| 50 | + |
| 51 | +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ |
| 52 | + return 2; |
| 53 | +} |
| 54 | +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 55 | + Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier:indexPath.row == 0? self.phoneCodeCellIdentifier: kCellIdentifier_Input_OnlyText_Cell_Text forIndexPath:indexPath]; |
| 56 | + |
| 57 | + __weak typeof(self) weakSelf = self; |
| 58 | + if (indexPath.row == 0) { |
| 59 | + cell.textField.keyboardType = UIKeyboardTypeNumberPad; |
| 60 | + [cell setPlaceholder:@" 手机号码" value:self.phone]; |
| 61 | + cell.textValueChangedBlock = ^(NSString *valueStr){ |
| 62 | + weakSelf.phone = valueStr; |
| 63 | + }; |
| 64 | + cell.phoneCodeBtnClckedBlock = ^(PhoneCodeButton *btn){ |
| 65 | + [weakSelf phoneCodeBtnClicked:btn]; |
| 66 | + }; |
| 67 | + }else{ |
| 68 | + cell.textField.keyboardType = UIKeyboardTypeNumberPad; |
| 69 | + [cell setPlaceholder:@" 手机验证码" value:self.code]; |
| 70 | + cell.textValueChangedBlock = ^(NSString *valueStr){ |
| 71 | + weakSelf.code = valueStr; |
| 72 | + }; |
| 73 | + } |
| 74 | + [tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth]; |
| 75 | + return cell; |
| 76 | +} |
| 77 | +- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ |
| 78 | + UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 20)]; |
| 79 | + headerView.backgroundColor = kColorTableSectionBg; |
| 80 | + return headerView; |
| 81 | +} |
| 82 | + |
| 83 | +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ |
| 84 | + return 20.0; |
| 85 | +} |
| 86 | + |
| 87 | +- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ |
| 88 | + return 0.5; |
| 89 | +} |
| 90 | + |
| 91 | +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 92 | + [tableView deselectRowAtIndexPath:indexPath animated:YES]; |
| 93 | +} |
| 94 | + |
| 95 | +#pragma mark CodeBtn |
| 96 | +- (void)phoneCodeBtnClicked:(PhoneCodeButton *)sender{ |
| 97 | + if (![_phone isPhoneNo]) { |
| 98 | + [NSObject showHudTipStr:@"手机号码格式有误"]; |
| 99 | + return; |
| 100 | + } |
| 101 | + sender.enabled = NO; |
| 102 | + [[Coding_NetAPIManager sharedManager] request_GeneratePhoneCodeToResetPhone:_phone block:^(id data, NSError *error) { |
| 103 | + if (data) { |
| 104 | + [sender startUpTimer]; |
| 105 | + }else{ |
| 106 | + [sender invalidateTimer]; |
| 107 | + } |
| 108 | + }]; |
| 109 | +} |
| 110 | + |
| 111 | +#pragma mark DoneBtn Clicked |
| 112 | +- (void)doneBtnClicked:(id)sender{ |
| 113 | + NSString *tipStr; |
| 114 | + if (![_phone isPhoneNo]) { |
| 115 | + tipStr = @"手机号码格式有误"; |
| 116 | + }else if (_code.length <= 0){ |
| 117 | + tipStr = @"请填写手机验证码"; |
| 118 | + } |
| 119 | + if (tipStr.length > 0) { |
| 120 | + [NSObject showHudTipStr:tipStr]; |
| 121 | + return; |
| 122 | + } |
| 123 | + __weak typeof(self) weakSelf = self; |
| 124 | + [[Coding_NetAPIManager sharedManager] request_ResetPhone:_phone code:_code andBlock:^(id data, NSError *error) { |
| 125 | + weakSelf.navigationItem.rightBarButtonItem.enabled = YES; |
| 126 | + if (data) { |
| 127 | + [NSObject showHudTipStr:@"手机号码绑定成功"]; |
| 128 | + [weakSelf.navigationController popViewControllerAnimated:YES]; |
| 129 | + } |
| 130 | + }]; |
| 131 | +} |
| 132 | + |
| 133 | +@end |
0 commit comments