Files
peko-ios/YuMi/Modules/YMLogin/View/NewLogin/XPLoginPhoneViewController.m

439 lines
18 KiB
Mathematica
Raw Normal View History

2023-07-14 18:50:55 +08:00
//
// YMLoginPhoneViewController.m
// YUMI
//
// Created by XY on 2023/2/13.
//
#import "XPLoginPhoneViewController.h"
#import <Masonry.h>
#import "YUMIMacroUitls.h"
#import <ReactiveObjC.h>
#import "XPLoginInputView.h"
2023-10-07 16:21:47 +08:00
#import "PILoginManager.h"
2023-07-14 18:50:55 +08:00
#import "XPLoginPwdViewController.h"
#import "XPLoginAraeViewController.h"
#import "LoginVerifCodePresent.h"
#import "LoginVerifCodeProtocol.h"
2023-08-14 14:39:41 +08:00
#import "XPForgetPwdViewController.h"
2023-07-14 18:50:55 +08:00
@interface XPLoginPhoneViewController ()<XPLoginInputViewDelegate, LoginVerifCodeProtocol, XPLoginAraeViewControllerDelegate>
2023-08-14 14:39:41 +08:00
///
@property(nonatomic,strong) UIImageView *bgImageView;
///
@property(nonatomic,strong) UIButton *backBnt;
2023-07-14 18:50:55 +08:00
///
@property (nonatomic, strong) UILabel *titleLabel;
///
@property (nonatomic, strong) UILabel *despLabel;
2023-08-14 14:39:41 +08:00
///
@property(nonatomic,strong) UIImageView *chooseTypeView;
///
@property(nonatomic,strong) UIButton *choosePhoneBtn;
///
@property(nonatomic,strong) UIButton *choosePsdBtn;
2023-07-14 18:50:55 +08:00
///
@property (nonatomic, strong) XPLoginInputView *phoneInputView;
///
@property (nonatomic, strong) XPLoginInputView *codeInputView;
2023-08-14 14:39:41 +08:00
/////
@property (nonatomic, strong) XPLoginInputView *accountView;
///
@property (nonatomic, strong) XPLoginInputView *accountPwdView;
///
@property (nonatomic, strong) UIButton *forgetBtn;
2023-07-14 18:50:55 +08:00
///
@property (nonatomic, strong) UIButton *loginBtn;
2023-08-14 14:39:41 +08:00
///
2023-08-16 14:21:58 +08:00
@property (nonatomic,copy) NSString *pi_phoneAreaCode;
2023-08-14 14:39:41 +08:00
///,01.
@property(nonatomic,assign) int selectType;
2023-07-14 18:50:55 +08:00
@end
@implementation XPLoginPhoneViewController
2023-08-14 14:39:41 +08:00
- (BOOL)isHiddenNavBar {
return YES;
}
2023-07-14 18:50:55 +08:00
- (LoginVerifCodePresent *)createPresenter {
return [[LoginVerifCodePresent alloc] init];
}
- (void)viewDidLoad {
2023-08-14 14:39:41 +08:00
self.selectType = 0;
2023-12-15 17:08:10 +08:00
NSString *code = [NSString getCountryCode];
self.pi_phoneAreaCode = [code stringByReplacingOccurrencesOfString:@"+" withString:@""];
2023-07-14 18:50:55 +08:00
[super viewDidLoad];
[self createUI];
[self racBind];
}
- (void)createUI {
2023-08-14 14:39:41 +08:00
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.bgImageView];
[self.view addSubview:self.backBnt];
2023-07-14 18:50:55 +08:00
[self.view addSubview:self.titleLabel];
2023-08-14 14:39:41 +08:00
[self.view addSubview:self.chooseTypeView];
[self.chooseTypeView addSubview:self.choosePhoneBtn];
[self.chooseTypeView addSubview:self.choosePsdBtn];
UIView *bgView = [UIView new];
bgView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:bgView];
2023-07-14 18:50:55 +08:00
[self.view addSubview:self.phoneInputView];
[self.view addSubview:self.codeInputView];
2023-08-14 14:39:41 +08:00
[self.view addSubview:self.accountView];
[self.view addSubview:self.accountPwdView];
[self.view addSubview:self.forgetBtn];
2023-07-14 18:50:55 +08:00
2023-08-14 14:39:41 +08:00
[self.view addSubview:self.loginBtn];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(418));
}];
[self.backBnt mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(20));
make.width.mas_equalTo(kGetScaleWidth(28));
make.height.mas_equalTo(kGetScaleWidth(28));
make.top.mas_equalTo(kGetScaleWidth(52));
}];
2023-07-14 18:50:55 +08:00
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
2023-08-14 14:39:41 +08:00
make.top.equalTo(self.backBnt.mas_bottom).mas_offset(kGetScaleWidth(48));
make.leading.mas_equalTo(kGetScaleWidth(24));
make.height.mas_equalTo(kGetScaleWidth(40));
2023-07-14 18:50:55 +08:00
}];
2023-08-14 14:39:41 +08:00
[self.chooseTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLabel.mas_bottom).mas_offset(kGetScaleWidth(24));
make.left.right.equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(65));
}];
[self.choosePsdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(16));
make.height.mas_equalTo(kGetScaleWidth(22));
make.width.mas_equalTo(KScreenWidth/2);
make.left.mas_equalTo(0);
}];
[self.choosePhoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(16));
make.height.mas_equalTo(kGetScaleWidth(22));
make.width.mas_equalTo(KScreenWidth/2);
make.right.mas_equalTo(0);
}];
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.equalTo(self.view);
make.top.equalTo(self.chooseTypeView.mas_bottom);
2023-07-14 18:50:55 +08:00
}];
[self.phoneInputView mas_makeConstraints:^(MASConstraintMaker *make) {
2023-08-14 14:39:41 +08:00
make.centerX.equalTo(self.view);
make.width.mas_equalTo(kGetScaleWidth(303));
make.top.mas_equalTo(self.chooseTypeView.mas_bottom).offset(kGetScaleWidth(39));
make.height.mas_equalTo(kGetScaleWidth(52));
2023-07-14 18:50:55 +08:00
}];
[self.codeInputView mas_makeConstraints:^(MASConstraintMaker *make) {
2023-08-14 14:39:41 +08:00
make.centerX.equalTo(self.view);
make.width.mas_equalTo(kGetScaleWidth(303));
make.top.mas_equalTo(self.phoneInputView.mas_bottom).offset(kGetScaleWidth(20));
make.height.mas_equalTo(kGetScaleWidth(52));
2023-07-14 18:50:55 +08:00
}];
2023-08-14 14:39:41 +08:00
[self.accountView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.phoneInputView);
}];
[self.accountPwdView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.codeInputView);
2023-07-14 18:50:55 +08:00
}];
2023-08-14 14:39:41 +08:00
[self.forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-kGetScaleWidth(52));
make.height.mas_equalTo(kGetScaleWidth(17));
make.top.equalTo(self.accountPwdView.mas_bottom).mas_offset(kGetScaleWidth(8));
}];
[self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.codeInputView.mas_bottom).offset(kGetScaleWidth(48));
2023-07-14 18:50:55 +08:00
make.centerX.mas_equalTo(self.view);
2023-08-14 14:39:41 +08:00
make.height.mas_equalTo(kGetScaleWidth(48));
make.width.mas_equalTo(kGetScaleWidth(303));
2023-07-14 18:50:55 +08:00
}];
2023-08-14 14:39:41 +08:00
2023-07-14 18:50:55 +08:00
}
2023-08-16 15:50:27 +08:00
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
}
2023-07-14 18:50:55 +08:00
- (void)racBind {
2023-08-14 14:39:41 +08:00
@weakify(self);
RAC(self.loginBtn, enabled) = [[RACSignal combineLatest:@[self.phoneInputView.inputTextField.rac_textSignal, self.codeInputView.inputTextField.rac_textSignal,self.accountView.inputTextField.rac_textSignal,self.accountPwdView.inputTextField.rac_textSignal] reduce:^id _Nonnull(NSString *phone, NSString* smsCode,NSString *account,NSString *accountPwd){
@strongify(self);
if(self.selectType == 0){
return @((account.length > 0) && accountPwd.length >= 6);
}
2023-07-14 18:50:55 +08:00
return @((phone.length > 0) && smsCode.length >= 5);
}] takeUntil:self.rac_willDeallocSignal];
}
///
- (void)loginBtnClicked {
2023-08-14 19:03:26 +08:00
[XNDJTDDLoadingTool showOnlyView:self.view];
2023-08-14 14:39:41 +08:00
if(self.selectType == 0){
NSString *phone = self.accountView.inputTextField.text;
NSString *password = self.accountPwdView.inputTextField.text;
[self.presenter loginWithPhone:phone password:password];
return;
}
2023-07-14 18:50:55 +08:00
NSString *phone = self.phoneInputView.inputTextField.text;
NSString *smsCode = self.codeInputView.inputTextField.text;
2023-08-16 14:21:58 +08:00
NSString * phoneStr = [NSString stringWithFormat:@"%@%@",self.pi_phoneAreaCode, phone];
[self.presenter loginWithPhone:phoneStr code:smsCode phoneAreaCode:self.pi_phoneAreaCode];
2023-07-14 18:50:55 +08:00
}
2023-08-14 14:39:41 +08:00
- (void)forgetBtnClicked {
XPForgetPwdViewController *forgetVC = [[XPForgetPwdViewController alloc] init];
[self.navigationController pushViewController:forgetVC animated:YES];
2023-07-14 18:50:55 +08:00
}
#pragma mark - XPLoginInputViewDelegate
- (void)smsCodeAction {
NSString *phone = self.phoneInputView.inputTextField.text;
if (phone.length == 0 ) {
[self showErrorToast:YMLocalizedString(@"XPLoginPhoneViewController0")];
return;
}
2023-08-16 14:21:58 +08:00
[self.presenter phoneSmsCode:[NSString stringWithFormat:@"%@%@",self.pi_phoneAreaCode,phone] type:GetSmsType_Regist phoneAreaCode:self.pi_phoneAreaCode];
2023-07-14 18:50:55 +08:00
}
- (void)areaListAction {
XPLoginAraeViewController *codeVC = [XPLoginAraeViewController new];
codeVC.delegate = self;
[self.navigationController pushViewController:codeVC animated:YES];
}
- (void)chooseAreaCodeSuccess:(NSString *)code {
if (code.length > 0) {
2023-08-16 14:21:58 +08:00
self.pi_phoneAreaCode = code;
2023-07-14 18:50:55 +08:00
[self.phoneInputView.areaCodeBtn setTitle:[NSString stringWithFormat:@"+%@", code] forState:UIControlStateNormal];
}
}
#pragma mark - LoginVerifCodeProtocol
2023-08-17 16:10:11 +08:00
- (void)loginWithPhoenSuccess{
[XNDJTDDLoadingTool hideOnlyView:self.view];
2023-08-18 10:05:07 +08:00
[[NSUserDefaults standardUserDefaults]setValue:@(ThirdLoginType_Phone) forKey:@"kLoginSuccessType"];
[[NSUserDefaults standardUserDefaults]synchronize];
2023-08-17 16:10:11 +08:00
[self showSuccessToast:YMLocalizedString(@"XPLoginPhoneViewController1")];
2023-10-07 16:21:47 +08:00
[PILoginManager loginWithVC:self isLoginPhone:YES];
2023-08-17 16:10:11 +08:00
}
2023-07-14 18:50:55 +08:00
- (void)loginSuccess {
2023-08-14 19:03:26 +08:00
[XNDJTDDLoadingTool hideOnlyView:self.view];
2023-08-14 14:39:41 +08:00
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"kLoginSuccessType"];
2023-07-14 18:50:55 +08:00
[self showSuccessToast:YMLocalizedString(@"XPLoginPhoneViewController1")];
2023-10-07 16:21:47 +08:00
[PILoginManager loginWithVC:self isLoginPhone:NO];
2023-07-14 18:50:55 +08:00
}
2023-09-01 14:29:14 +08:00
- (void)loginFailWithMsg:(NSString *)msg{
[self showErrorToast:msg];
2023-08-14 19:03:26 +08:00
[XNDJTDDLoadingTool hideOnlyView:self.view];
}
2023-08-14 14:39:41 +08:00
-(void)backViewAction{
[self.navigationController popViewControllerAnimated:YES];
}
2023-07-14 18:50:55 +08:00
#pragma mark - LoginProtocol
- (void)phoneSmsCodeSuccess {
[self showSuccessToast:YMLocalizedString(@"XPLoginPhoneViewController2")];
[self.codeInputView fireTimer];
}
2023-08-14 14:39:41 +08:00
-(void)setSelectType:(int)selectType{
_selectType = selectType;
_chooseTypeView.image = _selectType == 0 ? kImage(@"login_choose_phone_bg"): kImage(@"login_choose_pwd_bg");
_choosePhoneBtn.selected = _selectType != 0;
_choosePsdBtn.selected = _selectType == 0;
_forgetBtn.hidden = _selectType != 0;
_phoneInputView.hidden = _selectType == 0;
_codeInputView.hidden = _selectType == 0;
_accountView.hidden = _selectType != 0;
_accountPwdView.hidden = _selectType != 0;
}
-(void)choosePhoneAction{
self.selectType = 1;
}
-(void)choosePwdAction{
self.selectType = 0;
}
2023-07-14 18:50:55 +08:00
#pragma mark -
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
2023-08-14 14:39:41 +08:00
_titleLabel.text = @"Welcome to Piko";
_titleLabel.font = kFontBold(28);
_titleLabel.textColor = UIColorFromRGB(0x1F1B4F);
2023-07-14 18:50:55 +08:00
}
return _titleLabel;
}
- (UILabel *)despLabel {
if (!_despLabel) {
_despLabel = [[UILabel alloc] init];
_despLabel.text = YMLocalizedString(@"XPLoginPhoneViewController4");
_despLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
_despLabel.textColor = [UIColor.whiteColor colorWithAlphaComponent:0.6];
}
return _despLabel;
}
- (XPLoginInputView *)phoneInputView {
if (!_phoneInputView) {
_phoneInputView = [[XPLoginInputView alloc] init];
_phoneInputView.areaStackView.hidden = NO;
_phoneInputView.delegate = self;
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPhoneViewController5")];
2023-08-14 14:39:41 +08:00
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
2023-07-14 18:50:55 +08:00
_phoneInputView.inputTextField.attributedPlaceholder = placeholder;
_phoneInputView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
2023-08-14 14:39:41 +08:00
_phoneInputView.hidden = YES;
2023-07-14 18:50:55 +08:00
}
return _phoneInputView;
}
- (XPLoginInputView *)codeInputView {
if (!_codeInputView) {
_codeInputView = [[XPLoginInputView alloc] init];
_codeInputView.smsCodeBtn.hidden = NO;
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPhoneViewController6")];
2023-08-14 14:39:41 +08:00
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
2023-07-14 18:50:55 +08:00
_codeInputView.inputTextField.attributedPlaceholder = placeholder;
_codeInputView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
_codeInputView.delegate = self;
2023-08-14 14:39:41 +08:00
_codeInputView.hidden = YES;
2023-07-14 18:50:55 +08:00
}
return _codeInputView;
}
- (UIButton *)loginBtn {
if (!_loginBtn) {
_loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
2023-08-14 14:39:41 +08:00
UIImage *nextImage = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor],[DJDKMIMOMColor confirmButtonGradientMiddleColor],[DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(303), kGetScaleWidth(48))];
UIImage *disableImage = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xD1F9FF),UIColorFromRGB(0xDEE4FF),UIColorFromRGB(0xEEDCFF)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(303), kGetScaleWidth(48))];
[_loginBtn setImage:nextImage forState:UIControlStateNormal];
[_loginBtn setImage:disableImage forState:UIControlStateDisabled];
_loginBtn.layer.cornerRadius = kGetScaleWidth(48)/2;
_loginBtn.layer.masksToBounds = YES;
UILabel *titleView = [UILabel labelInitWithText:YMLocalizedString(@"XPLoginPhoneViewController8") font:kFontMedium(16) textColor:[UIColor whiteColor]];
titleView.textAlignment = NSTextAlignmentCenter;
[_loginBtn addSubview:titleView];
[titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.loginBtn);
}];
2023-07-14 18:50:55 +08:00
[_loginBtn addTarget:self action:@selector(loginBtnClicked) forControlEvents:UIControlEventTouchUpInside];
}
return _loginBtn;
}
2023-08-14 14:39:41 +08:00
- (UIImageView *)bgImageView{
if(!_bgImageView){
_bgImageView = [[UIImageView alloc]init];
_bgImageView.image = kImage(@"login_phone_pwd_bg");
_bgImageView.contentMode = 2;
}
return _bgImageView;
}
- (UIButton *)backBnt{
if(!_backBnt){
_backBnt = [UIButton new];
[_backBnt setImage:kImage(@"common_nav_back") forState:UIControlStateNormal];
[_backBnt addTarget:self action:@selector(backViewAction) forControlEvents:UIControlEventTouchUpInside];
[_backBnt setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
}
return _backBnt;
}
- (UIImageView *)chooseTypeView{
if(!_chooseTypeView){
_chooseTypeView = [UIImageView new];
_chooseTypeView.userInteractionEnabled = YES;
[_chooseTypeView setImage:kImage(@"login_choose_phone_bg")];
}
return _chooseTypeView;
}
- (UIButton *)choosePhoneBtn{
if(!_choosePhoneBtn){
_choosePhoneBtn = [UIButton new];
[_choosePhoneBtn setTitle:YMLocalizedString(@"XPLoginPhoneViewController10" ) forState:UIControlStateNormal];
[_choosePhoneBtn setTitleColor:UIColorFromRGB(0x6D6B89) forState:UIControlStateNormal];
[_choosePhoneBtn setTitleColor:UIColorFromRGB(0x1F1B4F) forState:UIControlStateSelected];
_choosePhoneBtn.titleLabel.font = kFontSemibold(16);
[ _choosePhoneBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
[_choosePhoneBtn addTarget:self action:@selector(choosePhoneAction) forControlEvents:UIControlEventTouchUpInside];
}
return _choosePhoneBtn;
}
- (UIButton *)choosePsdBtn{
if(!_choosePsdBtn){
_choosePsdBtn = [UIButton new];
[_choosePsdBtn setTitle:YMLocalizedString(@"XPLoginPhoneViewController9") forState:UIControlStateNormal];
[_choosePsdBtn setTitleColor:UIColorFromRGB(0x6D6B89) forState:UIControlStateNormal];
[_choosePsdBtn setTitleColor:UIColorFromRGB(0x1F1B4F) forState:UIControlStateSelected];
_choosePsdBtn.titleLabel.font = kFontSemibold(16);
[_choosePsdBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
[_choosePsdBtn addTarget:self action:@selector(choosePwdAction) forControlEvents:UIControlEventTouchUpInside];
_choosePsdBtn.selected = YES;
}
return _choosePsdBtn;
}
- (XPLoginInputView *)accountView {
if (!_accountView) {
_accountView = [[XPLoginInputView alloc] init];
_accountView.areaStackView.hidden = YES;
2023-08-25 16:32:51 +08:00
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPwdViewController6")];
2023-08-14 14:39:41 +08:00
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
_accountView.inputTextField.attributedPlaceholder = placeholder;
_accountView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
2023-07-14 18:50:55 +08:00
}
2023-08-14 14:39:41 +08:00
return _accountView;
2023-07-14 18:50:55 +08:00
}
2023-08-14 14:39:41 +08:00
- (XPLoginInputView *)accountPwdView {
if (!_accountPwdView) {
_accountPwdView = [[XPLoginInputView alloc] init];
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPwdViewController3")];
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
_accountPwdView.inputTextField.attributedPlaceholder = placeholder;
_accountPwdView.inputTextField.keyboardType = UIKeyboardTypeAlphabet;
_accountPwdView.inputTextField.secureTextEntry = YES;
}
return _accountPwdView;
}
- (UIButton *)forgetBtn {
if (!_forgetBtn) {
_forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_forgetBtn setTitle:YMLocalizedString(@"XPRoomRedPacketPwdView1") forState:UIControlStateNormal];
[_forgetBtn setTitleColor:UIColorFromRGB(0xB3B3C3) forState:UIControlStateNormal];
_forgetBtn.titleLabel.font = kFontRegular(12);
[_forgetBtn addTarget:self action:@selector(forgetBtnClicked) forControlEvents:UIControlEventTouchUpInside];
}
return _forgetBtn;
}
2023-07-14 18:50:55 +08:00
@end