Files
peko-ios/YuMi/Modules/YMMine/View/Setting/XPMineLoginPasswordViewController.m
2023-08-25 16:32:51 +08:00

269 lines
10 KiB
Objective-C

//
// XPMineLoginPasswordViewController.m
// xplan-ios
//
// Created by 冯硕 on 2022/4/25.
//
#import "XPMineLoginPasswordViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <ReactiveObjC/ReactiveObjC.h>
///Tool
#import "UIButton+EnlargeTouchArea.h"
#import "UIImage+Utils.h"
///Model
#import "UserInfoModel.h"
///View
#import "XPMineModifPayPwdView.h"
///P
#import "XPMineLoginPasswordPresenter.h"
#import "XPMineLoginPasswordProtocol.h"
///VC
#import "XPMineSettingViewController.h"
#import "LoginForgetPasswordViewController.h"
@interface XPMineLoginPasswordViewController ()<XPMineLoginPasswordProtocol>
///容器
@property (nonatomic,strong) UIStackView *stackView;
///当前的密码
@property (nonatomic,strong) XPMineModifPayPwdView *currentPwdView;
///新密码
@property (nonatomic,strong) XPMineModifPayPwdView *newsPwdView;
///检查密码
@property (nonatomic,strong) XPMineModifPayPwdView *checkPwdView;
///忘记密码
@property (nonatomic, strong) UIButton *forgetButton;
///提交
@property (nonatomic, strong) UIButton *submitButton;
///限制的提示
@property (nonatomic,strong) UILabel *limitLabel;
///旧密码
@property (nonatomic,copy) NSString *currentPwd;
///新密码
@property (nonatomic,copy) NSString *newsPwd;
///检查密码
@property (nonatomic,copy) NSString *checkPwd;
@end
@implementation XPMineLoginPasswordViewController
- (XPMineLoginPasswordPresenter *)createPresenter {
return [[XPMineLoginPasswordPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
}
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.stackView];
[self.view addSubview:self.limitLabel];
[self.view addSubview:self.forgetButton];
[self.view addSubview:self.submitButton];
[self.stackView addArrangedSubview:self.currentPwdView];
[self.stackView addArrangedSubview:self.newsPwdView];
[self.stackView addArrangedSubview:self.checkPwdView];
}
- (void)initSubViewConstraints {
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(self.view);
make.top.mas_equalTo(30);
}];
[self.limitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(self.view).offset(20);
make.trailing.mas_equalTo(-20);
make.top.mas_equalTo(self.stackView.mas_bottom).offset(10);
}];
[self.forgetButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.mas_equalTo(self.view).offset(-20);
make.top.mas_equalTo(self.submitButton.mas_bottom).offset(15);
}];
[self.submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.limitLabel.mas_bottom).offset(20);
make.trailing.mas_equalTo(self.view).offset(-32);
make.leading.mas_equalTo(self.view).offset(32);
make.height.mas_equalTo(45);
}];
}
#pragma mark - XPMineLoginPasswordProtocol
- (void)setLoginPasswordSuccess {
[self showSuccessToast:YMLocalizedString(@"XPMineLoginPasswordViewController0")];
self.userInfo.isBindPasswd = YES;
if(self.isLogout == YES){
// 返回设置页面
__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];
}
return;
}
[self.navigationController popViewControllerAnimated:YES];
}
- (void)modifyLoginPasswordSuccess {
[self showSuccessToast:YMLocalizedString(@"XPMineLoginPasswordViewController1")];
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - Event Response
- (void)forgetButtonAction:(UIButton *)sender {
LoginForgetPasswordViewController *forgetPawVC = [LoginForgetPasswordViewController new];
forgetPawVC.isLogout = YES;
[self.navigationController pushViewController:forgetPawVC animated:YES];
}
- (void)submitButtonAction:(UIButton *)sender {
if (![self.newsPwdView.contentTextField.text isEqualToString:self.checkPwdView.contentTextField.text]) {
[self showErrorToast:YMLocalizedString(@"XPMineLoginPasswordViewController2")];
return;
}
if (self.isModifiPwd) {
[self.presenter modifyLoginPassword:self.userInfo.phone newPwd:self.newsPwd pwd:self.currentPwd];
} else {
[self.presenter setLoginPassword:self.userInfo.phone newPwd:self.newsPwd];
}
}
- (void)textFieldDidChange:(UITextField *)textfield {
if (textfield == self.currentPwdView.contentTextField) {
self.currentPwd = textfield.text;
} else if (textfield == self.newsPwdView.contentTextField) {
self.newsPwd = textfield.text;
} else {
self.checkPwd = textfield.text;
}
if (self.isModifiPwd) {
if (self.currentPwd.length >= 6 && self.newsPwd.length >= 6 && self.checkPwd.length >= 6) {
self.submitButton.enabled = YES;
} else {
self.submitButton.enabled = NO;
}
} else {
if (self.newsPwd.length >= 6 && self.checkPwd.length >= 6) {
self.submitButton.enabled = YES;
} else {
self.submitButton.enabled = NO;
}
}
}
#pragma mark - Getters And Setters
- (void)setIsModifiPwd:(BOOL)isModifiPwd {
_isModifiPwd = isModifiPwd;
if (_isModifiPwd) {
self.currentPwdView.hidden = NO;
self.currentPwdView.placeholder = YMLocalizedString(@"XPMineLoginPasswordViewController3");
self.newsPwdView.placeholder = YMLocalizedString(@"XPMineLoginPasswordViewController4");
self.checkPwdView.placeholder = YMLocalizedString(@"XPMineLoginPasswordViewController5");
self.title = YMLocalizedString(@"XPMineLoginPasswordViewController6");
} else {
self.currentPwdView.hidden = YES;
self.newsPwdView.placeholder = YMLocalizedString(@"XPMineLoginPasswordViewController7");
self.checkPwdView.placeholder = YMLocalizedString(@"XPMineLoginPasswordViewController8");
self.forgetButton.hidden = YES;
self.title = YMLocalizedString(@"XPMineLoginPasswordViewController9");
}
self.currentPwdView.hidden = !_isModifiPwd;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisVertical;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentFill;
_stackView.spacing = 25;
}
return _stackView;
}
- (XPMineModifPayPwdView *)currentPwdView {
if (!_currentPwdView) {
_currentPwdView = [[XPMineModifPayPwdView alloc] init];
[_currentPwdView.contentTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
_currentPwdView.hidden = YES;
}
return _currentPwdView;
}
- (XPMineModifPayPwdView *)newsPwdView {
if (!_newsPwdView) {
_newsPwdView = [[XPMineModifPayPwdView alloc] init];
[_newsPwdView.contentTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}
return _newsPwdView;
}
- (XPMineModifPayPwdView *)checkPwdView {
if (!_checkPwdView) {
_checkPwdView = [[XPMineModifPayPwdView alloc] init];
[_checkPwdView.contentTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}
return _checkPwdView;
}
- (UIButton *)submitButton {
if (!_submitButton) {
_submitButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_submitButton setTitleColor:[DJDKMIMOMColor confirmButtonTextColor] forState:UIControlStateNormal];
[_submitButton setTitleColor:[DJDKMIMOMColor disableButtonTextColor] forState:UIControlStateDisabled];
[_submitButton setTitle:YMLocalizedString(@"XPMineLoginPasswordViewController10") forState:UIControlStateNormal];
_submitButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:18];
_submitButton.layer.masksToBounds = YES;
_submitButton.layer.cornerRadius = 45/2;
[_submitButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor], [DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
[_submitButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor disableButtonColor], [DJDKMIMOMColor disableButtonColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateDisabled];
[_submitButton addTarget:self action:@selector(submitButtonAction:) forControlEvents:UIControlEventTouchUpInside];
_submitButton.enabled = NO;
}
return _submitButton;
}
- (UIButton *)forgetButton {
if (!_forgetButton) {
_forgetButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_forgetButton setEnlargeEdgeWithTop:5 right:5 bottom:5 left:5];
[_forgetButton setTitleColor:[DJDKMIMOMColor secondTextColor] forState:UIControlStateNormal];
[_forgetButton setTitle:YMLocalizedString(@"XPMineLoginPasswordViewController11") forState:UIControlStateNormal];
_forgetButton.titleLabel.font = [UIFont systemFontOfSize:13];
[_forgetButton addTarget:self action:@selector(forgetButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _forgetButton;
}
- (UILabel *)limitLabel {
if (!_limitLabel) {
_limitLabel = [[UILabel alloc] init];
_limitLabel.font = [UIFont systemFontOfSize:13];
_limitLabel.textColor = [DJDKMIMOMColor secondTextColor];
_limitLabel.text = YMLocalizedString(@"XPMineLoginPasswordViewController12");
_limitLabel.numberOfLines = 0;
}
return _limitLabel;
}
@end