Files
2025-08-08 11:05:33 +08:00

97 lines
3.1 KiB
Objective-C
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// SPPhoneBindVC.m
// SweetParty
//
// Created by bj_szd on 2022/6/9.
//
#import "SPPhoneBindVC.h"
#import "ZWTimer.h"
@interface SPPhoneBindVC ()<ZWTimerDelegate>
@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@property (weak, nonatomic) IBOutlet UITextField *codeTF;
@property (weak, nonatomic) IBOutlet UIButton *codeBtn;
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;
@property (nonatomic, strong) ZWTimer *timer;
@property (nonatomic, assign) NSInteger leftSecond;
@end
@implementation SPPhoneBindVC
- (void)viewDidLoad {
[super viewDidLoad];
[self showNaviBarWithTitle:@"绑定手机号"];
self.phoneTF.attributedPlaceholder = [[NSMutableAttributedString alloc] initWithString:@"请输入手机号" attributes:@{NSForegroundColorAttributeName:[kWhiteColor colorWithAlphaComponent:0.6]}];
self.codeTF.attributedPlaceholder = [[NSMutableAttributedString alloc] initWithString:@"请输入验证码" attributes:@{NSForegroundColorAttributeName:[kWhiteColor colorWithAlphaComponent:0.6]}];
[self.confirmBtn setJianBianWithCGSize:CGSizeMake(ScreenWidth-27*2, 49)];
self.leftSecond = 60;
self.phoneTF.text = BJUserManager.userInfo.user_name;
}
- (IBAction)onConfirm:(id)sender {
if (self.phoneTF.text.length != 11) {
[HelpPageDefine showMessage:@"手机号格式不正确"];
return;
}
if (self.codeTF.text.length <= 0) {
[HelpPageDefine showMessage:@"请输入验证码"];
return;
}
NSDictionary *params = @{@"phone":self.phoneTF.text, @"sms_code":self.codeTF.text};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"api/user/bind_phone" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
} Failure:^(id _Nonnull errorData) {
}];
}
- (IBAction)onGetCode:(id)sender {
if (self.phoneTF.text.length != 11) {
[HelpPageDefine showMessage:@"手机号格式不正确"];
return;
}
//type 1,其他时候使用2注册时候用
NSDictionary *params = @{@"mobile":self.phoneTF.text, @"type":@"2"};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"api/login/send_sms" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
self.leftSecond = 60;
[self.timer startTimer:1 delegate:self repeats:YES];
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)onTimerFired:(ZWTimer *)timer {
NSString *str = [NSString stringWithFormat:@"%ld秒后重发", self.leftSecond];
self.codeBtn.userInteractionEnabled = NO;
self.leftSecond -= 1;
if (self.leftSecond < 0) {
str = @"获取验证码";
[self.timer stopTimer];
self.codeBtn.userInteractionEnabled = YES;
}
self.codeBtn.titleLabel.text = str;
[self.codeBtn setTitle:str forState:UIControlStateNormal];
}
- (ZWTimer *)timer {
if (!_timer) {
_timer = [[ZWTimer alloc] init];
}
return _timer;
}
@end