// // SettingViewController.m // IBOSSmini // // Created by apple on 2017/5/4. // Copyright © 2017年 elongtian. All rights reserved. // #import "SettingViewController.h" #import "PWModifyViewController.h" @interface SettingViewController () @property(nonatomic,strong) ASIDownManager *downManager; @property(nonatomic,strong) NSString *originalPassword; @property(nonatomic,strong) NSString *newsPassword; @property(nonatomic,strong) NSString *confirmPassword; @end @implementation SettingViewController - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title=@"iBOSSMini"; UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)]; //设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。 tapGestureRecognizer.cancelsTouchesInView = NO; //将触摸事件添加到当前view [self.view addGestureRecognizer:tapGestureRecognizer]; [self initUI]; } /** didReceiveMemoryWarning */ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } /** viewWillAppear @param animated <#animated description#> */ - (void)viewWillAppear:(BOOL)animated{ // 修改密码消失 if(!_clickFlag){ [self cancelPW]; } } /** 密码修改成功回调成功 @param sender <#sender description#> */ -(void)OnPasswordLoadFinish:(ASIDownManager *)sender{ NSDictionary *dic = [sender.mWebStr JSONValue]; [self stopLoading]; if (dic && [dic isKindOfClass:[NSDictionary class]]) { int iStatus = [[dic objectForKey:@"Status"] intValue]; NSString *message=[dic objectForKey:@"Message"]; if (iStatus == 0) { _clickFlag=true; [self showAlertViewText:@"密码修改成功"]; [_passwordModify removeFromSuperview]; return; } else{ _clickFlag=false; [self showAlertViewText:message]; return; } } } /** 回调失败 @param sender <#sender description#> */ -(void)OnPasswordLoadFail:(ASIDownManager *)sender{ [self stopLoading]; _clickFlag=false; [self showAlertViewText:@"密码修改失败"]; return; } /** 切换用户回调成功 @param sender <#sender description#> */ - (void)onLoadFinish:(ASIDownManager *)sender { NSDictionary *dic = [sender.mWebStr JSONValue]; [self stopLoading]; if (dic && [dic isKindOfClass:[NSDictionary class]]) { int iStatus = [[dic objectForKey:@"Status"] intValue]; NSString *message=[dic objectForKey:@"Message"]; if (iStatus == 0) { //个人数据统统滴清除 kkUserPwdOrinal=@""; kkUserPwd=@""; kkUserCode=@""; kkAccountCode=@""; [[UserInfoManager Share]ClearUserData ]; //退回登录界面 [Appdelegate changeViewDidLogout]; } else if(iStatus==ActionResultStatusAuthError ||iStatus==ActionResultStatusNoLogin ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){ [self showReLoginDialog:message]; } else { [self showAlertViewText:message]; //退回登录界面 [Appdelegate changeViewDidLogout]; } } } /** 切换用户回调失败 @param sender <#sender description#> */ - (void)onLoadFail:(ASIDownManager *)sender { [self stopLoading]; [self showAlertViewText:@"切换用户失败"]; } #pragma mark - 私有函数 /** 初始化ui */ -(void)initUI{ _clickFlag=true; UIView *contentView=[[UIView alloc]init]; [contentView setBackgroundColor:[UIColor whiteColor]]; [self.view addSubview:contentView]; UIImage *pic=[UIImage imageNamed:@"banner_setting"]; UIImageView *bannerView=[[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.width*pic.size.height/pic.size.width)]; [bannerView setImage:pic]; [self.view addSubview:bannerView]; UIView *separatorView=[[UIView alloc]init]; [separatorView setBackgroundColor:LineBackgroundColor]; separatorView.frame=CGRectMake(0, CGRectGetMaxY(bannerView.frame), self.view.frame.size.width, 10); [self.view addSubview: separatorView]; CGFloat titleHeight = 50; CGFloat lblx = 20; CGFloat fontsize = 14; CGFloat valuey = 13; CGFloat valueheight = 25; CGFloat heightLine =1; CGFloat height = 350; //头布局 UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(separatorView.frame), Screen_Width, height)]; UIButton *btnHead=[UIButton buttonWithType:UIButtonTypeCustom]; btnHead.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [self.view addSubview: headView]; //名称================== UIView *vname=[UIView new]; vname.frame=CGRectMake(0, 0, Screen_Width, titleHeight); [headView addSubview:vname]; UILabel *lbtotal = [UILabel new]; lbtotal.frame=CGRectMake(lblx, valuey, Screen_Width - 3*lblx, valueheight); lbtotal.font = [UIFont boldSystemFontOfSize:fontsize]; NSString *str = [NSString stringWithFormat:@"用户名:%@(%@)",kkUserName,kkUserCode]; lbtotal.text = str; [vname addSubview:lbtotal]; bannerView=[[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width - lblx - 18,valuey+4,18,12.5)]; [bannerView setImage:[UIImage imageNamed:@"setting_right"]]; [vname addSubview:bannerView]; //分割线 UIView *viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vname.frame), Screen_Width, heightLine); viewBackgroud.backgroundColor = LineBackgroundColor; [headView addSubview:viewBackgroud]; float margin = 5; //切换用户================== UIView *vchangeUser=[UIView new]; vchangeUser.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [headView addSubview:vchangeUser]; UIImageView *imgview = [UIImageView new]; imgview.frame=CGRectMake(lblx, valuey+margin, 14, 19); [imgview setImage:[UIImage imageNamed:@"setting_change_user"]]; [vchangeUser addSubview:imgview]; UIButton *btnChangeUser = [UIButton buttonWithType:UIButtonTypeCustom]; btnChangeUser.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight); btnChangeUser.titleLabel.font = [UIFont systemFontOfSize:fontsize]; btnChangeUser.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [btnChangeUser setTitle:@"切换用户" forState:UIControlStateNormal]; [btnChangeUser setTitleColor:NavTitleColor forState:UIControlStateNormal]; [btnChangeUser addTarget:self action:@selector(changeUser) forControlEvents:UIControlEventTouchUpInside]; [vchangeUser addSubview:btnChangeUser]; CGRect cg = CGRectMake(Screen_Width - lblx - 9,valuey+4,9,15 ); bannerView=[[UIImageView alloc] initWithFrame:cg]; [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]]; [vchangeUser addSubview:bannerView]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vchangeUser.frame), Screen_Width, heightLine); viewBackgroud.backgroundColor = LineBackgroundColor; [headView addSubview:viewBackgroud]; // 修改密码 UIView *vchangePw=[UIView new]; vchangePw.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [headView addSubview:vchangePw]; imgview = [UIImageView new]; imgview.frame=CGRectMake(lblx, valuey+margin, 14, 16); [imgview setImage:[UIImage imageNamed:@"setting_change_pw"]]; [vchangePw addSubview:imgview]; UIButton *btnChangePw = [UIButton buttonWithType:UIButtonTypeCustom]; btnChangePw.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight); btnChangePw.titleLabel.font = [UIFont systemFontOfSize:fontsize]; btnChangePw.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [btnChangePw setTitle:@"修改密码" forState:UIControlStateNormal]; [btnChangePw setTitleColor:NavTitleColor forState:UIControlStateNormal]; [btnChangePw addTarget:self action:@selector(changePw) forControlEvents:UIControlEventTouchUpInside]; [vchangePw addSubview:btnChangePw]; bannerView=[[UIImageView alloc] initWithFrame:cg]; [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]]; [vchangePw addSubview:bannerView]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vchangePw.frame), Screen_Width,heightLine); viewBackgroud.backgroundColor = LineBackgroundColor; [headView addSubview:viewBackgroud]; // // 版本信息 // UIView *vversion=[UIView new]; // vversion.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); // [headView addSubview:vversion]; // // imgview = [UIImageView new]; // imgview.frame=CGRectMake(lblx, valuey+margin, 21, 16); // [imgview setImage:[UIImage imageNamed:@"setting_version"]]; // [vversion addSubview:imgview]; // // lblvalue = [UILabel new]; // lblvalue.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, lblwidth, valueheight); // lblvalue.font = [UIFont systemFontOfSize:fontsize]; // lblvalue.text=@"版本信息"; // [vversion addSubview:lblvalue]; // // bannerView=[[UIImageView alloc] initWithFrame:cg]; // [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]]; // [vversion addSubview:bannerView]; // // viewBackgroud = [UIView new]; // viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vversion.frame), Screen_Width,heightLine); // viewBackgroud.backgroundColor = LineBackgroundColor; // [headView addSubview:viewBackgroud]; // 退出登录 UIView *vexit=[UIView new]; vexit.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight); [headView addSubview:vexit]; imgview = [UIImageView new]; imgview.frame=CGRectMake(lblx, valuey + margin, 15, 16); [imgview setImage:[UIImage imageNamed:@"setting_exit"]]; [vexit addSubview:imgview]; UIButton *btnExit= [UIButton buttonWithType:UIButtonTypeCustom]; btnExit.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight); btnExit.titleLabel.font = [UIFont systemFontOfSize:fontsize]; btnExit.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [btnExit setTitle:@"退出登录" forState:UIControlStateNormal]; [btnExit setTitleColor:NavTitleColor forState:UIControlStateNormal]; [btnExit addTarget:self action:@selector(exitApp) forControlEvents:UIControlEventTouchUpInside]; [vexit addSubview:btnExit]; bannerView=[[UIImageView alloc] initWithFrame:cg]; [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]]; [vexit addSubview:bannerView]; viewBackgroud = [UIView new]; viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vexit.frame), Screen_Width,heightLine); viewBackgroud.backgroundColor = LineBackgroundColor; [headView addSubview:viewBackgroud]; contentView.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height); } //隐藏键盘 -(void)keyboardHide:(UITapGestureRecognizer*)tap{ [self.view endEditing:YES]; } /** 切换用户 */ - (void)changeUser{ __weak typeof (self)weakself = self; // 初始化-> UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"切换用户" message:@"是否要切换用户吗?" preferredStyle:UIAlertControllerStyleAlert]; // addAction-> UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ weakself.downManager = [[ASIDownManager alloc] init]; weakself.downManager.delegate = self; weakself.downManager.OnImageDown = @selector(onLoadFinish:); weakself.downManager.OnImageFail = @selector(onLoadFail:); [weakself startLoading]; NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"SMDLogout" forKey:@"Action"]; [dict setObject:kkAccountCode forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; [weakself.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; }]; // addAction-> UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){ }]; UIColor *cancelColor=[UIColor blackColor]; UIColor *sureColor=[UIColor redColor]; [cancelAction setValue:cancelColor forKey:@"titleTextColor"]; [okAction setValue:sureColor forKey:@"titleTextColor"]; [alert addAction:okAction]; [alert addAction:cancelAction]; // 展示-> [self presentViewController:alert animated:YES completion:nil]; } /** 修改密码 */ - (void)changePw{ if(!_clickFlag){ return; } _clickFlag=false; _passwordModify =[DKPWModifyAlterView alterViewWithTitle:@"密码修改" cancel:@"取消" sure:@"确定"]; [self.view addSubview:_passwordModify]; [[_passwordModify sureBt] addTarget:self action:@selector(surePW) forControlEvents:UIControlEventTouchUpInside]; [[_passwordModify cancelBt] addTarget:self action:@selector(cancelPW) forControlEvents:UIControlEventTouchUpInside]; } /** 退出app程序 */ - (void)exitApp{ if(!_clickFlag){ return; } //初始化提示框; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"退出程序" message:@"是否要退出登录吗?" preferredStyle:UIAlertControllerStyleAlert ]; // addAction-> UIAlertAction *okAction =[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ exit(0); }]; // addAction-> UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){ }]; UIColor *cancelColor=[UIColor blackColor]; UIColor *sureColor=[UIColor redColor]; [cancelAction setValue:cancelColor forKey:@"titleTextColor"]; [okAction setValue:sureColor forKey:@"titleTextColor"]; [alert addAction:okAction]; [alert addAction:cancelAction]; // 3.显示alertController:presentViewController [self presentViewController:alert animated:YES completion:nil]; } /** 确定修改密码 */ - (void)surePW{ _originalPassword= _passwordModify.originalPassword.text; if(_originalPassword==nil||[_originalPassword isEqualToString:@""]){ [self showAlertViewText:@"原密码不能为空"]; return; } _newsPassword=_passwordModify.nePassword.text; if(_newsPassword==nil||[_newsPassword isEqualToString:@""]){ [self showAlertViewText:@"新密码不能为空"]; return; } _confirmPassword=_passwordModify.confirmPassword.text; if(_confirmPassword==nil||[_confirmPassword isEqualToString:@""]){ [self showAlertViewText:@"确认密码不能为空"]; return; } if(![_newsPassword isEqualToString:_confirmPassword]){ [self showAlertViewText:@"新密码与确认密码不一致"]; return; } self.downManager = [[ASIDownManager alloc] init]; [self startLoading]; self.downManager.delegate = self; self.downManager.OnImageDown = @selector(OnPasswordLoadFinish:); self.downManager.OnImageFail = @selector(OnPasswordLoadFail:); NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"SaveUserPassWordIphone" forKey:@"Action"]; [dict setObject:kkAccountCode forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; [dict setObject:_originalPassword forKey:@"OldUserPassWord"]; [dict setObject:_newsPassword forKey:@"NewUserPassword"]; [self.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } /** 取消修改密码 */ - (void)cancelPW{ _clickFlag=true; [_passwordModify removeFromSuperview]; } - (void)Cancel { [self stopLoading]; } @end