// // YOUPAILPYoungForgetPWD.m // livePro // // Created by leo on 2019/12/27. // Copyright © 2019 caiPro. All rights reserved. // #import "YOUPAILPYoungForgetPWD.h" #import "YMCaptchaPopupView.h" @interface YOUPAILPYoungForgetPWD () @property(nonatomic,strong)UITextField* youpaipphoneTextField,*youpaippwdTextField; @property(nonatomic,assign)NSInteger youpaipphoneLength; @property(nonatomic,strong)UITextField* youpaipcodeTextField; @property(nonatomic,strong)UIButton* youpaiploginBtn; @property(nonatomic,strong)UIButton* youpaipverifyBtn; @property(nonatomic,strong)dispatch_source_t youpaipcodeTimer; @end @implementation YOUPAILPYoungForgetPWD - (void)viewDidLoad { [super viewDidLoad]; self.title = @"关闭未成年模式"; self.youpaipphoneLength = 0; [self youpaifsetupView]; self.view.backgroundColor = [UIColor whiteColor]; } - (void)youpaifsetupView{ UIScrollView* scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight)]; scrollView.contentSize = CGSizeMake(KScreenWidth, KScreenHeight-NavBarHeight+1); scrollView.bounces = YES; scrollView.showsHorizontalScrollIndicator = NO; scrollView.showsVerticalScrollIndicator = NO; scrollView.delegate = self; [self.view addSubview:scrollView]; UITextField* phoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(27, 27, KScreenWidth-54, 56)]; self.youpaipphoneTextField = phoneTextField; phoneTextField.layer.cornerRadius = 28.0f; phoneTextField.clipsToBounds = YES; phoneTextField.backgroundColor = LZF7F8FAColor; phoneTextField.textColor = LZ273145Color; phoneTextField.tintColor = LZ7C69FEColor; UIView *phoneTipV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 28+53+12, 56)]; UILabel* phoneTipLabel = [[UILabel alloc]initWithFrame:CGRectMake(28, 0, 53, 56)]; phoneTipLabel.text = @"手机号"; phoneTipLabel.textColor = LZ273145Color; phoneTipLabel.font = LCFont17; phoneTipLabel.textAlignment = NSTextAlignmentLeft; [phoneTipV addSubview:phoneTipLabel]; phoneTextField.leftView = phoneTipV; phoneTextField.leftViewMode = UITextFieldViewModeAlways; phoneTextField.clearButtonMode = UITextFieldViewModeWhileEditing; [[phoneTextField valueForKey:@"_clearButton"] setImage:[UIImage imageNamed:@"vqu_images_D_nick_clean"] forState:UIControlStateNormal]; phoneTextField.keyboardType = UIKeyboardTypeNumberPad; [phoneTextField addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged]; NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc]initWithString:@"请输入手机号码"]; [attrStr addAttribute:NSFontAttributeName value:LCFont17 range:NSMakeRange(0, attrStr.length)]; [attrStr addAttribute:NSForegroundColorAttributeName value:LZD3D1D7Color range:NSMakeRange(0, attrStr.length)]; phoneTextField.attributedPlaceholder = attrStr; phoneTextField.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter; [scrollView addSubview:phoneTextField]; UITextField* codeTextField = [[UITextField alloc]initWithFrame:CGRectMake(27, CGRectGetMaxY(phoneTextField.frame) + 14.0f, KScreenWidth-54, 56)]; self.youpaipcodeTextField = codeTextField; codeTextField.layer.cornerRadius = 28.0f; codeTextField.clipsToBounds = YES; codeTextField.backgroundColor = LZF7F8FAColor; codeTextField.textColor = LZ273145Color; codeTextField.tintColor = LZ7C69FEColor; UIView *codeTipLV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 28+53+12, 56)]; UILabel* codeTipLabel = [[UILabel alloc]initWithFrame:CGRectMake(28, 0, 53, 56)]; codeTipLabel.text = @"验证码"; codeTipLabel.textColor = LZ273145Color; codeTipLabel.font =LCFont17; codeTipLabel.textAlignment = NSTextAlignmentLeft; [codeTipLV addSubview:codeTipLabel]; codeTextField.leftView = codeTipLV; codeTextField.leftViewMode = UITextFieldViewModeAlways; UIView* rightview = [[UIView alloc]initWithFrame:CGRectMake(0, 0,107, 56)]; UIButton* verifyBtn = [[UIButton alloc]initWithFrame:CGRectMake(14.0f, 14.0f, 79.0f, 28.0f)]; self.youpaipverifyBtn = verifyBtn; verifyBtn.layer.cornerRadius = 14.0f; verifyBtn.layer.masksToBounds = YES; verifyBtn.backgroundColor = LZD3D1D7Color; verifyBtn.titleLabel.font = LCFont12; [verifyBtn setTitleColor:LZ273145Color forState:(UIControlStateNormal)]; [verifyBtn setTitle:@"获取验证码" forState:(UIControlStateNormal)]; verifyBtn.userInteractionEnabled = NO; [verifyBtn addTarget:self action:@selector(youpaifverifyBtnClick) forControlEvents:(UIControlEventTouchUpInside)]; [rightview addSubview:verifyBtn]; codeTextField.rightView = rightview; codeTextField.rightViewMode = UITextFieldViewModeAlways; codeTextField.keyboardType = UIKeyboardTypeNumberPad; [codeTextField addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged]; NSMutableAttributedString* attrStrCode = [[NSMutableAttributedString alloc]initWithString:@"短信验证码"]; [attrStrCode addAttribute:NSFontAttributeName value:LCFont17 range:NSMakeRange(0, attrStrCode.length)]; [attrStrCode addAttribute:NSForegroundColorAttributeName value:LZD3D1D7Color range:NSMakeRange(0, attrStrCode.length)]; codeTextField.attributedPlaceholder = attrStrCode; codeTextField.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter; [scrollView addSubview:codeTextField]; UIButton* loginBtn = [[UIButton alloc]init]; self.youpaiploginBtn = loginBtn; loginBtn.userInteractionEnabled = NO; loginBtn.backgroundColor = LZD3D1D7Color; loginBtn.layer.cornerRadius = 28.0; loginBtn.layer.masksToBounds = YES; loginBtn.titleLabel.font = LCFont17; [loginBtn setTitleColor:LZ273145Color forState:(UIControlStateNormal)]; [loginBtn setTitle:@"关闭未成年模式" forState:(UIControlStateNormal)]; [loginBtn addTarget:self action:@selector(youpaifloginBtnClick) forControlEvents:(UIControlEventTouchUpInside)]; [scrollView addSubview:loginBtn]; [loginBtn makeConstraints:^(MASConstraintMaker *make) { make.top.offset(KScreenHeight-100-SafeHeight-56.0f-NavBarHeight); make.centerX.equalTo(self.view.mas_centerX); make.size.mas_equalTo(CGSizeMake(KScreenWidth-54.0f, 56.0f)); }]; } //监听输入的手机号码自动添加空格 -(void)textFieldDidEditing:(UITextField *)textField{ if ([self.youpaipphoneTextField.text isEqualToString:@""] || [self.youpaipcodeTextField.text isEqualToString:@""]|| [self.youpaippwdTextField.text isEqualToString:@""]){ self.youpaiploginBtn.backgroundColor = LZD3D1D7Color; [self.youpaiploginBtn setTitleColor:LZ273145Color forState:UIControlStateNormal]; [self.youpaiploginBtn setBackgroundImage:nil forState:(UIControlStateNormal)]; self.youpaiploginBtn.userInteractionEnabled = NO; }else{ [self.youpaiploginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [self.youpaiploginBtn setBackgroundImage:[LCTools ColorImage:self.youpaiploginBtn.frame.size FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)]; self.youpaiploginBtn.userInteractionEnabled = YES;; } if (textField == self.youpaipphoneTextField) { if (textField.text.length > self.youpaipphoneLength) { if (textField.text.length == 4 || textField.text.length == 9 ) {//输入 NSMutableString * str = [[NSMutableString alloc ] initWithString:textField.text]; [str insertString:@" " atIndex:(textField.text.length-1)]; textField.text = str; }if (textField.text.length >= 13 ) {//输入完成 textField.text = [textField.text substringToIndex:13]; self.youpaipverifyBtn.userInteractionEnabled = YES; [self.youpaipverifyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [self.youpaipverifyBtn setBackgroundImage:[LCTools ColorImage:self.youpaipverifyBtn.frame.size FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)]; } self.youpaipphoneLength = textField.text.length; }else if (textField.text.length < self.youpaipphoneLength){//删除 if (textField.text.length == 4 || textField.text.length == 9) { textField.text = [NSString stringWithFormat:@"%@",textField.text]; textField.text = [textField.text substringToIndex:(textField.text.length-1)]; } [self.youpaipverifyBtn setTitleColor:LZ273145Color forState:UIControlStateNormal]; self.youpaipverifyBtn.userInteractionEnabled = NO; [self.youpaipverifyBtn setBackgroundImage:nil forState:(UIControlStateNormal)]; self.youpaipphoneLength = textField.text.length; } } } - (void)youpaifverifyBtnClick{ NSString *phoneText = [self.youpaipphoneTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""]; if ([ZCRegularHelper regularPhoneNumber:phoneText]) {//首先手机格式保证正确 YMCaptchaPopupView *view = [[YMCaptchaPopupView alloc] init]; view.cancelButtonTappedBlock = ^{}; @weakify(self) view.confirmButtonTappedBlock = ^(NSString * _Nonnull input) { @strongify(self) @weakify(self) [LCHttpHelper requestWithURLString:PhoneCode parameters:@{@"captcha":input, @"mobile":phoneText,@"type":@"forget"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [ZCHUDHelper showTitle:@"验证码已发送"]; __block int timeout=120; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue); dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行 dispatch_source_set_event_handler(_timer, ^{ if(timeout<=0){ dispatch_source_cancel(_timer); dispatch_async(dispatch_get_main_queue(), ^{ [self.youpaipverifyBtn setTitle:@"获取验证码" forState:UIControlStateNormal]; self.youpaipverifyBtn.userInteractionEnabled = YES; }); }else{ NSString *strTime = [NSString stringWithFormat:@"%.2dS",timeout]; dispatch_async(dispatch_get_main_queue(), ^{ //设置界面的按钮显示 根据自己需求设置 [self.youpaipverifyBtn setTitle:strTime forState:UIControlStateNormal]; self.youpaipverifyBtn.userInteractionEnabled = NO; }); timeout--; } }); dispatch_resume(_timer); } } failure:^(NSError *error) { }]; }; UIView *currentVCView = [LCTools getCurrentVC].view; if (currentVCView != nil && ![currentVCView isEqual:NSNull.null]) { [view showInView:currentVCView]; } } } - (void)youpaifloginBtnClick{ NSString *phoneText = [self.youpaipphoneTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""]; if ([ZCRegularHelper regularPhoneNumber:phoneText]) { if ([ZCRegularHelper regularVerifyCode4:self.youpaipcodeTextField.text]) { NSMutableDictionary* params = [NSMutableDictionary dictionary]; [params setObject:phoneText forKey:@"mobile"]; [params setObject:self.youpaipcodeTextField.text forKey:@"phone_code"]; // [params setObject:self.pwdTextField.text forKey:@"password"]; //password [LCHttpHelper requestWithURLString:VerifyMobileCode parameters:params needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [_youpaipdelegate youpaifswitchYounModel:0]; [self.navigationController popToRootViewControllerAnimated:YES]; } } failure:^(NSError *error) { }]; } } } -(void)youpaifshowBtnClick:(UIButton*)btn{ if (btn.selected) { btn.selected = NO; [btn setImage:[UIImage imageNamed:@"vqu_images_sign_input3"] forState:(UIControlStateNormal)]; self.youpaippwdTextField.secureTextEntry = YES; }else{ btn.selected = YES; [btn setImage:[UIImage imageNamed:@"vqu_images_sign_input2"] forState:(UIControlStateNormal)]; self.youpaippwdTextField.secureTextEntry = NO; } } - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ [self.view endEditing:YES]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end