1111#import " TPKeyboardAvoidingTableView.h"
1212#import " Coding_NetAPIManager.h"
1313#import " Login.h"
14+ #import " CountryCodeListViewController.h"
1415
1516@interface SettingPhoneViewController ()<UITableViewDataSource, UITableViewDelegate>
1617@property (strong , nonatomic ) TPKeyboardAvoidingTableView *myTableView;
17- @property (strong , nonatomic ) NSString *phone, *code;
18+ @property (strong , nonatomic ) NSString *phone, *code, *phone_country_code, *country, *verifyStr ;
1819@property (strong , nonatomic ) NSString *phoneCodeCellIdentifier;
19-
20+ @property ( assign , nonatomic ) VerifyType verifyType;
2021@end
2122
2223@implementation SettingPhoneViewController
@@ -26,6 +27,8 @@ - (void)viewDidLoad {
2627 // Do any additional setup after loading the view.
2728 self.title = @" 绑定手机号码" ;
2829 self.phone = [Login curLoginUser ].phone ;
30+ self.country = [Login curLoginUser ].country ;
31+ self.phone_country_code = [Login curLoginUser ].phone_country_code ;
2932
3033 // 添加myTableView
3134 self.phoneCodeCellIdentifier = [Input_OnlyText_Cell randomCellIdentifierOfPhoneCodeType ];
@@ -35,7 +38,9 @@ - (void)viewDidLoad {
3538 tableView.dataSource = self;
3639 tableView.delegate = self;
3740 tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
41+ [tableView registerClass: [Input_OnlyText_Cell class ] forCellReuseIdentifier: kCellIdentifier_Input_OnlyText_Cell_Phone ];
3842 [tableView registerClass: [Input_OnlyText_Cell class ] forCellReuseIdentifier: kCellIdentifier_Input_OnlyText_Cell_Text ];
43+ [tableView registerClass: [Input_OnlyText_Cell class ] forCellReuseIdentifier: kCellIdentifier_Input_OnlyText_Cell_Password ];
3944 [tableView registerClass: [Input_OnlyText_Cell class ] forCellReuseIdentifier: self .phoneCodeCellIdentifier];
4045 [self .view addSubview: tableView];
4146 [tableView mas_makeConstraints: ^(MASConstraintMaker *make) {
@@ -45,14 +50,25 @@ - (void)viewDidLoad {
4550 });
4651 self.navigationItem .rightBarButtonItem = [[UIBarButtonItem alloc ] initWithTitle: @" 完成" style: UIBarButtonItemStylePlain target: self action: @selector (doneBtnClicked: )];
4752
53+ self.verifyType = VerifyTypePassword;
54+ [[Coding_NetAPIManager sharedManager ] request_VerifyTypeWithBlock: ^(VerifyType type, NSError *error) {
55+ if (!error) {
56+ self.verifyType = type;
57+ [self .myTableView reloadData ];
58+ }
59+ }];
4860}
4961#pragma mark TableM
5062
5163- (NSInteger )tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger )section {
52- return 2 ;
64+ return 3 ;
5365}
5466- (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];
67+ NSString *identifier = (indexPath.row == 0 ? kCellIdentifier_Input_OnlyText_Cell_Phone :
68+ indexPath.row == 1 ? self.phoneCodeCellIdentifier :
69+ _verifyType == VerifyTypePassword? kCellIdentifier_Input_OnlyText_Cell_Password :
70+ kCellIdentifier_Input_OnlyText_Cell_Text );
71+ Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier: identifier forIndexPath: indexPath];
5672
5773 __weak typeof (self) weakSelf = self;
5874 if (indexPath.row == 0 ) {
@@ -61,15 +77,24 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
6177 cell.textValueChangedBlock = ^(NSString *valueStr){
6278 weakSelf.phone = valueStr;
6379 };
64- cell.phoneCodeBtnClckedBlock = ^(PhoneCodeButton *btn){
65- [weakSelf phoneCodeBtnClicked: btn];
80+ cell.countryCodeL .text = _phone_country_code;
81+ cell.countryCodeBtnClickedBlock = ^(){
82+ [weakSelf goToCountryCodeVC ];
6683 };
67- }else {
84+ }else if (indexPath. row == 1 ) {
6885 cell.textField .keyboardType = UIKeyboardTypeNumberPad;
6986 [cell setPlaceholder: @" 手机验证码" value: self .code];
7087 cell.textValueChangedBlock = ^(NSString *valueStr){
7188 weakSelf.code = valueStr;
7289 };
90+ cell.phoneCodeBtnClckedBlock = ^(PhoneCodeButton *btn){
91+ [weakSelf phoneCodeBtnClicked: btn];
92+ };
93+ }else {
94+ [cell setPlaceholder: _verifyType == VerifyTypePassword? @" 输入密码" : @" 输入两步验证码" value: _verifyStr];
95+ cell.textValueChangedBlock = ^(NSString *valueStr){
96+ weakSelf.verifyStr = valueStr;
97+ };
7398 }
7499 [tableView addLineforPlainCell: cell forRowAtIndexPath: indexPath withLeftSpace: kPaddingLeftWidth ];
75100 return cell;
@@ -99,7 +124,7 @@ - (void)phoneCodeBtnClicked:(PhoneCodeButton *)sender{
99124 return ;
100125 }
101126 sender.enabled = NO ;
102- [[Coding_NetAPIManager sharedManager ] request_GeneratePhoneCodeToResetPhone: _phone block: ^(id data, NSError *error) {
127+ [[Coding_NetAPIManager sharedManager ] request_GeneratePhoneCodeToResetPhone: _phone phoneCountryCode: _phone_country_code block: ^(id data, NSError *error) {
103128 if (data) {
104129 [NSObject showHudTipStr: @" 验证码发送成功" ];
105130 [sender startUpTimer ];
@@ -116,19 +141,36 @@ - (void)doneBtnClicked:(id)sender{
116141 tipStr = @" 手机号码格式有误" ;
117142 }else if (_code.length <= 0 ){
118143 tipStr = @" 请填写手机验证码" ;
144+ }else if (_verifyStr.length <= 0 ){
145+ tipStr = _verifyType == VerifyTypePassword? @" 请填写密码" : @" 请填写两步验证码" ;
119146 }
120147 if (tipStr.length > 0 ) {
121148 [NSObject showHudTipStr: tipStr];
122149 return ;
123150 }
151+ NSMutableDictionary *params = @{@" phone" : _phone,
152+ @" code" : _code,
153+ @" phoneCountryCode" : _phone_country_code,
154+ @" two_factor_code" : _verifyType == VerifyTypePassword? [_verifyStr sha1Str ]: _verifyStr}.mutableCopy ;
124155 __weak typeof (self) weakSelf = self;
125- [[Coding_NetAPIManager sharedManager ] request_ResetPhone: _phone code: _code andBlock: ^(id data, NSError *error) {
126- weakSelf.navigationItem .rightBarButtonItem .enabled = YES ;
156+ [[CodingNetAPIClient sharedJsonClient ] requestJsonDataWithPath: @" api/account/phone/change" withParams: params withMethodType: Post andBlock: ^(id data, NSError *error) {
127157 if (data) {
128158 [NSObject showHudTipStr: @" 手机号码绑定成功" ];
129159 [weakSelf.navigationController popViewControllerAnimated: YES ];
130160 }
131161 }];
132162}
133163
164+ #pragma mark - VC
165+ - (void )goToCountryCodeVC {
166+ __weak typeof (self) weakSelf = self;
167+ CountryCodeListViewController *vc = [CountryCodeListViewController new ];
168+ vc.selectedBlock = ^(NSDictionary *countryCodeDict){
169+ weakSelf.country = countryCodeDict[@" iso_code" ];
170+ weakSelf.phone_country_code = [NSString stringWithFormat: @" +%@ " , countryCodeDict[@" country_code" ]];
171+ [weakSelf.myTableView reloadData ];
172+ };
173+ [self .navigationController pushViewController: vc animated: YES ];
174+ }
175+
134176@end
0 commit comments