cdts/xdts-ios 3/TreeHole/Code/Features/Settings/ViewController/ChangePhoneViewController.m

117 lines
4.2 KiB
Mathematica
Raw Normal View History

2023-07-27 09:20:00 +08:00
//
// ChangePhoneViewController.m
// Youth
//
// Created by mambaxie on 2022/1/2.
//
#import "ChangePhoneViewController.h"
#import "PYGetSmsCodeButton.h"
#import "GetSmsCodeViewController.h"
@interface ChangePhoneViewController ()
@property (nonatomic, strong) PYThemeTextField *phoneFiled;
@property (nonatomic, strong) PYThemeTextField *smsCodeFiled;
@property (nonatomic, strong) PYThemeButton *okButton;
@end
@implementation ChangePhoneViewController
- (BOOL)mt_nagationBarTransparent {
return NO;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"修改手机号";
self.view.backgroundColor = BG_COLOR;
PYImageView *iconView = [[PYImageView alloc] init];
iconView.image = ImageNamed(@"TH_phone_icon_logo");
iconView.size = CGSizeMake(FIX_SIZE(140), FIX_SIZE(44));
iconView.y = FIX_SIZE(53) + NAVIGATION_BAR_HEIGHT;
iconView.height = 0.0;
iconView.centerX = SCREEN_WIDTH * 0.5;
[self.view addSubview:iconView];
UILabel *tipsLabel = [[UILabel alloc] init];
tipsLabel.font = MT_FONT_REGULAR_SIZE(13);
tipsLabel.textColor = [UIColor whiteColor];
tipsLabel.text = [NSString stringWithFormat:@"你的手机号: %@", [UserService currentUser].phone];
[tipsLabel sizeToFit];
tipsLabel.centerX = SCREEN_WIDTH * 0.5;
tipsLabel.y = iconView.y;
[self.view addSubview:tipsLabel];
WeakSelf(self);
PYThemeTextField *phoneFiled = [PYThemeTextField fieldWithPlaceholder:@"新手机号" maxLength:11];
phoneFiled.y = tipsLabel.bottom + FIX_SIZE(43);
phoneFiled.textField.keyboardType = UIKeyboardTypeNumberPad;
phoneFiled.textDidChangeAction = ^(PYThemeTextField * _Nonnull textFiled) {
[weakself updateOkButton];
};
[self.view addSubview:phoneFiled];
self.phoneFiled = phoneFiled;
PYThemeTextField *smsCodeFiled = [PYThemeTextField fieldWithPlaceholder:@"验证码" maxLength:6];
smsCodeFiled.y = phoneFiled.bottom + FIX_SIZE(10);
smsCodeFiled.textField.keyboardType = UIKeyboardTypeNumberPad;
smsCodeFiled.textDidChangeAction = ^(PYThemeTextField * _Nonnull textFiled) {
[weakself updateOkButton];
};
[self.view addSubview:smsCodeFiled];
self.smsCodeFiled = smsCodeFiled;
PYGetSmsCodeButton *codeButton = [PYGetSmsCodeButton smsCodeButton];
[codeButton setTitleColor:THEME_COLOR forState:UIControlStateNormal];
codeButton.titleLabel.font = MT_FONT_REGULAR_SIZE(11);
codeButton.backgroundColor = [UIColor clearColor];
codeButton.width = FIX_SIZE(100);
codeButton.getSmsWithPhoneBlock = ^NSString * _Nonnull{
return weakself.phoneFiled.text;
};
codeButton.right = smsCodeFiled.width;
codeButton.centerY = smsCodeFiled.height * 0.5;
[smsCodeFiled addSubview:codeButton];
PYThemeButton *okButton = [PYThemeButton middleButtonWithTitle:@"确认修改" action:^(UIButton * _Nonnull button) {
NSString *phone = weakself.phoneFiled.text ?: @"";
NSString *code = weakself.smsCodeFiled.text ?: @"";
[SVProgressHUD showWithStatus:nil];
[UserService modifyPhoneWhshCode:code newPhone:phone completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
[SVProgressHUD showSuccessWithStatus:@"修改成功"];
[UserService currentUser].phone = phone;
[weakself.navigationController popViewControllerAnimated:YES];
}
}];
// [UserService updateUserToRemoteWithParams:@{
// @"phone": phone
// } completion:^(id _Nullable rsp, NSError * _Nullable error) {
// if (!error) {
// [UserService currentUser].phone = phone;
// [weakself.navigationController popViewControllerAnimated:YES];
// }
// }];
}];
okButton.y = FIX_SIZE(15) + smsCodeFiled.bottom;
self.okButton = okButton;
okButton.enabled = NO;
[self.view addSubview:okButton];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.phoneFiled.textField becomeFirstResponder];
}
- (void)updateOkButton {
self.okButton.enabled = self.phoneFiled.text.length == 11 && self.smsCodeFiled.text.length == SMSCodeNumberCount;
}
@end