// // YOUPAILZVerifyPhoneWindow.m // MEISHI // // Created by CY on 2021/1/29. // Copyright © 2021 leo. All rights reserved. // #import "YOUPAILZVerifyPhoneWindow.h" #import "UIViewController+TFPresent.h" @interface YOUPAILZVerifyPhoneWindow () @property(nonatomic,strong)UITextField* youpaipphoneTextField; @property(nonatomic,assign)NSInteger youpaipphoneLength; @property(nonatomic,strong)UITextField* youpaippwdTextField; @property(nonatomic,strong)UIButton* youpaipsendVerCodeBtn; @property(nonatomic,strong)UITextField* youpaipcodeTextField; @property(nonatomic,strong)UIButton *youpaipverifyBtn; @property(nonatomic,strong)UIButton *youpaipregisterBtn; @end @implementation YOUPAILZVerifyPhoneWindow - (void)viewDidLoad { [super viewDidLoad]; self.baseView.hidden = YES; [self youpaifinitUI]; } - (void)youpaifinitUI{ UIView *bgV = [[UIView alloc] init]; bgV.backgroundColor = [UIColor whiteColor]; bgV.layer.cornerRadius = 10.0f; bgV.clipsToBounds = YES; [self.view addSubview:bgV]; [bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(31.0f); make.right.offset(-31.0f); make.centerY.equalTo(self.view); make.height.offset(389.0f); }]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(14,20,KScreenWidth-90,22)]; label.text = @"手机号绑定"; label.textAlignment = NSTextAlignmentCenter; label.textColor = HexColorFromRGB(0x333333); label.font = LCFont(19); [bgV addSubview:label]; UITextField* youpaipphoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(14,CGRectGetMaxY(label.frame)+20, KScreenWidth-90,48)]; self.youpaipphoneTextField = youpaipphoneTextField; youpaipphoneTextField.backgroundColor = ZYBGGrayColor; youpaipphoneTextField.layer.cornerRadius = 5.0; youpaipphoneTextField.layer.masksToBounds = YES; youpaipphoneTextField.tintColor = ZYPinkColor; //适配ios13 leftview sizefit UIView *leftPhoneView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,16,48)]; youpaipphoneTextField.leftView = leftPhoneView; youpaipphoneTextField.leftViewMode = UITextFieldViewModeAlways; UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 32.0f, 48)]; UIButton *clearPhoneBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0,16,48)]; clearPhoneBtn.adjustsImageWhenHighlighted = NO; [clearPhoneBtn setImage:[UIImage imageNamed:@"ic_clear"] forState:(UIControlStateNormal)]; [clearPhoneBtn addTarget:self action:@selector(youpaifclearPhoneBtnClick) forControlEvents:(UIControlEventTouchUpInside)]; [rightView addSubview:clearPhoneBtn]; youpaipphoneTextField.rightView = rightView; youpaipphoneTextField.rightViewMode = UITextFieldViewModeAlways; youpaipphoneTextField.font = LCFont(13); youpaipphoneTextField.clearButtonMode = UITextFieldViewModeWhileEditing; [[youpaipphoneTextField valueForKey:@"_clearButton"] setImage:[UIImage imageNamed:@"vqu_images_D_nick_clean"] forState:UIControlStateNormal]; youpaipphoneTextField.keyboardType = UIKeyboardTypeNumberPad; [youpaipphoneTextField addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged]; NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc]initWithString:@"请输入手机号码"]; [attrStr addAttribute:NSFontAttributeName value:LCFont(13) range:NSMakeRange(0, attrStr.length)]; [attrStr addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xCFCFCF) range:NSMakeRange(0, attrStr.length)]; youpaipphoneTextField.attributedPlaceholder = attrStr; youpaipphoneTextField.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter; [bgV addSubview:youpaipphoneTextField]; UITextField* youpaipcodeTextField = [[UITextField alloc]initWithFrame:CGRectMake(14,CGRectGetMaxY(youpaipphoneTextField.frame)+5, KScreenWidth-90, 48)]; self.youpaipcodeTextField = youpaipcodeTextField; youpaipcodeTextField.backgroundColor = ZYBGGrayColor; youpaipcodeTextField.layer.cornerRadius = 5.0f; youpaipcodeTextField.layer.masksToBounds = YES; youpaipcodeTextField.tintColor = ZYPinkColor; //适配ios13 leftview sizefit UIView *leftCodeView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,16,48)]; youpaipcodeTextField.leftView = leftCodeView; youpaipcodeTextField.leftViewMode = UITextFieldViewModeAlways; youpaipcodeTextField.clearButtonMode = UITextFieldViewModeWhileEditing; [[youpaipcodeTextField valueForKey:@"_clearButton"] setImage:[UIImage imageNamed:@"vqu_images_D_nick_clean"] forState:UIControlStateNormal]; youpaipcodeTextField.font = LCFont(13); UIView *verRightView = [[UIView alloc]initWithFrame:CGRectMake(0,0,79 + 10,48)]; UIButton* youpaipverifyBtn = [[UIButton alloc]initWithFrame:CGRectMake(0,(verRightView.mj_h - 28) / 2.0f,79,28)]; self.youpaipverifyBtn = youpaipverifyBtn; youpaipverifyBtn.layer.cornerRadius = 14; youpaipverifyBtn.layer.masksToBounds = YES; youpaipverifyBtn.backgroundColor = HexColorFromRGB(0xDDDDDD); youpaipverifyBtn.titleLabel.font = LCFont(12); [youpaipverifyBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; [youpaipverifyBtn setTitle:@"获取验证码" forState:(UIControlStateNormal)]; youpaipverifyBtn.userInteractionEnabled = NO; youpaipverifyBtn.uxy_acceptEventInterval = 3.0; [youpaipverifyBtn addTarget:self action:@selector(youpaifsendVerCodeClick) forControlEvents:(UIControlEventTouchUpInside)]; [verRightView addSubview:youpaipverifyBtn]; youpaipcodeTextField.rightView = verRightView; youpaipcodeTextField.rightViewMode = UITextFieldViewModeAlways; youpaipcodeTextField.keyboardType = UIKeyboardTypeNumberPad; [youpaipcodeTextField addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged]; NSMutableAttributedString* attrStrCode = [[NSMutableAttributedString alloc]initWithString:@"请输入验证码"]; [attrStrCode addAttribute:NSFontAttributeName value:LCFont(13) range:NSMakeRange(0, attrStrCode.length)]; [attrStrCode addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xCFCFCF) range:NSMakeRange(0, attrStrCode.length)]; youpaipcodeTextField.attributedPlaceholder = attrStrCode; youpaipcodeTextField.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter; [bgV addSubview:youpaipcodeTextField]; UITextField* youpaippwdTextField = [[UITextField alloc]initWithFrame:CGRectMake(14,CGRectGetMaxY(youpaipcodeTextField.frame)+5, KScreenWidth-90, 48)]; youpaippwdTextField.clearButtonMode = UITextFieldViewModeWhileEditing; [[youpaippwdTextField valueForKey:@"_clearButton"] setImage:[UIImage imageNamed:@"vqu_images_D_nick_clean"] forState:UIControlStateNormal]; self.youpaippwdTextField = youpaippwdTextField; youpaippwdTextField.backgroundColor = ZYBGGrayColor; youpaippwdTextField.layer.cornerRadius = 5.0f; youpaippwdTextField.layer.masksToBounds = YES; youpaippwdTextField.tintColor = ZYPinkColor; //适配ios13 leftview sizefit UIView *leftPwdView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,16,48)]; youpaippwdTextField.leftView = leftPwdView; youpaippwdTextField.leftViewMode = UITextFieldViewModeAlways; youpaippwdTextField.textColor = HexColorFromRGB(0x333333); youpaippwdTextField.font = LCFont(15); UIView *rightPwdView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 26, 48)]; UIButton* showBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0,16,48)]; showBtn.adjustsImageWhenHighlighted = NO; [showBtn setImage:[UIImage imageNamed:@"vqu_images_sign_input3"] forState:(UIControlStateNormal)]; [showBtn addTarget:self action:@selector(youpaifshowBtnClick:) forControlEvents:(UIControlEventTouchUpInside)]; youpaippwdTextField.secureTextEntry = YES; [rightPwdView addSubview:showBtn]; youpaippwdTextField.rightView = rightPwdView; youpaippwdTextField.rightViewMode = UITextFieldViewModeAlways; [youpaippwdTextField addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged]; NSMutableAttributedString* attrStrPwd = [[NSMutableAttributedString alloc]initWithString:@"请输入账户密码"]; [attrStrPwd addAttribute:NSFontAttributeName value:LCFont(15) range:NSMakeRange(0, attrStrPwd.length)]; [attrStrPwd addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xCFCFCF) range:NSMakeRange(0, attrStrPwd.length)]; youpaippwdTextField.attributedPlaceholder = attrStrPwd; youpaippwdTextField.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter; [bgV addSubview:youpaippwdTextField]; UIButton* registerBtn = [[UIButton alloc]init]; self.youpaipregisterBtn = registerBtn; registerBtn.userInteractionEnabled = NO; registerBtn.backgroundColor = HexColorFromRGB(0xCCCCCC); registerBtn.layer.cornerRadius = 5.0f; registerBtn.layer.masksToBounds = YES; registerBtn.titleLabel.font = LCFont17; [registerBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; [registerBtn setTitle:@"确定" forState:(UIControlStateNormal)]; [registerBtn addTarget:self action:@selector(youpaifloginBtnClick) forControlEvents:(UIControlEventTouchUpInside)]; registerBtn.uxy_acceptEventInterval = 3.0; [bgV addSubview:registerBtn]; [registerBtn makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(youpaippwdTextField.bottom).offset(30); make.centerX.equalTo(self.view.centerX); make.size.mas_equalTo(CGSizeMake(KScreenWidth-90, 48)); }]; UILabel *detailL= [[UILabel alloc] init]; detailL.text = @"尊敬的用户,为保障您的账号安全,请绑定手机号码,绑定后可通过手机号+密码登录账号。如需帮助,请联系在线客服!"; detailL.font = LCFont(11.0f); detailL.textColor = LCTextGray; detailL.numberOfLines = 0; [bgV addSubview:detailL]; [detailL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(14.0f); make.right.offset(-14.0f); make.bottom.offset(-20.0f); }]; } - (void)youpaifclearPhoneBtnClick{ self.youpaipphoneTextField.text = @""; [self textFieldDidEditing:self.youpaipphoneTextField]; } //监听输入的手机号码自动添加空格 -(void)textFieldDidEditing:(UITextField *)textField{ if ([self.youpaipphoneTextField.text isEqualToString:@""] || [self.youpaippwdTextField.text isEqualToString:@""]|| [self.youpaipcodeTextField.text isEqualToString:@""]){ self.youpaipregisterBtn.backgroundColor = LCGray; [self.youpaipregisterBtn setBackgroundImage:nil forState:(UIControlStateNormal)]; self.youpaipregisterBtn.userInteractionEnabled = NO; }else{ [self.youpaipregisterBtn setBackgroundImage:[LCTools ColorImage:self.youpaipregisterBtn.frame.size FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)]; self.youpaipregisterBtn.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 setBackgroundColor:ZYPinkColor]; [self.youpaipverifyBtn setTitleColor:HexColorFromRGB(0xffffff) 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.userInteractionEnabled = NO; [self.youpaipverifyBtn setTitleColor:HexColorFromRGB(0x999999) forState:(UIControlStateNormal)]; self.youpaipphoneLength = textField.text.length; } } } // 发送验证码 -(void)youpaifsendVerCodeClick { NSString *phoneText = [self.youpaipphoneTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""]; if ([ZCRegularHelper regularPhoneNumber:phoneText]) {//首先手机格式保证正确 WeakSelf; [LCHttpHelper requestWithURLString:PhoneCode parameters:@{@"mobile":phoneText,@"type":@"bind"} needToken:NO type:(HttpRequestTypePost) success:^(id responseObject) { 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(), ^{ [weakSelf.youpaipverifyBtn setTitle:@"获取验证码" forState:UIControlStateNormal]; weakSelf.youpaipverifyBtn.userInteractionEnabled = YES; }); }else{ NSString *strTime = [NSString stringWithFormat:@"%.2dS",timeout]; dispatch_async(dispatch_get_main_queue(), ^{ //设置界面的按钮显示 根据自己需求设置 [weakSelf.youpaipverifyBtn setTitle:strTime forState:UIControlStateNormal]; weakSelf.youpaipverifyBtn.userInteractionEnabled = NO; }); timeout--; } }); dispatch_resume(_timer); } } 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)youpaifloginBtnClick{ __block 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.youpaippwdTextField.text forKey:@"password"]; WeakSelf; [LCHttpHelper requestWithURLString:BindPhone parameters:params needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0 && weakSelf.block) {//成功 [weakSelf dismissViewControllerAnimated:YES completion:^{ weakSelf.block(phoneText); }]; }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } } } @end