224 lines
6.7 KiB
Objective-C
224 lines
6.7 KiB
Objective-C
//
|
|
// LoginBindPhoneViewController.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2021/9/14.
|
|
//
|
|
|
|
#import "LoginBindPhoneViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
|
///Tool
|
|
#import "YUMIMacroUitls.h"
|
|
#import "DJDKMIMOMColor.h"
|
|
#import "NSString+Utils.h"
|
|
#import "UIButton+EnlargeTouchArea.h"
|
|
///Tool
|
|
#import "LoginBindPhonePresent.h"
|
|
///VC
|
|
#import "LoginVerifCodeViewController.h"
|
|
|
|
@interface LoginBindPhoneViewController ()
|
|
///提示Label
|
|
@property (nonatomic, strong) UILabel *titleLabel;
|
|
/// 手机号输入框背景
|
|
@property (nonatomic, strong) UIView *bgView;
|
|
///86 Label
|
|
@property (nonatomic, strong) UILabel *countryLabel;
|
|
///手机号输入框
|
|
@property (nonatomic, strong) UITextField *phoneTextField;
|
|
///登录按钮
|
|
@property (nonatomic, strong) UIButton *loginBtn;
|
|
///返回按钮 如果点击了返回按钮的话 那就退出登录
|
|
@property (nonatomic,strong) UIButton *backButton;
|
|
@end
|
|
|
|
@implementation LoginBindPhoneViewController
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
#pragma mark - life cycle
|
|
- (LoginBindPhonePresent *)createPresenter {
|
|
return [[LoginBindPhonePresent alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self setUpUI];
|
|
[self setEvents];
|
|
}
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
[self showErrorToast:YMLocalizedString(@"LoginBindPhoneViewController0")];
|
|
}
|
|
|
|
- (void)setUpUI {
|
|
[self.view addSubview:self.titleLabel];
|
|
[self.view addSubview:self.bgView];//输入框
|
|
[self.bgView addSubview:self.countryLabel];
|
|
[self.bgView addSubview:self.phoneTextField];
|
|
[self.view addSubview:self.loginBtn]; //登录按钮
|
|
[self.view addSubview:self.backButton];
|
|
}
|
|
|
|
- (void)viewDidLayoutSubviews {
|
|
[super viewDidLayoutSubviews];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.view).offset(150);
|
|
}];
|
|
//输入框
|
|
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(50);
|
|
make.width.mas_equalTo(280);
|
|
make.height.mas_equalTo(45);
|
|
}];
|
|
[self.countryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(10);
|
|
make.top.mas_equalTo(self.bgView).offset(5);
|
|
make.width.mas_equalTo(60);
|
|
make.height.mas_equalTo(35);
|
|
}];
|
|
[self.phoneTextField mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(70);
|
|
make.top.mas_equalTo(self.bgView).offset(5);
|
|
make.width.mas_equalTo(200);
|
|
make.height.mas_equalTo(35);
|
|
}];
|
|
//登录按钮
|
|
[self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.bgView.mas_bottom).offset(50);
|
|
make.width.mas_equalTo(60);
|
|
make.height.mas_equalTo(60);
|
|
}];
|
|
|
|
[self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(15, 15));
|
|
make.left.mas_equalTo(self.view).offset(14);
|
|
make.top.mas_equalTo(self.view).offset(36 + kSafeAreaTopHeight);
|
|
}];
|
|
}
|
|
|
|
- (void)setEvents {
|
|
@weakify(self)
|
|
// 登录
|
|
[[RACSignal combineLatest:@[self.phoneTextField.rac_textSignal]
|
|
reduce:^id(NSString *phone){
|
|
BOOL enable = phone.length > 0;
|
|
return @(enable);
|
|
}] subscribeNext:^(NSNumber *enable) {
|
|
@strongify(self)
|
|
self.loginBtn.enabled = [enable boolValue];
|
|
}];
|
|
|
|
|
|
[[[[self.loginBtn rac_signalForControlEvents:UIControlEventTouchUpInside] doNext:^(id x) {
|
|
@strongify(self)
|
|
self.loginBtn.enabled = NO;
|
|
}] flattenMap:^id (id value) {
|
|
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
|
|
if (!self.phoneTextField.text.isPhoneNumber) {
|
|
[self showErrorToast:YMLocalizedString(@"LoginBindPhoneViewController1")];
|
|
[subscriber sendNext:@(NO)];
|
|
}else {
|
|
[subscriber sendNext:@(YES)];
|
|
}
|
|
[subscriber sendCompleted];
|
|
return nil;
|
|
}];
|
|
}] subscribeNext:^(NSNumber *signedIn) {
|
|
@strongify(self)
|
|
self.loginBtn.enabled = YES;
|
|
BOOL success = [signedIn boolValue];
|
|
if (success) {
|
|
//跳转去验证码页面
|
|
LoginVerifCodeViewController *codeVC = [[LoginVerifCodeViewController alloc] init];
|
|
codeVC.phone = self.phoneTextField.text;
|
|
codeVC.type = VerifCodeType_BindPhone;
|
|
[self.navigationController pushViewController:codeVC animated:YES];
|
|
}
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)backButtonAction:(UIButton *)sender {
|
|
///退出登录状态
|
|
[self dismissViewControllerAnimated:NO completion:^{
|
|
[self.presenter logout];
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (UILabel *)titleLabel{
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:18];
|
|
_titleLabel.text = YMLocalizedString(@"LoginBindPhoneViewController2");
|
|
_titleLabel.textColor = [DJDKMIMOMColor mainTextColor];
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UIView *)bgView {
|
|
if (!_bgView) {
|
|
_bgView = [[UIView alloc] init];
|
|
_bgView.backgroundColor = [DJDKMIMOMColor appCellBackgroundColor];
|
|
_bgView.layer.cornerRadius = 45/2;
|
|
_bgView.layer.masksToBounds = YES;
|
|
}
|
|
return _bgView;
|
|
}
|
|
|
|
- (UILabel *)countryLabel{
|
|
if (!_countryLabel) {
|
|
_countryLabel = [[UILabel alloc] init];
|
|
_countryLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:15];
|
|
NSString *code = [NSString getCountryCode];
|
|
_countryLabel.text = code;
|
|
_countryLabel.textColor = [DJDKMIMOMColor mainTextColor];
|
|
_countryLabel.backgroundColor = [UIColor clearColor];
|
|
_countryLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _countryLabel;
|
|
}
|
|
|
|
- (UITextField *)phoneTextField {
|
|
if (!_phoneTextField) {
|
|
_phoneTextField = [[UITextField alloc] init];
|
|
_phoneTextField.keyboardType = UIKeyboardTypeNumberPad;
|
|
_phoneTextField.backgroundColor = [UIColor clearColor];
|
|
_phoneTextField.textColor = [DJDKMIMOMColor mainTextColor];
|
|
_phoneTextField.tintColor = [DJDKMIMOMColor appMainColor];
|
|
_phoneTextField.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:15];
|
|
_phoneTextField.textAlignment = NSTextAlignmentLeft;
|
|
}
|
|
return _phoneTextField;
|
|
}
|
|
|
|
- (UIButton *)loginBtn {
|
|
if (!_loginBtn) {
|
|
_loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
_loginBtn.enabled = NO;
|
|
[_loginBtn setImage:[UIImage imageNamed:@"login_button"] forState:UIControlStateDisabled];
|
|
[_loginBtn setImage:[UIImage imageNamed:@"login_button_sel"] forState:UIControlStateNormal];
|
|
}
|
|
return _loginBtn;
|
|
}
|
|
|
|
- (UIButton *)backButton {
|
|
if (!_backButton) {
|
|
_backButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_backButton setImage:[UIImage imageNamed:@"common_nav_back"] forState:UIControlStateNormal];
|
|
[_backButton setImage:[UIImage imageNamed:@"common_nav_back"] forState:UIControlStateSelected];
|
|
[_backButton setEnlargeEdgeWithTop:15 right:15 bottom:15 left:15];
|
|
[_backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _backButton;
|
|
}
|
|
|
|
@end
|