| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- //
- // ModifypasswordViewController.m
- // jitao
- //
- // Created by 罗云飞 on 2017/12/11.
- // Copyright © 2017年 罗云飞. All rights reserved.
- //
- #import "ModifypasswordViewController.h"
- #import "NewRegistCell.h"
- #import "NewInterfaceReplacement.h"
- #import "HuanXinHelper.h"
- @interface ModifypasswordViewController ()<UITableViewDelegate,UITableViewDataSource>
- {
- NSMutableArray *dataArray;
- UITableView *mainTableView;
- UITextField *phoneTextField;
- UITextField *verificationCodeTextField;
- UITextField *passWord1TextField;
- UITextField *passWord2TextField;
- UIButton *verificationCodeButton;
-
- UIView *view;
- UIView *popupsview;
- }
- @end
- @implementation ModifypasswordViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setNavTitle:@"修改密码"];
- [self dataInitialization];
- [self loadsView];
- // Do any additional setup after loading the view.
- }
- #pragma mark - 数据初始化
- -(void)dataInitialization
- {
- phoneTextField = nil;
- verificationCodeTextField = nil;
- verificationCodeButton = nil;
- passWord1TextField = nil;
- passWord2TextField = nil;
- dataArray = NewMutableArrayInit;
-
- for (int i=0; i<4; i++) {
- NSDictionary *dataDic = [NSDictionary dictionary];
-
- switch (i) {
- case 0:
- dataDic = @{@"nameKey":@"手机号",@"imageKey":@"手机号码",@"placeholderKey":@"请输入手机号"};
- [dataArray addObject:dataDic];
- break;
- case 1:
- dataDic = @{@"nameKey":@"验证码",@"imageKey":@"短信",@"placeholderKey":@"请输入短信验证码"};
- [dataArray addObject:dataDic];
- break;
- case 2:
- dataDic = @{@"nameKey":@"新密码",@"imageKey":@"密码",@"placeholderKey":@"密码不少于6位数"};
- [dataArray addObject:dataDic];
- break;
- case 3:
- dataDic = @{@"nameKey":@"确认密码",@"imageKey":@"密码",@"placeholderKey":@"请重新输入新密码"};
- [dataArray addObject:dataDic];
- break;
- default:
- break;
- }
- }
- }
- #pragma mark - UI初始化
- -(void)loadsView
- {
- [self.view addSubview:mainTableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, ViewStartY, SCREEN_WIDTH, SCREEN_HEIGHT-ViewStartY) backgroundColor:NewWhiteColor style:0 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
- mainTableView.separatorStyle = NO; //newtableView隐藏线条
-
- UIView *view;
- mainTableView.tableFooterView = view = [NewControlPackage viewInitWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 84) backgroundColor:NewClearColor hidden:NO tag:101 userInteractionEnabled:YES];
-
- UIImageView *lineImge;
- [view addSubview:lineImge = [NewControlPackage imageViewInitWithFrame:CGRectMake(15, 0, SCREEN_WIDTH-15, .6) image:nil highlightedImage:nil backgroundColor:NewCellLineColor tag:102 hidden:NO userInteractionEnabled:YES]];
- lineImge.hidden = YES;
-
-
- UIButton *confirm;
- [view addSubview:confirm = [NewControlPackage buttonInitWithTitle:@"提交" Frame:CGRectMake(20, 20+lineImge.height, SCREEN_WIDTH-40, 36) 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(confirm, 8);
-
- }
- #pragma mark - UITableView Delegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
-
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
-
- return dataArray.count;
- }
- - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- static NSString *Cell = @"Cell";
- NewRegistCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
- if (cell == nil) {
- cell = [[NewRegistCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
- }
-
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.accessoryType = UITableViewCellAccessoryNone;
-
- cell.image.image = NewImageNamed(dataArray[indexPath.row][@"imageKey"]);
- cell.title.text = dataArray[indexPath.row][@"nameKey"];
-
- if (passWord2TextField == nil) {
-
- //获取验证码frame
- float vcwidth = 66;
- float vcheight = cell.height-20;
- float vcx = SCREEN_WIDTH-vcwidth-20;
- float vcy = 10;
-
-
- //输入框frame
- float tx = 110;
- float ty = 2;
- float twidth = SCREEN_WIDTH-tx-20;
- float theight = cell.height-2;
-
-
- UITextField *textField;
- [cell.contentView addSubview:textField = [NewControlPackage textFieldInitWithFrame:CGRectMake(tx, ty, twidth, theight) backgroundImage:nil backgroundColor:NewClearColor textColor:NewGrayColor placeholder:dataArray[indexPath.row][@"placeholderKey"] hidden:NO tag:100+(int)indexPath.row font:NewFont(14) textAlignment:NSTextAlignmentLeft clearButtonMode:NO clearsOnBeginEditing:NO adjustsFontSizeToFitWidth:NO secureTextEntry:NO keyboardType:UIKeyboardTypeDefault returnKeyType:UIReturnKeyDefault userInteractionEnabled:YES]];
- [textField addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
-
- if (indexPath.row == 0) {
- cell.areacode.hidden = NO;
- }else{
- cell.areacode.hidden = YES;
- }
-
- if (indexPath.row==0) {
-
- phoneTextField = textField;
- //phoneTextField.keyboardType = UIKeyboardTypeNumberPad;
- textField.frame = CGRectMake(140, ty, twidth, theight);
- [textField setKeyboardType:UIKeyboardTypeNumberPad];
-
- }else if (indexPath.row==1) {
-
- verificationCodeTextField = textField;
-
- [cell.contentView addSubview:verificationCodeButton = [NewControlPackage buttonInitWithTitle:@"获取验证码" Frame:CGRectMake(vcx, vcy, vcwidth, vcheight) backgroundImage:nil backgroundImageHighlighted:nil backgroundColor:NewLightGrayColor textColor:NewWhiteColor textAlignment:UIControlContentHorizontalAlignmentCenter font:NewFont(10) tag:99 target:self action:@selector(touchVerificationCode:) hidden:NO userInteractionEnabled:YES]];
- ViewRadius(verificationCodeButton, 10);
-
- }else if (indexPath.row==2) {
- passWord1TextField = textField;
- [passWord1TextField setSecureTextEntry:YES];
-
- }else if (indexPath.row==3) {
- passWord2TextField = textField;
- [passWord2TextField setSecureTextEntry:YES];
-
- }
- }
-
- return cell;
- }
- #pragma mark - 作字符输入限制
- - (void)textFieldEditingChanged:(UITextField *)textField
- {
- if (textField == phoneTextField) {
- if ([textField.text length]>11) {
- textField.text=[textField.text substringToIndex:11];//手机号码11位
- }
- }else if (textField == verificationCodeTextField) {
- if ([textField.text length]>6) {
- textField.text=[textField.text substringToIndex:6];//验证码6位
- }
- }else if (textField == passWord1TextField) {
- if ([textField.text length]>20) {
- textField.text=[textField.text substringToIndex:20];//新密码最多20位
- }
- }else if (textField == passWord2TextField) {
- 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:@"请稍后..."];
- NSMutableDictionary *parameters = NewMutableDictionaryInit;
- [parameters safeSetObject:phoneTextField.text forKey:@"mobile"];//手机号码
- [parameters safeSetObject:@"false" forKey:@"sign"];//是否已注册
- [parameters safeSetObject:[UserEntity sharedInstance].type forKey:@"type"];//0-个人 1-单位
- [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];
- }
- }else{
- [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];
- }];
- }
- - (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
- {
- if (![self verification:nil]) {
- return;
- }
- NSMutableDictionary *parameters = NewMutableDictionaryInit;
- [parameters safeSetObject:verificationCodeTextField.text forKey:@"resetCode"];//验证码
- [parameters safeSetObject:phoneTextField.text forKey:@"mobile"];//手机号码
- [parameters safeSetObject:[UserEntity sharedInstance].type forKey:@"type"];//用户类型
- [parameters safeSetObject:passWord2TextField.text forKey:@"newPwd"];//新密码
-
- [NetworkRequestManager requestPostWithInterfacePrefix:JT_resetPwd 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];
- }
- }else{
- [self popview];
- }
- } onFailure:^{
-
- }];
- };
- #pragma mark ----- 修改密码成功弹窗-------
- - (void)popview{
- UITapGestureRecognizer*tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewclick:)];
- view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- view.userInteractionEnabled = YES;
- [view addGestureRecognizer:tapGes];
- view.hidden = NO;
- view.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.5];
- [[AppDelegate shareDelegate].window addSubview:view];
-
- popupsview = [[UIView alloc] initWithFrame:CGRectMake(25, 148, SCREEN_WIDTH-50, fitScreenHeight(178))];
- popupsview.backgroundColor = NewWhiteColor;
- ViewRadius(popupsview, 10);
- popupsview.hidden = NO;
- [[AppDelegate shareDelegate].window addSubview:popupsview];
-
- UIImageView *image = [UIImageView new];
- [image setImage:[UIImage imageNamed:@"成功"]];
- [popupsview addSubview:image];
-
- image.sd_layout
- .centerXEqualToView(popupsview)
- .topSpaceToView(popupsview, 12)
- .heightIs(49)
- .widthIs(49);
-
- UILabel *prompt = [UILabel new];
- prompt.text = @"密码修改成功";
- [prompt setSingleLineAutoResizeWithMaxWidth:0];
- prompt.font = NewFont(14);
- prompt.textColor = [UIColor colorWithString:@"#3C3C3C"];
- [popupsview addSubview:prompt];
-
- prompt.sd_layout
- .centerXEqualToView(popupsview)
- .heightIs(15)
- .topSpaceToView(image, 10);
-
- UIButton *loginBT = [UIButton new];
- [loginBT setTitle:@"去登录" forState:UIControlStateNormal];
- [loginBT setTitleColor:NewWhiteColor forState:UIControlStateNormal];
- loginBT.titleLabel.font = NewFont(12);
- [loginBT setBackgroundColor:NewButtonColor];
- NewTouchUpInside(loginBT, loginBTclick:);
- [popupsview addSubview:loginBT];
- ViewRadius(loginBT, 8);
-
- loginBT.sd_layout
- .centerXEqualToView(popupsview)
- .topSpaceToView(prompt, 22)
- .heightIs(31)
- .widthIs(89);
-
- UIButton *XX = [UIButton new];
- [XX setImage:[UIImage imageNamed:@"关闭"] forState:UIControlStateNormal];
- NewTouchUpInside(XX, XXclick:);
- // [popupsview addSubview:XX];
-
- XX.sd_layout
- .rightSpaceToView(popupsview, 10)
- .heightIs(fitScreenHeight(10))
- .widthIs(fitScreenWidth(10))
- .topSpaceToView(popupsview, 10);
- }
- //点击空白灰色背景
- - (void)viewclick:(UITapGestureRecognizer *)tag{
- // view.hidden = YES;
- // popupsview.hidden = YES;
- }
- #pragma mark -----去登录按钮-----
- - (void)loginBTclick:(UIButton *)sender {
- NSLog(@"去登陆");
- view.hidden = YES;
- popupsview.hidden = YES;
- // [[NewInterfaceReplacement sharedInstance] replacementLogin];
- //退出云信账号、解绑阿里云推送账号、删除用户单例类以及本地缓存保存的数据
- [UserHelper exitLogin];
- //退出环信账号
- [[HuanXinHelper sharedInstance] exitlogon];
- //销毁之前的单利对象
- [NewBasicTabbarController objectDealloc];
-
- //给予系统0.5秒清除本地数据
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- // 跳转登录界面
- NewLoginViewController *startVc = [[NewLoginViewController alloc] init];
- startVc.string = @"退出登录";
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:startVc];
- [AppDelegate shareDelegate].window.rootViewController = navi;
- });
-
- }
- #pragma mark -----取消按钮
- -(void)XXclick:(UIButton *)sender {
- view.hidden = YES;
- popupsview.hidden = YES;
- }
- - (BOOL)verification:(NSString *)status
- {
- if ([status isEqualToString:@"校验手机号"]) {
- if (phoneTextField.text.length <= 0) {
- [self.view makeToast:@"请输入手机号码" duration:1.0 position:CSToastPositionCenter];
- return NO;
- }else if (phoneTextField.text.length < 11){
- [self.view makeToast:@"手机号码输入有误" duration:1.0 position:CSToastPositionCenter];
- return NO;
- }
- }else{
- if (phoneTextField.text.length <= 0) {
- [self.view makeToast:@"手机号码输入有误" duration:1.5 position:CSToastPositionCenter];
- return NO;
- }
- if (verificationCodeTextField.text.length <= 0) {
- [self.view makeToast:@"验证码输入有误" duration:1.5 position:CSToastPositionCenter];
- return NO;
- }
- if (passWord1TextField.text.length<6||passWord2TextField.text.length<6) {
- [self.view makeToast:@"新密码不能少于6位数" duration:1.5 position:CSToastPositionCenter];
- return NO;
- }
- if (passWord1TextField.text.length <= 0) {
- [self.view makeToast:@"新密码输入有误" duration:1.5 position:CSToastPositionCenter];
- return NO;
- }
- if (passWord2TextField.text.length <= 0) {
- [self.view makeToast:@"确认新密码输入有误" duration:1.5 position:CSToastPositionCenter];
- return NO;
- }
- if (![passWord1TextField.text isEqualToString:passWord2TextField.text]) {
- [self.view makeToast:@"设置密码和确认密码不同" duration:1.5 position:CSToastPositionCenter];
- return NO;
- }
- }
- return YES;
- }
- - (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
|