Files
peko-ios/YuMi/Modules/YMLogin/View/NewLogin/XPForgetPwdViewController.m
2023-08-14 14:39:41 +08:00

266 lines
10 KiB
Objective-C

//
// YMForgetPwdViewController.m
// YUMI
//
// Created by XY on 2023/2/14.
//
#import "XPForgetPwdViewController.h"
#import <Masonry.h>
#import "YUMIMacroUitls.h"
#import <ReactiveObjC.h>
#import "XPLoginInputView.h"
#import "LoginForgetPasswordPresent.h"
#import "LoginForgetPasswordProtocol.h"
#import "XPLoginAraeViewController.h"
@interface XPForgetPwdViewController ()<XPLoginInputViewDelegate, LoginForgetPasswordProtocol, XPLoginAraeViewControllerDelegate>
///背景
@property(nonatomic,strong) UIImageView *bgImageView;
///返回
@property(nonatomic,strong) UIButton *backBnt;
/// 标题
@property (nonatomic, strong) UILabel *titleLabel;
/// 手机号输入框
@property (nonatomic, strong) XPLoginInputView *phoneInputView;
/// 验证码输入框
@property (nonatomic, strong) XPLoginInputView *codeInputView;
/// 密码输入框
@property (nonatomic, strong) XPLoginInputView *pwdInputView;
/// 确定按钮
@property (nonatomic, strong) UIButton *sureBtn;
@property (nonatomic,copy) NSString *phoneAreaCode;
@end
@implementation XPForgetPwdViewController
- (BOOL)isHiddenNavBar {
return YES;
}
- (LoginForgetPasswordPresent *)createPresenter {
return [[LoginForgetPasswordPresent alloc] init];
}
- (void)viewDidLoad {
self.phoneAreaCode = @"852";
[super viewDidLoad];
[self createUI];
[self racBind];
}
- (void)createUI {
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.bgImageView];
[self.view addSubview:self.backBnt];
[self.view addSubview:self.titleLabel];
UIView *bgView = [UIView new];
bgView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:bgView];
bgView.layer.cornerRadius = kGetScaleWidth(20);
bgView.layer.masksToBounds = YES;
[self.view addSubview:self.phoneInputView];
[self.view addSubview:self.codeInputView];
[self.view addSubview:self.pwdInputView];
[self.view addSubview:self.sureBtn];
[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));
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.top.equalTo(self.backBnt.mas_bottom).mas_offset(kGetScaleWidth(48));
make.leading.mas_equalTo(kGetScaleWidth(24));
make.height.mas_equalTo(kGetScaleWidth(40));
}];
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.equalTo(self.view);
make.top.mas_equalTo(kGetScaleWidth(257));
}];
[self.phoneInputView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.width.mas_equalTo(kGetScaleWidth(303));
make.top.mas_equalTo(kGetScaleWidth(296));
make.height.mas_equalTo(kGetScaleWidth(52));
}];
[self.codeInputView mas_makeConstraints:^(MASConstraintMaker *make) {
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));
}];
[self.pwdInputView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.width.mas_equalTo(kGetScaleWidth(303));
make.top.mas_equalTo(self.codeInputView.mas_bottom).offset(kGetScaleWidth(20));
make.height.mas_equalTo(kGetScaleWidth(52));
}];
[self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.pwdInputView.mas_bottom).offset(kGetScaleWidth(48));
make.centerX.mas_equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(48));
make.width.mas_equalTo(kGetScaleWidth(303));
}];
}
- (void)racBind {
RAC(self.sureBtn, enabled) = [[RACSignal combineLatest:@[self.phoneInputView.inputTextField.rac_textSignal, self.pwdInputView.inputTextField.rac_textSignal, self.pwdInputView.inputTextField.rac_textSignal] reduce:^id _Nonnull(NSString *phone, NSString* smsCode, NSString *password){
return @((phone.length > 0) && smsCode.length >= 5 && (password.length >= 6 && password.length <= 16));
}] takeUntil:self.rac_willDeallocSignal];
}
/// 确认
- (void)sureBtnClicked {
NSString *phone = self.phoneInputView.inputTextField.text;
NSString *smsCode = self.codeInputView.inputTextField.text;
NSString *password = self.pwdInputView.inputTextField.text;
[self.presenter resetPassword:phone newPwd:password smsCode:smsCode phoneAreaCode:@""];
}
#pragma mark - XPLoginInputViewDelegate
- (void)smsCodeAction {
NSString *phone = self.phoneInputView.inputTextField.text;
if (phone.length <= 0) {
[self showErrorToast:YMLocalizedString(@"XPForgetPwdViewController0")];
return;
}
[self.presenter phoneSmsCode:phone type:GetSmsType_Reset_Password phoneAreaCode:self.phoneAreaCode];
}
- (void)areaListAction {
XPLoginAraeViewController *codeVC = [XPLoginAraeViewController new];
codeVC.delegate = self;
[self.navigationController pushViewController:codeVC animated:YES];
}
- (void)chooseAreaCodeSuccess:(NSString *)code {
if (code.length > 0) {
self.phoneAreaCode = code;
[self.phoneInputView.areaCodeBtn setTitle:[NSString stringWithFormat:@"+%@", code] forState:UIControlStateNormal];
}
}
#pragma mark - LoginForgetPasswordProtocol
///请求手机号的验证码成功
- (void)phoneSmsCodeSuccess {
[self showSuccessToast:YMLocalizedString(@"XPForgetPwdViewController1")];
[self.codeInputView fireTimer];
}
///重置密码成功
- (void)resetPasswrodSuccess {
[self showSuccessToast:YMLocalizedString(@"XPForgetPwdViewController2")];
[self.navigationController popViewControllerAnimated:YES];
}
-(void)backViewAction1{
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - 懒加载
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = kFontBold(28);
_titleLabel.textColor = UIColorFromRGB(0x1F1B4F);
_titleLabel.text = YMLocalizedString(@"XPForgetPwdViewController3");
}
return _titleLabel;
}
- (XPLoginInputView *)phoneInputView {
if (!_phoneInputView) {
_phoneInputView = [[XPLoginInputView alloc] init];
_phoneInputView.areaStackView.hidden = NO;
_phoneInputView.delegate = self;
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPForgetPwdViewController4")];
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
_phoneInputView.inputTextField.attributedPlaceholder = placeholder;
_phoneInputView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
}
return _phoneInputView;
}
- (XPLoginInputView *)codeInputView {
if (!_codeInputView) {
_codeInputView = [[XPLoginInputView alloc] init];
_codeInputView.smsCodeBtn.hidden = NO;
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPForgetPwdViewController5")];
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
_codeInputView.inputTextField.attributedPlaceholder = placeholder;
_codeInputView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
_codeInputView.delegate = self;
}
return _codeInputView;
}
- (XPLoginInputView *)pwdInputView {
if (!_pwdInputView) {
_pwdInputView = [[XPLoginInputView alloc] init];
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPForgetPwdViewController6")];
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
_pwdInputView.inputTextField.attributedPlaceholder = placeholder;
_pwdInputView.inputTextField.keyboardType = UIKeyboardTypeAlphabet;
_pwdInputView.inputTextField.secureTextEntry = YES;
}
return _pwdInputView;
}
- (UIButton *)sureBtn {
if (!_sureBtn) {
_sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
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))];
[_sureBtn setImage:nextImage forState:UIControlStateNormal];
[_sureBtn setImage:disableImage forState:UIControlStateDisabled];
_sureBtn.layer.cornerRadius = kGetScaleWidth(48)/2;
_sureBtn.layer.masksToBounds = YES;
UILabel *titleView = [UILabel labelInitWithText:YMLocalizedString(@"XPLoginPhoneViewController8") font:kFontMedium(16) textColor:[UIColor whiteColor]];
titleView.textAlignment = NSTextAlignmentCenter;
[_sureBtn addSubview:titleView];
[titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.sureBtn);
}];
[_sureBtn addTarget:self action:@selector(sureBtnClicked) forControlEvents:UIControlEventTouchUpInside];
}
return _sureBtn;
}
- (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(backViewAction1) forControlEvents:UIControlEventTouchUpInside];
[_backBnt setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
}
return _backBnt;
}
@end