401 lines
14 KiB
Objective-C
401 lines
14 KiB
Objective-C
//
|
|
// MewLoginVerifBindPhoneViewController.m
|
|
// yinmeng-ios
|
|
//
|
|
// Created by 触海 on 2023/11/22.
|
|
//
|
|
|
|
#import "MewLoginVerifBindPhoneViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
|
///Tool
|
|
#import "MewThemeColor.h"
|
|
#import "MewConstant.h"
|
|
#import "MewMacro.h"
|
|
#import "UIImage+MewUtils.h"
|
|
#import "MewHUDTool.h"
|
|
#import "MEWCountDownHelper.h"
|
|
///Model
|
|
#import "MewUserInfoModel.h"
|
|
///P
|
|
#import "MewLoginVerifBindPhoneProtocol.h"
|
|
#import "MewLoginVerifBindPhonePresenter.h"
|
|
///VC
|
|
#import "MewLoginBindPhoneViewController.h"
|
|
|
|
@interface MewLoginVerifBindPhoneViewController ()<MewLoginVerifBindPhoneProtocol, MEWCountDownHelperDelegate>
|
|
@property (nonatomic, strong) UIView *containerView;
|
|
|
|
@property (nonatomic, strong) UIImageView *bgImageView;
|
|
/// 返回按钮
|
|
@property (nonatomic, strong) UIButton *backButton;
|
|
@property (nonatomic, strong) UILabel *titleLabel;
|
|
|
|
@property (nonatomic, strong) UIView *phoneBgView;
|
|
@property (nonatomic, strong) UILabel *areaCodeLabel;
|
|
@property (nonatomic, strong) UITextField *phoneNumTextField;
|
|
@property (nonatomic, strong) UIButton *authCodeBtn;
|
|
|
|
@property (nonatomic, strong) UIView *authCodeBgView;
|
|
@property (nonatomic, strong) UITextField *authCodeTextField;
|
|
|
|
@property (nonatomic, strong) UIButton *confirmBtn; // 确认按钮
|
|
|
|
@end
|
|
|
|
|
|
@implementation MewLoginVerifBindPhoneViewController
|
|
- (BOOL)mew_isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (void)dealloc {
|
|
[[MEWCountDownHelper shareHelper] mewStopCountDown];
|
|
}
|
|
|
|
- (MewLoginVerifBindPhonePresenter *)createPresenter {
|
|
return [[MewLoginVerifBindPhonePresenter alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self mew_initSubViews];
|
|
[self mew_initSubViewConstraints];
|
|
[self mew_setConfigs];
|
|
[self mew_setEvents];
|
|
}
|
|
|
|
- (void)viewDidDisappear:(BOOL)animated {
|
|
[super viewDidDisappear:animated];
|
|
[[MEWCountDownHelper shareHelper] mewStopCountDown];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)mew_initSubViews {
|
|
[MEWCountDownHelper shareHelper].delegate = self;
|
|
[self.view addSubview:self.containerView];
|
|
[self.containerView addSubview:self.bgImageView];
|
|
[self.containerView addSubview:self.backButton];
|
|
[self.containerView addSubview:self.titleLabel];
|
|
|
|
[self.containerView addSubview:self.phoneBgView];
|
|
[self.phoneBgView addSubview:self.areaCodeLabel];
|
|
[self.phoneBgView addSubview:self.phoneNumTextField];
|
|
[self.phoneBgView addSubview:self.authCodeBtn];
|
|
|
|
[self.containerView addSubview:self.authCodeBgView];
|
|
[self.authCodeBgView addSubview:self.authCodeTextField];
|
|
// [self.containerView addSubview:self.authLineView];
|
|
|
|
[self.containerView addSubview:self.confirmBtn];
|
|
// [self.containerView addSubview:self.tipsLabel];
|
|
}
|
|
|
|
- (void)mew_initSubViewConstraints {
|
|
[self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self.view);
|
|
}];
|
|
|
|
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self.containerView);
|
|
}];
|
|
|
|
[self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.view).mas_offset(10);
|
|
make.top.mas_equalTo(statusbarHeight);
|
|
make.height.width.mas_equalTo(44);
|
|
}];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.equalTo(self.backButton);
|
|
make.centerX.equalTo(self.view);
|
|
}];
|
|
|
|
[self.phoneBgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(60);
|
|
make.left.mas_equalTo(32);
|
|
make.height.mas_equalTo(52);
|
|
make.width.mas_equalTo(KScreenWidth - 2 * 36);
|
|
}];
|
|
|
|
[self.areaCodeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.equalTo(self.phoneBgView);
|
|
make.left.mas_equalTo(self.phoneBgView).offset(10);
|
|
}];
|
|
|
|
[self.authCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(self.phoneBgView).offset(-10);
|
|
make.centerY.mas_equalTo(self.areaCodeLabel);
|
|
}];
|
|
|
|
[self.phoneNumTextField mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.areaCodeLabel.mas_right).offset(10);
|
|
make.centerY.mas_equalTo(self.areaCodeLabel);
|
|
make.right.mas_equalTo(self.authCodeBtn.mas_left).offset(-20);
|
|
}];
|
|
|
|
[self.authCodeBgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.phoneBgView.mas_bottom).offset(20);
|
|
make.left.height.width.mas_equalTo(self.phoneBgView);
|
|
}];
|
|
[self.authCodeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.authCodeBgView);
|
|
make.right.mas_equalTo(self.authCodeBgView).offset(-10);
|
|
make.left.mas_equalTo(self.authCodeBgView).offset(10);
|
|
make.height.mas_equalTo(48);
|
|
}];
|
|
|
|
|
|
|
|
[self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.authCodeBgView);
|
|
make.top.mas_equalTo(self.authCodeBgView.mas_bottom).offset(20);
|
|
make.height.mas_equalTo(52);
|
|
}];
|
|
|
|
}
|
|
#pragma mark -配置
|
|
- (void)mew_setConfigs {
|
|
switch (self.bindingPhoneNumType) {
|
|
case MewBindingPhoneNumTypeEdit:{
|
|
self.navigationItem.title = @"更改绑定手机";
|
|
}
|
|
break;
|
|
case MewBindingPhoneNumTypeNormal:{
|
|
self.navigationItem.title = @"绑定手机号";
|
|
}
|
|
break;
|
|
case MewBindingPhoneNumTypeConfirm:{
|
|
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)mew_setEvents {
|
|
@weakify(self)
|
|
// 获取验证码点击事件
|
|
[[[self.authCodeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] filter:^BOOL(__kindof UIControl * _Nullable value) {
|
|
// 获取验证码
|
|
if (self.phoneNumTextField.text.length == 0) {
|
|
[self mew_showErrorToast:@"手机号码不能为空"];
|
|
return NO;
|
|
}else if (self.phoneNumTextField.text.length < 11) {
|
|
[self mew_showErrorToast:@"请输入正确手机号码"];
|
|
return NO;
|
|
}else {
|
|
return YES;
|
|
}
|
|
}] subscribeNext:^(id _Nullable x) {
|
|
@strongify(self);
|
|
[self.presenter mew_phoneSmsCode:self.phoneNumTextField.text type:self.bindingPhoneNumType == MewBindingPhoneNumTypeConfirm ? MewUserLoginType_Unbind_Phone : MewUserLoginType_Bind_Phone];
|
|
}];
|
|
|
|
|
|
// 绑定和验证
|
|
[[[self.confirmBtn rac_signalForControlEvents:UIControlEventTouchUpInside] filter:^BOOL(__kindof UIControl * _Nullable value) {
|
|
@strongify(self)
|
|
// 确认绑定手机号
|
|
if (self.phoneNumTextField.text.length == 0) {
|
|
[self mew_showErrorToast:@"手机号码不能为空"];
|
|
return NO;
|
|
}else if (self.authCodeTextField.text.length == 0) {
|
|
[self mew_showErrorToast:@"验证码不能为空"];
|
|
return NO;
|
|
}else {
|
|
return YES;
|
|
}
|
|
}] subscribeNext:^(id _Nullable x) {
|
|
@strongify(self)
|
|
if (self.bindingPhoneNumType == MewBindingPhoneNumTypeConfirm) {
|
|
[self.presenter mew_checkMoblieCodeWithMoblie:self.phoneNumTextField.text code:self.authCodeTextField.text];
|
|
} else {
|
|
[self.presenter mew_bindkMoblieCodeWithMoblie:self.phoneNumTextField.text code:self.authCodeTextField.text];
|
|
}
|
|
} error:^(NSError * _Nullable error) {
|
|
|
|
}];
|
|
}
|
|
|
|
// 返回
|
|
- (void)mew_backButtonAction {
|
|
[self.navigationController popViewControllerAnimated:NO];
|
|
}
|
|
|
|
|
|
#pragma mark - MewLoginVerifBindPhoneProtocol
|
|
- (void)mew_phoneSmsCodeSuccess {
|
|
self.authCodeBtn.enabled = NO;
|
|
[self mew_showSuccessToast:@"验证码发送成功"];
|
|
[[MEWCountDownHelper shareHelper] mewOpenCountdownWithTime:60];
|
|
}
|
|
|
|
|
|
- (void)mew_checkMoblieCodeWithMoblieSuccess {
|
|
[self mew_showSuccessToast:@"验证成功"];
|
|
[[MEWCountDownHelper shareHelper] mewStopCountDown];
|
|
}
|
|
|
|
- (void)mew_bindMoblieCodeWithMoblieSuccess {
|
|
[[MEWCountDownHelper shareHelper] mewStopCountDown];
|
|
// 修改绑定信息
|
|
if (self.bindingPhoneNumType == MewBindingPhoneNumTypeEdit) {
|
|
|
|
} else if (self.bindingPhoneNumType == MewBindingPhoneNumTypeNormal) {
|
|
// @weakify(self);
|
|
[MewHUDTool showSuccessWithMessage:@"绑定成功"];
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
self.confirmBtn.enabled = YES; // 打开交互
|
|
}
|
|
|
|
|
|
#pragma mark - CountDownHelperDelegate
|
|
///倒计时进行中
|
|
- (void)mewOnCountdownOpen:(int)time {
|
|
[self.authCodeBtn setTitle:[NSString stringWithFormat:@"%ds后重试", time] forState:UIControlStateDisabled];
|
|
}
|
|
///倒计时结束
|
|
- (void)mewOnCountdownFinish {
|
|
self.authCodeBtn.enabled= YES;
|
|
[self.authCodeBtn setTitle:@"重新发送" forState:UIControlStateNormal];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (UIView *)containerView{
|
|
if (!_containerView) {
|
|
_containerView = [[UIView alloc] init];
|
|
_containerView.backgroundColor = [MewThemeColor mewAppBackgroundColor];
|
|
}
|
|
return _containerView;
|
|
}
|
|
|
|
- (UIImageView *)bgImageView {
|
|
if (!_bgImageView) {
|
|
_bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mew_home_bg"]];
|
|
}
|
|
return _bgImageView;
|
|
}
|
|
|
|
- (UIButton *)backButton {
|
|
if (!_backButton) {
|
|
_backButton = [[UIButton alloc] init];
|
|
[_backButton setImage:[UIImage imageNamed:@"mew_common_back_white_left"] forState:UIControlStateNormal];
|
|
[_backButton addTarget:self action:@selector(mew_backButtonAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _backButton;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.text = @"绑定手机号";
|
|
_titleLabel.font = kFontMedium(18);
|
|
_titleLabel.textColor = UIColor.whiteColor;
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UILabel *)areaCodeLabel{
|
|
if (!_areaCodeLabel) {
|
|
_areaCodeLabel = [[UILabel alloc] init];
|
|
_areaCodeLabel.text = @"+86";
|
|
_areaCodeLabel.textColor = [MewThemeColor mewSecondTextColor];
|
|
_areaCodeLabel.font = [UIFont systemFontOfSize:14.f];
|
|
_areaCodeLabel.adjustsFontSizeToFitWidth = YES;
|
|
}
|
|
return _areaCodeLabel;
|
|
}
|
|
|
|
|
|
- (UIButton *)confirmBtn {
|
|
if (!_confirmBtn) {
|
|
_confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_confirmBtn setTitle:@"绑定" forState:UIControlStateNormal];
|
|
[_confirmBtn.titleLabel setFont:[UIFont fontWithName:@"PingFang-SC-Medium" size:18]];
|
|
_confirmBtn.layer.cornerRadius = 52/2.f;
|
|
_confirmBtn.layer.masksToBounds = YES;
|
|
_confirmBtn.enabled = NO;
|
|
UIImage *image = [UIImage mew_gradientColorImageFromColors:@[[MewThemeColor mewColorWithHexString:@"#FF60FD"], [MewThemeColor mewColorWithHexString:@"#8974FF"],[MewThemeColor mewColorWithHexString:@"#69EBFF"]] gradientType:MewGradientTypeLeftToRight imgSize:CGSizeMake(KScreenWidth - 2*36, 52)];
|
|
_confirmBtn.backgroundColor = [UIColor colorWithPatternImage:image];
|
|
}
|
|
return _confirmBtn;
|
|
}
|
|
|
|
- (UIButton *)authCodeBtn {
|
|
if (!_authCodeBtn) {
|
|
_authCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_authCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
|
|
[_authCodeBtn setTitleColor:[MewThemeColor mewColorWithHexString:@"#9552FF"] forState:UIControlStateNormal];
|
|
// [_authCodeBtn setTitleColor:[MewThemeColor appMainColor] forState:UIControlStateNormal];
|
|
[_authCodeBtn setTitleColor:[MewThemeColor mewSecondTextColor] forState:UIControlStateDisabled];
|
|
[_authCodeBtn.titleLabel setFont:[UIFont systemFontOfSize:12.f]];
|
|
}
|
|
return _authCodeBtn;
|
|
}
|
|
- (UIView *)phoneBgView {
|
|
if (!_phoneBgView) {
|
|
_phoneBgView = [[UIView alloc] init];
|
|
_phoneBgView.backgroundColor = UIColor.whiteColor;
|
|
_phoneBgView.layer.cornerRadius = 52/2.f;
|
|
_phoneBgView.layer.masksToBounds = YES;
|
|
}
|
|
return _phoneBgView;
|
|
}
|
|
|
|
- (UITextField *)phoneNumTextField {
|
|
if (!_phoneNumTextField) {
|
|
_phoneNumTextField = [[UITextField alloc] init];
|
|
_phoneNumTextField.textColor = [MewThemeColor mewMainTextColor];
|
|
_phoneNumTextField.font = [UIFont systemFontOfSize:14.f];
|
|
_phoneNumTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入手机号"attributes:@{NSForegroundColorAttributeName: [MewThemeColor mewSecondTextColor]}];
|
|
_phoneNumTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
|
|
_phoneNumTextField.borderStyle = UITextBorderStyleNone;
|
|
_phoneNumTextField.keyboardType = UIKeyboardTypeNumberPad;
|
|
_phoneNumTextField.tintColor = [MewThemeColor mewMainTextColor];
|
|
}
|
|
return _phoneNumTextField;
|
|
}
|
|
|
|
- (UIView *)authCodeBgView {
|
|
if (!_authCodeBgView) {
|
|
_authCodeBgView = [[UIView alloc] init];
|
|
_authCodeBgView.backgroundColor = UIColor.whiteColor;
|
|
_authCodeBgView.layer.cornerRadius = 52/2.f;
|
|
_authCodeBgView.layer.masksToBounds = YES;
|
|
}
|
|
return _authCodeBgView;
|
|
}
|
|
|
|
- (UITextField *)authCodeTextField {
|
|
if (!_authCodeTextField) {
|
|
_authCodeTextField = [[UITextField alloc] init];
|
|
_authCodeTextField.textColor = [MewThemeColor mewMainTextColor];
|
|
_authCodeTextField.font = [UIFont systemFontOfSize:14.f];
|
|
_authCodeTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入验证码"attributes:@{NSForegroundColorAttributeName: [MewThemeColor mewSecondTextColor]}];
|
|
_authCodeTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
|
|
_authCodeTextField.borderStyle = UITextBorderStyleNone;
|
|
_authCodeTextField.keyboardType = UIKeyboardTypeNumberPad;
|
|
_authCodeTextField.tintColor = [MewThemeColor mewMainTextColor];
|
|
}
|
|
return _authCodeTextField;
|
|
}
|
|
|
|
|
|
@end
|