cdts/xdts-ios 3/TreeHole/Code/Features/Login/ViewController/GetSmsCodeViewController.m
2023-08-18 14:05:39 +08:00

130 lines
3.9 KiB
Objective-C

//
// GetSmsCodeViewController.m
// Youth
//
// Created by mambaxie on 2022/1/1.
//
#import "GetSmsCodeViewController.h"
#import "WLUnitField.h"
#import "PYGetSmsCodeButton.h"
#import "SetNickNameViewController.h"
NSUInteger SMSCodeNumberCount = 4;
@interface GetSmsCodeViewController () <WLUnitFieldDelegate>
@property (nonatomic, strong) NSString *phone;
@property (nonatomic, strong) UILabel *tipsLabel;
@property (nonatomic, strong) WLUnitField *uniField;
@end
@implementation GetSmsCodeViewController
- (NSString *)topImageName {
return @"TH_login_code_img";
}
- (NSString *)tipsContent {
return @"请输入获取的验证码";
}
- (instancetype)initWithPhone:(NSString *)phone {
if (self = [super init]) {
_phone = phone;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
WLUnitField *uniField = [[WLUnitField alloc] initWithInputUnitCount:SMSCodeNumberCount];
uniField.y = [self topContentMargin];
uniField.unitSize = CGSizeMake(FIX_SIZE(44), FIX_SIZE(52));
uniField.delegate = self;
uniField.unitSpace = FIX_SIZE(8);
uniField.borderRadius = 15;
uniField.cursorColor = uniField.trackTintColor = uniField.textColor = COLOR_WITH_RGB(0x222222);
uniField.textFont = MT_FONT_MEDIUM_SIZE(15);
uniField.borderWidth = 1;
uniField.backgroundColor = COLOR_WITH_RGB(0xF3F9FB);
uniField.tintColor = [UIColor clearColor];
[uniField sizeToFit];
uniField.inputDelegate = self;
// [uniField addTarget:self action:@selector(unitFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
uniField.centerX = SCREEN_WIDTH * 0.5;
[self.cardView addSubview:uniField];
self.uniField = uniField;
UILabel *tipsLabel = [[UILabel alloc] init];
tipsLabel.font = MT_FONT_REGULAR_SIZE(11);
tipsLabel.textColor = COLOR_WITH_RGB(0xA5AFB5);
tipsLabel.text = [NSString stringWithFormat:@"已发送验证码至 %@", self.phone];
[tipsLabel sizeToFit];
tipsLabel.centerX = SCREEN_WIDTH * 0.5;
tipsLabel.y = uniField.bottom + FIX_SIZE(10);
[self.cardView addSubview:tipsLabel];
self.tipsLabel = tipsLabel;
PYGetSmsCodeButton *getSmsCodeButton = [PYGetSmsCodeButton smsCodeButton];
getSmsCodeButton.y = tipsLabel.bottom + FIX_SIZE(51.5);
getSmsCodeButton.centerX = tipsLabel.centerX;
WeakSelf(self);
getSmsCodeButton.getSmsWithPhoneBlock = ^NSString * _Nonnull{
return weakself.phone;
};
getSmsCodeButton.enabled = NO;
[getSmsCodeButton startTimer];
[self.cardView addSubview:getSmsCodeButton];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
#if DEBUG
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// self.uniField.text = @"1454"; // 14554
// [self unitFieldEditingChanged:self.uniField];
});
#else
#endif
[self.uniField becomeFirstResponder];
}
#pragma mark - WLUnitFieldDelegate
- (void)textDidChange:(nullable id <UITextInput>)textInput {
if (self.uniField.text.length == SMSCodeNumberCount) {
[LoginService loginByPhoneWithPhone:self.phone code:self.uniField.text completion:^(id _Nullable rsp, NSError * _Nullable error) {
if (error) {
self.tipsLabel.text = @"短信验证码错误";
[self.tipsLabel sizeToFit];
self.tipsLabel.centerX = SCREEN_WIDTH * 0.5;
self.tipsLabel.textColor = COLOR_WITH_RGB(0xFF4C73);
}
}];
}
}
- (void)selectionWillChange:(nullable id <UITextInput>)textInput {
}
- (void)selectionDidChange:(nullable id <UITextInput>)textInput {
}
- (void)textWillChange:(nullable id <UITextInput>)textInput {
}
- (BOOL)unitField:(WLUnitField *)uniField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
return YES;
}
@end