// // MMMessageVerificationVC.m // MingMen // // Created by 肖雨 on 2017/3/11. // Copyright © 2017年 肖雨. All rights reserved. // #import "NewForgotPasswordViewController.h" #import "NewRegistCell.h" @interface NewForgotPasswordViewController () { NSMutableArray *dataArray; UIButton *verificationCodeButton; UIButton *confirm2; NSString *yonghutype; } @property (strong ,nonatomic) UITextField * account; @property (strong ,nonatomic) UITextField * iphoneNumber; @property (strong ,nonatomic) UITextField * yanzhenma; @property (strong ,nonatomic) UITextField * password; @property (strong ,nonatomic) UITextField * querenpassword; @property (strong ,nonatomic) UIButton * yhtypeStr; @end @implementation NewForgotPasswordViewController -(void)dealloc { NSLog(@"找回密码界面销毁"); } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self setNavTitle:@"忘记密码"]; [self dataInitialization]; [self loadsView]; } #pragma mark - 数据初始化 -(void)dataInitialization { verificationCodeButton = nil; yonghutype = @"请选择用户类型"; } #pragma mark - UI初始化 -(void)loadsView { UIImageView *backimage = [UIImageView new]; [backimage setImage:[UIImage imageNamed:@"dlbj"]]; backimage.backgroundColor = NewClearColor; backimage.userInteractionEnabled = YES; [self.view addSubview:backimage]; backimage.sd_layout .leftEqualToView(self.view) .topEqualToView(self.view) .bottomEqualToView(self.view) .rightEqualToView(self.view); UIButton *fanhuiBT = [UIButton new]; [fanhuiBT setBackgroundImage:NewImageNamed(@"fh") forState:UIControlStateNormal]; NewTouchUpInside(fanhuiBT, fanhuiBTclick:); [backimage addSubview:fanhuiBT]; fanhuiBT.sd_layout .leftSpaceToView(backimage, 17) .topSpaceToView(backimage, 32) .heightIs(21) .widthIs(11); UIImageView *logoimage = [UIImageView new]; [logoimage setImage:[UIImage imageNamed:@"logo"]]; logoimage.backgroundColor = NewClearColor; [backimage addSubview:logoimage]; logoimage.sd_layout .centerXEqualToView(backimage) .topSpaceToView(backimage, fitScreenHeight(90)) .heightIs(fitScreenWidth(80)) .widthIs(fitScreenWidth(80)); //用户名 UIView *usernameview = [UIView new]; usernameview.backgroundColor = [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1]; usernameview.userInteractionEnabled = YES; ViewRadius(usernameview, 5); // [backimage addSubview:usernameview]; usernameview.sd_layout .leftSpaceToView(backimage, 45) .rightSpaceToView(backimage, 45) .heightIs(45) .topSpaceToView(logoimage, fitScreenHeight(65)); UIImageView *usernameimage = [UIImageView new]; [usernameimage setImage:[UIImage imageNamed:@"yh"]]; [usernameimage setBackgroundColor:NewClearColor]; [usernameview addSubview:usernameimage]; usernameimage.sd_layout .centerYEqualToView(usernameview) .leftSpaceToView(usernameview, 15) .heightIs(16) .widthIs(16); [usernameview addSubview:self.account]; _account.sd_layout .leftSpaceToView(usernameimage, 15) .heightIs(30) .centerYEqualToView(usernameview) .rightSpaceToView(usernameview, 15); //手机号码 UIView *iponeNumView = [UIView new]; iponeNumView.backgroundColor = [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1]; iponeNumView.userInteractionEnabled = YES; ViewRadius(iponeNumView, 5); [backimage addSubview:iponeNumView]; iponeNumView.sd_layout .leftSpaceToView(backimage, 45) .rightSpaceToView(backimage, 45) .heightIs(45) .topSpaceToView(logoimage, fitScreenHeight(65)); UIImageView *iponeNumimage = [UIImageView new]; [iponeNumimage setImage:[UIImage imageNamed:@"sj"]]; [iponeNumimage setBackgroundColor:NewClearColor]; [iponeNumView addSubview:iponeNumimage]; iponeNumimage.sd_layout .centerYEqualToView(iponeNumView) .leftSpaceToView(iponeNumView, 15) .heightIs(20) .widthIs(17); [iponeNumView addSubview:self.iphoneNumber]; _iphoneNumber.sd_layout .leftSpaceToView(iponeNumimage, 15) .heightIs(30) .centerYEqualToView(iponeNumimage) .rightSpaceToView(iponeNumView, 15); //验证码 UIView *yanzhenmaView = [UIView new]; yanzhenmaView.backgroundColor = [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1]; yanzhenmaView.userInteractionEnabled = YES; ViewRadius(yanzhenmaView, 5); [backimage addSubview:yanzhenmaView]; yanzhenmaView.sd_layout .leftSpaceToView(backimage, 45) .rightSpaceToView(backimage, 45) .heightIs(45) .topSpaceToView(iponeNumView, 15); UIImageView *yanzhenmaimage = [UIImageView new]; [yanzhenmaimage setImage:[UIImage imageNamed:@"yz"]]; [yanzhenmaimage setBackgroundColor:NewClearColor]; [yanzhenmaView addSubview:yanzhenmaimage]; yanzhenmaimage.sd_layout .centerYEqualToView(yanzhenmaView) .leftSpaceToView(yanzhenmaView, 15) .heightIs(20) .widthIs(18); [yanzhenmaView addSubview:self.yanzhenma]; self.yanzhenma.sd_layout .leftSpaceToView(yanzhenmaimage, 15) .heightIs(30) .centerYEqualToView(yanzhenmaimage) .rightSpaceToView(yanzhenmaView, 80); verificationCodeButton = [UIButton new]; [verificationCodeButton setTitle:@"获取验证码" forState:UIControlStateNormal]; [verificationCodeButton setTitleColor:[UIColor colorWithString:@"#2987DE"] forState:UIControlStateNormal]; verificationCodeButton.titleLabel.font = NewFont(13); verificationCodeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; NewTouchUpInside(verificationCodeButton, touchVerificationCode:); [yanzhenmaView addSubview:verificationCodeButton]; verificationCodeButton.sd_layout .centerYEqualToView(yanzhenmaView) .rightSpaceToView(yanzhenmaView, 10) .heightIs(15) .widthIs(80); //第一次密码 UIView *passwordView = [UIView new]; passwordView.backgroundColor = [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1]; passwordView.userInteractionEnabled = YES; ViewRadius(passwordView, 5); [backimage addSubview:passwordView]; passwordView.sd_layout .leftSpaceToView(backimage, 45) .rightSpaceToView(backimage, 45) .heightIs(45) .topSpaceToView(yanzhenmaView, 15); UIImageView *passwordimage = [UIImageView new]; [passwordimage setImage:[UIImage imageNamed:@"mm"]]; [passwordimage setBackgroundColor:NewClearColor]; [passwordView addSubview:passwordimage]; passwordimage.sd_layout .centerYEqualToView(passwordView) .leftSpaceToView(passwordView, 15) .heightIs(19) .widthIs(16); [passwordView addSubview:self.password]; _password.sd_layout .leftSpaceToView(passwordimage, 15) .heightIs(30) .centerYEqualToView(passwordimage) .rightSpaceToView(passwordView, 15); //第二次密码 UIView *querenpasswordView = [UIView new]; querenpasswordView.backgroundColor = [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1]; querenpasswordView.userInteractionEnabled = YES; ViewRadius(querenpasswordView, 5); [backimage addSubview:querenpasswordView]; querenpasswordView.sd_layout .leftSpaceToView(backimage, 45) .rightSpaceToView(backimage, 45) .heightIs(45) .topSpaceToView(passwordView, 15); UIImageView *querenpasswordimage = [UIImageView new]; [querenpasswordimage setImage:[UIImage imageNamed:@"qr"]]; [querenpasswordimage setBackgroundColor:NewClearColor]; [querenpasswordView addSubview:querenpasswordimage]; querenpasswordimage.sd_layout .centerYEqualToView(querenpasswordView) .leftSpaceToView(querenpasswordView, 15) .heightIs(19) .widthIs(16); [querenpasswordView addSubview:self.querenpassword]; _querenpassword.sd_layout .leftSpaceToView(querenpasswordimage, 15) .heightIs(30) .centerYEqualToView(querenpasswordimage) .rightSpaceToView(querenpasswordView, 15); UIView *yhtypeView = [UIView new]; yhtypeView.backgroundColor = [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1]; yhtypeView.userInteractionEnabled = YES; ViewRadius(yhtypeView, 5); [backimage addSubview:yhtypeView]; yhtypeView.sd_layout .leftSpaceToView(backimage, 45) .rightSpaceToView(backimage, 45) .heightIs(45) .topSpaceToView(querenpasswordView, 15); UIImageView *yhtype = [UIImageView new]; [yhtype setImage:[UIImage imageNamed:@"用户类型"]]; [yhtype setBackgroundColor:NewClearColor]; [yhtypeView addSubview:yhtype]; yhtype.sd_layout .centerYEqualToView(yhtypeView) .leftSpaceToView(yhtypeView, 15) .heightIs(19) .widthIs(16); _yhtypeStr = [UIButton new]; [_yhtypeStr setTitle:yonghutype forState:UIControlStateNormal]; [_yhtypeStr setTitleColor:[UIColor colorWithString:@"#9A9A9A"] forState:UIControlStateNormal]; _yhtypeStr.titleLabel.font = NewFont(fitScreenWidth(12)); NewTouchUpInside(_yhtypeStr, yhbuttoncilck); _yhtypeStr.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [yhtypeView addSubview:_yhtypeStr]; self.yhtypeStr.sd_layout .leftSpaceToView(yhtype, 15) .heightIs(30) .centerYEqualToView(yhtype) .rightSpaceToView(yhtypeView, 15); [backimage addSubview:confirm2 = [NewControlPackage buttonInitWithTitle:@"确 定" Frame:CGRectMake(0, 0, 0, 0) backgroundImage:nil backgroundImageHighlighted:nil backgroundColor:NewButtonColor textColor:NewWhiteColor textAlignment:UIControlContentHorizontalAlignmentCenter font:NewFont(14) tag:105 target:self action:@selector(touchConfirm) hidden:NO userInteractionEnabled:YES]]; ViewRadius(confirm2, 8); confirm2.sd_layout .leftEqualToView(querenpasswordView) .bottomSpaceToView(backimage, 35) .heightIs(40) .rightEqualToView(querenpasswordView); } - (UITextField *)account { if (!_account) { _account = [UITextField new]; [_account setBackgroundColor:[UIColor clearColor]]; [_account setTextColor:NewGrayColor]; [_account setPlaceholder:@"请输入用户名"]; [_account setText:@""]; [_account setFont:[UIFont systemFontOfSize:fitScreenWidth(12)]]; [_account setSecureTextEntry:NO]; [_account setKeyboardType:UIKeyboardTypeNumberPad]; [_account setReturnKeyType:UIReturnKeyDefault]; [_account addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged]; } return _account; } - (UITextField *)password { if (!_password) { _password = [UITextField new]; [_password setBackgroundColor:[UIColor clearColor]]; [_password setTextColor:[UIColor colorWithString:@"#9A9A9A"]]; [_password setPlaceholder:@"请输入密码"]; [_password setText:@""]; [_password setFont:[UIFont systemFontOfSize:fitScreenWidth(12)]]; [_password setSecureTextEntry:YES]; [_password setKeyboardType:UIKeyboardTypeDefault]; [_password setReturnKeyType:UIReturnKeyDefault]; [_password addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged]; } return _password; } - (UITextField *)yanzhenma { if (!_yanzhenma) { _yanzhenma = [UITextField new]; [_yanzhenma setBackgroundColor:[UIColor clearColor]]; [_yanzhenma setTextColor:[UIColor colorWithString:@"#9A9A9A"]]; [_yanzhenma setPlaceholder:@"请输入验证码"]; [_yanzhenma setText:@""]; [_yanzhenma setFont:[UIFont systemFontOfSize:fitScreenWidth(12)]]; [_yanzhenma setSecureTextEntry:NO]; [_yanzhenma setKeyboardType:UIKeyboardTypeDefault]; [_yanzhenma setReturnKeyType:UIReturnKeyDefault]; [_yanzhenma addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged]; } return _yanzhenma; } - (UITextField *)iphoneNumber { if (!_iphoneNumber) { _iphoneNumber = [UITextField new]; [_iphoneNumber setBackgroundColor:[UIColor clearColor]]; [_iphoneNumber setTextColor:[UIColor colorWithString:@"#9A9A9A"]]; [_iphoneNumber setPlaceholder:@"请输入手机号码"]; [_iphoneNumber setText:@""]; [_iphoneNumber setFont:[UIFont systemFontOfSize:fitScreenWidth(12)]]; [_iphoneNumber setSecureTextEntry:NO]; [_iphoneNumber setKeyboardType:UIKeyboardTypeDefault]; [_iphoneNumber setReturnKeyType:UIReturnKeyDefault]; [_iphoneNumber addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged]; } return _iphoneNumber; } - (UITextField *)querenpassword { if (!_querenpassword) { _querenpassword = [UITextField new]; [_querenpassword setBackgroundColor:[UIColor clearColor]]; [_querenpassword setTextColor:[UIColor colorWithString:@"#9A9A9A"]]; [_querenpassword setPlaceholder:@"请确认新密码"]; [_querenpassword setText:@""]; [_querenpassword setFont:[UIFont systemFontOfSize:fitScreenWidth(12)]]; [_querenpassword setSecureTextEntry:YES]; [_querenpassword setKeyboardType:UIKeyboardTypeDefault]; [_querenpassword setReturnKeyType:UIReturnKeyDefault]; [_querenpassword addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged]; } return _querenpassword; } #pragma mark - 作字符输入限制 - (void)textFieldEditingChanged:(UITextField *)textField { /* @property (strong ,nonatomic) UITextField * account; @property (strong ,nonatomic) UITextField * iphoneNumber; @property (strong ,nonatomic) UITextField * yanzhenma; @property (strong ,nonatomic) UITextField * Customer; @property (strong ,nonatomic) UITextField * password; @property (strong ,nonatomic) UITextField * querenpassword; */ if (textField == self.iphoneNumber) { if ([textField.text length]>11) { textField.text=[textField.text substringToIndex:11];//手机号码11位 } }else if (textField == self.yanzhenma) { if ([textField.text length]>6) { textField.text=[textField.text substringToIndex:6];//验证码4位 } }else if (textField == self.account) { if ([textField.text length]>6) { textField.text=[textField.text substringToIndex:6];//用户名 } }else if (textField == self.password) { if ([textField.text length]>20) { textField.text=[textField.text substringToIndex:20];//第一次密码最多20位 } }else if (textField == self.querenpassword) { if ([textField.text length]>20) { textField.text=[textField.text substringToIndex:20];//第二次密码最多20位 } } } #pragma mark - 获取验证码 - (void)touchVerificationCode:(UIButton *)sender { if (![self verification:@"校验手机号"]) { return; } [MBProgressHUD showLoadToView:self.view title:@"请稍后..."]; verificationCodeButton.sd_layout .widthIs(fitScreenWidth(100)); [MBProgressHUD showSuccess:@"短信已发送" toView:self.view]; sender.frame = CGRectMake(sender.left, sender.top, 80, sender.height); [self verificationCode:60 sender:sender]; return; NSMutableDictionary *parameters = NewMutableDictionaryInit; [parameters safeSetObject:self.iphoneNumber.text forKey:@"mobile"];//手机号码 [parameters safeSetObject:@"0" forKey:@"type"];// [NetworkRequestManager requestGetWithInterfacePrefix:JT_getResetMCode parameters:parameters onSuccess:^(id requestdict) { [MBProgressHUD hideHUDForView:self.view]; if ([requestdict[@"error"] count] !=0) { for (NSDictionary *dic in requestdict[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; verificationCodeButton.sd_layout .widthIs(fitScreenWidth(66)); } }else{ verificationCodeButton.sd_layout .widthIs(fitScreenWidth(100)); [MBProgressHUD showSuccess:@"短信已发送" toView:self.view]; sender.frame = CGRectMake(sender.left, sender.top, 80, sender.height); [self verificationCode:60 sender:sender]; } } onFailure:^{ [MBProgressHUD hideHUDForView:self.view]; }]; } - (BOOL)verification:(NSString *)status { if ([status isEqualToString:@"校验手机号"]) { if (self.iphoneNumber.text.length <= 0) { [self.view makeToast:@"请输入手机号码" duration:1.0 position:CSToastPositionCenter]; return NO; }else if (self.iphoneNumber.text.length < 11){ [self.view makeToast:@"手机号码输入有误" duration:1.0 position:CSToastPositionCenter]; return NO; } }else if([status isEqualToString:@"个人注册"]){ if (self.iphoneNumber.text.length < 11) { [self.view makeToast:@"手机号码输入有误" duration:1.5 position:CSToastPositionCenter]; return NO; } if (self.yanzhenma.text.length <= 0) { [self.view makeToast:@"验证码输入有误" duration:1.5 position:CSToastPositionCenter]; return NO; } if (self.password.text.length<6||self.querenpassword.text.length<6) { [self.view makeToast:@"新密码不能少于6位数" duration:1.5 position:CSToastPositionCenter]; return NO; } if (self.password.text.length < 6) { [self.view makeToast:@"新密码输入有误" duration:1.5 position:CSToastPositionCenter]; return NO; } if (self.querenpassword.text.length < 6) { [self.view makeToast:@"确认新密码输入有误" duration:1.5 position:CSToastPositionCenter]; return NO; } if (![self.password.text isEqualToString:self.querenpassword.text]) { [self.view makeToast:@"设置密码和确认密码不同" duration:1.5 position:CSToastPositionCenter]; return NO; } // if (self.account.text.length<=0) { // [self.view makeToast:@"用户名输入有误" duration:1.5 position:CSToastPositionCenter]; // return NO; // } } return YES; } - (void)verificationCode:(NSInteger)code sender:(UIButton *)sender{ NSString *str=[NSString stringWithFormat:@"%d秒后重新发送",(int)code]; [sender setTitle:str forState:UIControlStateNormal]; sender.enabled=NO; if (code==0) { sender.enabled=YES; [sender setTitle:@"获取验证码" forState:UIControlStateNormal]; sender.frame = CGRectMake(sender.left, sender.top, 66, sender.height); return; } code--; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self verificationCode:code sender:sender]; }); } #pragma mark - 确认按钮 - (void)touchConfirm { NSMutableDictionary *parameters = NewMutableDictionaryInit; if (![self verification:@"个人注册"]) { return; } if ([yonghutype isEqualToString:@"请选择用户类型"]) { [MBProgressHUD showError:@"请先选择用户类型" toView:self.view]; return; } [MBProgressHUD showLoadToView:self.view title:@"请稍后..."]; [parameters safeSetObject:self.iphoneNumber.text forKey:@"mobile"];//手机号 [parameters safeSetObject:self.password.text forKey:@"newPwd"];//密码 [parameters safeSetObject:self.yanzhenma.text forKey:@"resetCode"];//短信验证码 [parameters safeSetObject:self.account.text forKey:@"username"];//您的姓名 if ([yonghutype isEqualToString:@"个人"]) { [parameters safeSetObject:@"0" forKey:@"type"];// }else if ([yonghutype isEqualToString:@"企业"]){ [parameters safeSetObject:@"1" forKey:@"type"];//您的姓名 } // [parameters safeSetObject:NewUDID forKey:@"uuid"]; [NetworkRequestManager requestPostWithInterfacePrefix:JT_appResetPwd parameters:parameters onSuccess:^(id requestData) { [MBProgressHUD hideHUDForView:self.view]; if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ [MBProgressHUD showSuccess:@"修改密码成功" toView:self.view]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NewPopViewController; }); } } onFailure:^{ [MBProgressHUD hideHUDForView:self.view]; }]; } - (void)fanhuiBTclick:(UIButton *)sender { NewPopViewController; } -(void)yhbuttoncilck { UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"用户类型" message:@"请选择用户类型" preferredStyle:UIAlertControllerStyleActionSheet]; // 创建action,这里action1只是方便编写,以后再编程的过程中还是以命名规范为主 UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"个人" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { yonghutype = @"个人"; [_yhtypeStr setTitle:yonghutype forState:UIControlStateNormal]; }]; UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"企业" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { yonghutype = @"企业"; [_yhtypeStr setTitle:yonghutype forState:UIControlStateNormal]; }]; UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; //把action添加到actionSheet里 [actionSheet addAction:action1]; [actionSheet addAction:action2]; [actionSheet addAction:action3]; //相当于之前的[actionSheet show]; [self presentViewController:actionSheet animated:YES completion:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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