435 lines
15 KiB
Objective-C
435 lines
15 KiB
Objective-C
//
|
|
// XPLoginVerifBindPhoneViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/9/18.
|
|
//
|
|
|
|
#import "XPLoginVerifBindPhoneViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#import "XPConstant.h"
|
|
#import "XPMacro.h"
|
|
#import "UIImage+Utils.h"
|
|
#import "CountDownHelper.h"
|
|
///Model
|
|
#import "UserInfoModel.h"
|
|
///P
|
|
#import "XPLoginVerifBindPhoneProtocol.h"
|
|
#import "XPLoginVerifBindPhonePresenter.h"
|
|
///VC
|
|
#import "LoginBindPhoneViewController.h"
|
|
#import "XPMineSettingViewController.h"
|
|
///View
|
|
#import "XPLoginBindSuccessView.h"
|
|
|
|
@interface XPLoginVerifBindPhoneViewController ()<XPLoginVerifBindPhoneProtocol, CountDownHelperDelegate>
|
|
@property (nonatomic, strong) UIView *containerView;
|
|
@property (nonatomic, strong) UILabel *areaLabel;
|
|
@property (nonatomic, strong) UIButton *countryBtn;
|
|
@property (nonatomic, strong) UIView *areaLineView;
|
|
|
|
@property (nonatomic, strong) UIView *phoneLineView;
|
|
@property (nonatomic, strong) UIView *authLineView;
|
|
@property (nonatomic, strong) UILabel *areaCodeLabel;
|
|
|
|
@property (nonatomic, strong) UIButton *authCodeBtn;
|
|
@property (nonatomic, strong) UITextField *phoneNumTextField;
|
|
@property (nonatomic, strong) UITextField *authCodeTextField;
|
|
|
|
@property (nonatomic, strong) UIButton *confirmBtn; // 确认按钮
|
|
|
|
@property (nonatomic, strong) UILabel *tipsLabel; // 手机号丢失
|
|
@property (nonatomic, assign) BOOL isResetPhone; // 重新绑定手机
|
|
@end
|
|
|
|
@implementation XPLoginVerifBindPhoneViewController
|
|
|
|
- (void)dealloc {
|
|
[[CountDownHelper shareHelper] stopCountDown];
|
|
}
|
|
|
|
- (XPLoginVerifBindPhonePresenter *)createPresenter {
|
|
return [[XPLoginVerifBindPhonePresenter alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
[self setConfigs];
|
|
[self setEvents];
|
|
}
|
|
|
|
- (void)viewDidDisappear:(BOOL)animated {
|
|
[super viewDidDisappear:animated];
|
|
[[CountDownHelper shareHelper] stopCountDown];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[CountDownHelper shareHelper].delegate = self;
|
|
[self.view addSubview:self.containerView];
|
|
[self.containerView addSubview:self.areaLabel];
|
|
[self.containerView addSubview:self.countryBtn];
|
|
|
|
[self.containerView addSubview:self.areaLineView];
|
|
[self.containerView addSubview:self.areaCodeLabel];
|
|
[self.containerView addSubview:self.phoneNumTextField];
|
|
[self.containerView addSubview:self.phoneLineView];
|
|
|
|
[self.containerView addSubview:self.authCodeBtn];
|
|
[self.containerView addSubview:self.authCodeTextField];
|
|
[self.containerView addSubview:self.authLineView];
|
|
|
|
[self.containerView addSubview:self.confirmBtn];
|
|
[self.containerView addSubview:self.tipsLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(0);
|
|
make.left.right.bottom.mas_equalTo(0);
|
|
}];
|
|
|
|
[self.areaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(32);
|
|
make.top.mas_equalTo(20);
|
|
}];
|
|
|
|
[self.countryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(-32);
|
|
make.centerY.mas_equalTo(self.areaLabel);
|
|
}];
|
|
|
|
[self.areaLineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.areaLabel.mas_bottom).offset(18);
|
|
make.left.right.mas_equalTo(0).inset(32);
|
|
make.height.mas_equalTo(1);
|
|
}];
|
|
|
|
[self.areaCodeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.areaLineView.mas_bottom).offset(18);
|
|
make.left.mas_equalTo(self.areaLabel);
|
|
}];
|
|
|
|
[self.phoneNumTextField mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(80);
|
|
make.centerY.mas_equalTo(self.areaCodeLabel);
|
|
make.right.mas_equalTo(self.authCodeBtn.mas_left).offset(-20);
|
|
}];
|
|
|
|
[self.authCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(-32);
|
|
make.centerY.mas_equalTo(self.areaCodeLabel);
|
|
}];
|
|
|
|
[self.phoneLineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.height.mas_equalTo(self.areaLineView);
|
|
make.top.mas_equalTo(self.areaCodeLabel.mas_bottom).offset(18);
|
|
}];
|
|
|
|
[self.authCodeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(0).inset(32);
|
|
make.height.mas_equalTo(48);
|
|
make.top.mas_equalTo(self.phoneLineView.mas_bottom);
|
|
}];
|
|
|
|
[self.authLineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.left.right.mas_equalTo(self.areaLineView);
|
|
make.top.mas_equalTo(self.authCodeTextField.mas_bottom);
|
|
}];
|
|
|
|
[self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(0).inset(32);
|
|
make.top.mas_equalTo(self.authLineView.mas_bottom).offset(70);
|
|
make.height.mas_equalTo(45);
|
|
}];
|
|
|
|
[self.tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.confirmBtn.mas_bottom).offset(36);
|
|
make.centerX.mas_equalTo(0);
|
|
}];
|
|
}
|
|
#pragma mark -配置
|
|
- (void)setConfigs {
|
|
switch (self.bindingPhoneNumType) {
|
|
case XPBindingPhoneNumTypeEdit:{
|
|
self.navigationItem.title = @"更改绑定手机";
|
|
}
|
|
break;
|
|
case XPBindingPhoneNumTypeNormal:{
|
|
self.navigationItem.title = @"绑定手机号";
|
|
}
|
|
break;
|
|
case XPBindingPhoneNumTypeConfirm:{
|
|
self.tipsLabel.hidden = NO;
|
|
self.navigationItem.title = @"验证已绑定的手机号码";
|
|
[self.confirmBtn setTitle:@"验证" forState:UIControlStateNormal];
|
|
if (self.userInfo.isBindPhone) {
|
|
self.phoneNumTextField.enabled = NO;
|
|
self.phoneNumTextField.text = self.userInfo.phone;
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
RAC(self.confirmBtn,enabled) = [RACSignal combineLatest:@[self.phoneNumTextField.rac_textSignal,self.authCodeTextField.rac_textSignal] reduce:^(NSString *phone,NSString *code){
|
|
return @(phone.length == 11 && code.length == 5);
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
#pragma mark 交互事件
|
|
- (void)setEvents {
|
|
@weakify(self)
|
|
// 获取验证码点击事件
|
|
[[[self.authCodeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] filter:^BOOL(__kindof UIControl * _Nullable value) {
|
|
// 获取验证码
|
|
if (self.phoneNumTextField.text.length == 0) {
|
|
[self showErrorToast:@"手机号码不能为空"];
|
|
return NO;
|
|
}else if (self.phoneNumTextField.text.length < 11) {
|
|
[self showErrorToast:@"请输入正确手机号码"];
|
|
return NO;
|
|
}else {
|
|
return YES;
|
|
}
|
|
}] subscribeNext:^(id _Nullable x) {
|
|
@strongify(self);
|
|
[self.presenter phoneSmsCode:self.phoneNumTextField.text type:self.bindingPhoneNumType == XPBindingPhoneNumTypeConfirm ? GetSmsType_Unbind_Phone : GetSmsType_Bind_Phone];
|
|
}];
|
|
|
|
|
|
// 绑定和验证
|
|
[[[self.confirmBtn rac_signalForControlEvents:UIControlEventTouchUpInside] filter:^BOOL(__kindof UIControl * _Nullable value) {
|
|
@strongify(self)
|
|
// 确认绑定手机号
|
|
if (self.phoneNumTextField.text.length == 0) {
|
|
[self showErrorToast:@"手机号码不能为空"];
|
|
return NO;
|
|
}else if (self.authCodeTextField.text.length == 0) {
|
|
[self showErrorToast:@"验证码不能为空"];
|
|
return NO;
|
|
}else {
|
|
return YES;
|
|
}
|
|
}] subscribeNext:^(id _Nullable x) {
|
|
@strongify(self)
|
|
if (self.bindingPhoneNumType == XPBindingPhoneNumTypeConfirm) {
|
|
[self.presenter checkMoblieCodeWithMoblie:self.phoneNumTextField.text code:self.authCodeTextField.text];
|
|
} else {
|
|
[self.presenter bindkMoblieCodeWithMoblie:self.phoneNumTextField.text code:self.authCodeTextField.text];
|
|
}
|
|
} error:^(NSError * _Nullable error) {
|
|
|
|
}];
|
|
}
|
|
|
|
#pragma mark - XPLoginVerifBindPhoneProtocol
|
|
- (void)phoneSmsCodeSuccess {
|
|
self.authCodeBtn.enabled = NO;
|
|
[self showSuccessToast:@"验证码发送成功"];
|
|
[[CountDownHelper shareHelper] openCountdownWithTime:60];
|
|
}
|
|
|
|
- (void)checkMoblieCodeWithMoblieSuccess {
|
|
[self showSuccessToast:@"验证成功"];
|
|
[[CountDownHelper shareHelper] stopCountDown];
|
|
XPLoginVerifBindPhoneViewController *vc = [[XPLoginVerifBindPhoneViewController alloc] init];
|
|
vc.bindingPhoneNumType = XPBindingPhoneNumTypeEdit;
|
|
vc.userInfo = self.userInfo;
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}
|
|
|
|
- (void)bindMoblieCodeWithMoblieSuccess {
|
|
[[CountDownHelper shareHelper] stopCountDown];
|
|
// 修改绑定信息
|
|
if (self.bindingPhoneNumType == XPBindingPhoneNumTypeEdit) {
|
|
@weakify(self);
|
|
[XPLoginBindSuccessView showBindSuccessViewWithHandler:^{
|
|
@strongify(self);
|
|
// 返回设置页面
|
|
__block __kindof UIViewController *vc;
|
|
[self.navigationController.childViewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if ([obj isKindOfClass:[XPMineSettingViewController class]]) {
|
|
vc = obj; // 导航控制器中有设置VC
|
|
}
|
|
}];
|
|
|
|
if ([self.navigationController.childViewControllers containsObject:vc]) {
|
|
[self.navigationController popToViewController:vc animated:YES];
|
|
} else {
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
}];
|
|
} else if (self.bindingPhoneNumType == XPBindingPhoneNumTypeNormal) {
|
|
@weakify(self);
|
|
[XPLoginBindSuccessView showBindSuccessViewWithHandler:^{
|
|
@strongify(self);
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}];
|
|
}
|
|
self.confirmBtn.enabled = YES; // 打开交互
|
|
}
|
|
|
|
|
|
#pragma mark - CountDownHelperDelegate
|
|
///倒计时进行中
|
|
- (void)onCountdownOpen:(int)time {
|
|
[self.authCodeBtn setTitle:[NSString stringWithFormat:@"%ds后重试", time] forState:UIControlStateDisabled];
|
|
}
|
|
///倒计时结束
|
|
- (void)onCountdownFinish {
|
|
self.authCodeBtn.enabled= YES;
|
|
[self.authCodeBtn setTitle:@"重新发送" forState:UIControlStateNormal];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (UIView *)containerView{
|
|
if (!_containerView) {
|
|
_containerView = [[UIView alloc] init];
|
|
_containerView.backgroundColor = [ThemeColor appBackgroundColor];
|
|
}
|
|
return _containerView;
|
|
}
|
|
|
|
- (UILabel *)areaLabel{
|
|
if (!_areaLabel) {
|
|
_areaLabel = [[UILabel alloc] init];
|
|
_areaLabel.text = @"国家和地区";
|
|
_areaLabel.textColor = [ThemeColor secondTextColor];
|
|
_areaLabel.font = [UIFont systemFontOfSize:14.f];
|
|
_areaLabel.adjustsFontSizeToFitWidth = YES;
|
|
}
|
|
return _areaLabel;
|
|
}
|
|
|
|
- (UILabel *)areaCodeLabel{
|
|
if (!_areaCodeLabel) {
|
|
_areaCodeLabel = [[UILabel alloc] init];
|
|
_areaCodeLabel.text = @"+86";
|
|
_areaCodeLabel.textColor = [ThemeColor secondTextColor];
|
|
_areaCodeLabel.font = [UIFont systemFontOfSize:14.f];
|
|
_areaCodeLabel.adjustsFontSizeToFitWidth = YES;
|
|
}
|
|
return _areaCodeLabel;
|
|
}
|
|
|
|
- (UIButton *)countryBtn {
|
|
if (!_countryBtn) {
|
|
_countryBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_countryBtn setTitle:@"中国" forState:UIControlStateNormal];
|
|
[_countryBtn setImage:[UIImage imageNamed:@"mine_item_arrow"] forState:UIControlStateNormal];
|
|
_countryBtn.transform = CGAffineTransformMakeScale(-1.0, 1.0);
|
|
_countryBtn.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0);
|
|
_countryBtn.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0);
|
|
_countryBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
|
|
[_countryBtn setTitleColor:[ThemeColor secondTextColor] forState:UIControlStateNormal];
|
|
[_countryBtn.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
|
|
}
|
|
return _countryBtn;
|
|
}
|
|
|
|
- (UIButton *)confirmBtn {
|
|
if (!_confirmBtn) {
|
|
_confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_confirmBtn setTitle:@"绑定" forState:UIControlStateNormal];
|
|
[_confirmBtn setTitleColor:[ThemeColor confirmButtonTextColor] forState:UIControlStateNormal];
|
|
[_confirmBtn setTitleColor:[ThemeColor disableButtonTextColor] forState:UIControlStateDisabled];
|
|
[_confirmBtn.titleLabel setFont:[UIFont fontWithName:@"PingFang-SC-Medium" size:18]];
|
|
_confirmBtn.layer.cornerRadius = 22.5f;
|
|
_confirmBtn.layer.masksToBounds = YES;
|
|
_confirmBtn.enabled = NO;
|
|
[_confirmBtn setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor], [ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
|
|
[_confirmBtn setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor disableButtonColor], [ThemeColor disableButtonColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateDisabled];
|
|
}
|
|
return _confirmBtn;
|
|
}
|
|
|
|
- (UIButton *)authCodeBtn {
|
|
if (!_authCodeBtn) {
|
|
_authCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_authCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
|
|
[_authCodeBtn setTitleColor:[ThemeColor appMainColor] forState:UIControlStateNormal];
|
|
[_authCodeBtn setTitleColor:[ThemeColor secondTextColor] forState:UIControlStateDisabled];
|
|
[_authCodeBtn.titleLabel setFont:[UIFont systemFontOfSize:12.f]];
|
|
}
|
|
return _authCodeBtn;
|
|
}
|
|
|
|
- (UITextField *)phoneNumTextField {
|
|
if (!_phoneNumTextField) {
|
|
_phoneNumTextField = [[UITextField alloc] init];
|
|
_phoneNumTextField.textColor = [ThemeColor mainTextColor];
|
|
_phoneNumTextField.font = [UIFont systemFontOfSize:14.f];
|
|
_phoneNumTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入手机号"attributes:@{NSForegroundColorAttributeName: [ThemeColor secondTextColor]}];
|
|
_phoneNumTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
|
|
_phoneNumTextField.borderStyle = UITextBorderStyleNone;
|
|
_phoneNumTextField.keyboardType = UIKeyboardTypeNumberPad;
|
|
_phoneNumTextField.tintColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _phoneNumTextField;
|
|
}
|
|
|
|
|
|
- (UITextField *)authCodeTextField {
|
|
if (!_authCodeTextField) {
|
|
_authCodeTextField = [[UITextField alloc] init];
|
|
_authCodeTextField.textColor = [ThemeColor mainTextColor];
|
|
_authCodeTextField.font = [UIFont systemFontOfSize:14.f];
|
|
_authCodeTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入验证码"attributes:@{NSForegroundColorAttributeName: [ThemeColor secondTextColor]}];
|
|
_authCodeTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
|
|
_authCodeTextField.borderStyle = UITextBorderStyleNone;
|
|
_authCodeTextField.keyboardType = UIKeyboardTypeNumberPad;
|
|
_authCodeTextField.tintColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _authCodeTextField;
|
|
}
|
|
|
|
- (UIView *)areaLineView {
|
|
if (!_areaLineView) {
|
|
_areaLineView = [[UIView alloc] init];
|
|
_areaLineView.backgroundColor = [ThemeColor dividerColor];
|
|
}
|
|
return _areaLineView;
|
|
}
|
|
|
|
- (UIView *)phoneLineView {
|
|
if (!_phoneLineView) {
|
|
_phoneLineView = [[UIView alloc] init];
|
|
_phoneLineView.backgroundColor = [ThemeColor dividerColor];
|
|
}
|
|
return _phoneLineView;
|
|
}
|
|
|
|
- (UIView *)authLineView {
|
|
if (!_authLineView) {
|
|
_authLineView = [[UIView alloc] init];
|
|
_authLineView.backgroundColor = [ThemeColor dividerColor];
|
|
}
|
|
return _authLineView;
|
|
}
|
|
|
|
- (UILabel *)tipsLabel{
|
|
if (!_tipsLabel) {
|
|
_tipsLabel = [[UILabel alloc] init];
|
|
_tipsLabel.text = [NSString stringWithFormat:@"如果您的手机号已丢失\n请咨询客服"];
|
|
_tipsLabel.textColor = [ThemeColor textThirdColor];
|
|
_tipsLabel.font = [UIFont systemFontOfSize:14.f];
|
|
_tipsLabel.adjustsFontSizeToFitWidth = YES;
|
|
_tipsLabel.numberOfLines = 0;
|
|
_tipsLabel.textAlignment = NSTextAlignmentCenter;
|
|
_tipsLabel.hidden = YES;
|
|
}
|
|
return _tipsLabel;
|
|
}
|
|
|
|
@end
|