| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- //
- // 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
|