// // PassWordResetVC.m // GIGA // // Created by lianxiang on 2018/8/21. // Copyright © 2018年 com.giga.ios. All rights reserved. // #import "PassWordResetVC.h" #import "NSTimer+Convenience.h" #import "GiGaBaseAPiRequest.h" @interface PassWordResetVC () @property (weak, nonatomic) IBOutlet UITextField *phoneNumberTextField; @property (weak, nonatomic) IBOutlet UITextField *codeTextField; @property (weak, nonatomic) IBOutlet UIButton *codeSendBtn; @property (weak, nonatomic) IBOutlet UITextField *passNewTextField; @property (weak, nonatomic) IBOutlet UIButton *confirmBtn; @property(nonatomic,strong) NSTimer*timer; @property(nonatomic) NSInteger time; @end @implementation PassWordResetVC - (void)viewDidLoad { [super viewDidLoad]; //self.title = @"重置密码"; [self addNavTitile:@"重置密码"]; [self confirmUI]; _time = 60; [self.codeSendBtn addTarget:self action:@selector(codeSendBtnAction:) forControlEvents:UIControlEventTouchUpInside]; [self.confirmBtn addTarget:self action:@selector(confirmBtnAction:) forControlEvents:UIControlEventTouchUpInside]; } -(void)confirmUI{ UIView *phoneView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; UIImageView *phoneIcon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 9, 12, 22)]; phoneIcon.image = [UIImage imageNamed:@"ic_number"]; [phoneView addSubview:phoneIcon]; self.phoneNumberTextField.leftView = phoneView; self.phoneNumberTextField.leftViewMode = UITextFieldViewModeAlways; UIView *codeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; UIImageView *codeIcon = [[UIImageView alloc] initWithFrame:CGRectMake(11,13.5, 18, 13)]; codeIcon.image = [UIImage imageNamed:@"ic_note"]; [codeView addSubview:codeIcon]; self.codeTextField.leftView = codeView; self.codeTextField.leftViewMode = UITextFieldViewModeAlways; UIView *passView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; UIImageView *passIcon = [[UIImageView alloc] initWithFrame:CGRectMake(15,10, 12, 22)]; passIcon.image = [UIImage imageNamed:@"icon_key"]; [passView addSubview:passIcon]; self.passNewTextField.leftView = passView; self.passNewTextField.leftViewMode = UITextFieldViewModeAlways; self.confirmBtn.layer.masksToBounds = YES; self.confirmBtn.layer.cornerRadius = self.confirmBtn.frame.size.height / 2; } #pragma mark - 发送短信 //短信发送 -(void)codeSendBtnAction:(UIButton *)btn{ if (self.phoneNumberTextField.text.length == 0) { GIGA_ShowToast(@"请输入手机号"); return; } if (![GiGaHelper isPhoneNumber:self.phoneNumberTextField.text]) { GIGA_ShowToast(@"请输入正确手机号"); return; } btn.userInteractionEnabled = NO; [self startTimer:btn]; [self requstCode:btn]; } //计时 -(void)startTimer:(UIButton *)btn{ if (_time>0) { _timer = [NSTimer scheduledTimerWithTimeInterval:1 count:60 callback:^{ NSString *timeStr=[NSString stringWithFormat:@"%lds",(long)self->_time]; [btn setTitle:timeStr forState:UIControlStateNormal]; self->_time--; if (self->_time==0) { [self.codeSendBtn setTitle:@"发送验证码" forState:UIControlStateNormal]; self->_time =60; btn.userInteractionEnabled = YES; } }]; [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; } } //获取验证码请求 -(void)requstCode:(UIButton *)btn{ if (self.phoneNumberTextField.text.length == 0) { GIGA_ShowToast(@"请输入手机号"); return; } if (![GiGaHelper isPhoneNumber:self.phoneNumberTextField.text]) { GIGA_ShowToast(@"请输入正确手机号"); return; } [self.view makeToastActivity:CSToastPositionCenter]; NSDictionary *params = @{@"mobile":self.phoneNumberTextField.text}; GiGaBaseAPiRequest *requst = [GiGaBaseAPiRequest initWithRequestPath:@"msg/sms/v1/retrievesendcode" method:RequestPostMethod parms:params]; [requst requstDataWithResult:^(GiGaAPIResult *result) { btn.userInteractionEnabled = YES; [self.view hideToastActivity]; GIGA_ShowToast(result.message); }]; } #pragma mark - 确认 -(void)confirmBtnAction:(UIButton *)btn{ if (self.phoneNumberTextField.text.length == 0) { GIGA_ShowToast(@"请输入手机号"); return; } if (![GiGaHelper isPhoneNumber:self.phoneNumberTextField.text]) { GIGA_ShowToast(@"请输入正确手机号"); return; } if (self.codeTextField.text.length == 0) { GIGA_ShowToast(@"请输入验证码"); return; } if (self.passNewTextField.text.length == 0) { GIGA_ShowToast(@"请输入新密码"); return; } if (!(self.passNewTextField.text.length >= 6 && self.passNewTextField.text.length <= 20)) { GIGA_ShowToast(@"请输入6~20位新密码"); return; } btn.userInteractionEnabled = NO; [self.view makeToastActivity:CSToastPositionCenter]; NSDictionary *params = @{ @"username":self.phoneNumberTextField.text, @"password":self.passNewTextField.text, @"verifiedCode":self.codeTextField.text }; GiGaBaseAPiRequest *requst = [GiGaBaseAPiRequest initWithRequestPath:@"sys/v1/retrievepwd" method:RequestPostMethod parms:params]; [requst requstDataWithResult:^(GiGaAPIResult *result) { [self.view hideToastActivity]; btn.userInteractionEnabled = YES; if (result.success) { GIGA_WIndowTost(result.message); [self.navigationController popViewControllerAnimated:YES]; } }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)dealloc{ if (_timer) { [_timer unfireTimer]; [_timer invalidate]; _timer = nil; } } @end