SettingViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. //
  2. // SettingViewController.m
  3. // IBOSSmini
  4. //
  5. // Created by apple on 2017/5/4.
  6. // Copyright © 2017年 elongtian. All rights reserved.
  7. //
  8. #import "SettingViewController.h"
  9. #import "PWModifyViewController.h"
  10. @interface SettingViewController ()
  11. @property(nonatomic,strong) ASIDownManager *downManager;
  12. @property(nonatomic,strong) NSString *originalPassword;
  13. @property(nonatomic,strong) NSString *newsPassword;
  14. @property(nonatomic,strong) NSString *confirmPassword;
  15. @end
  16. @implementation SettingViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.navigationItem.title=@"iBOSSMini";
  20. UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
  21. //设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。
  22. tapGestureRecognizer.cancelsTouchesInView = NO;
  23. //将触摸事件添加到当前view
  24. [self.view addGestureRecognizer:tapGestureRecognizer];
  25. [self initUI];
  26. }
  27. /**
  28. didReceiveMemoryWarning
  29. */
  30. - (void)didReceiveMemoryWarning {
  31. [super didReceiveMemoryWarning];
  32. }
  33. /**
  34. viewWillAppear
  35. @param animated <#animated description#>
  36. */
  37. - (void)viewWillAppear:(BOOL)animated{
  38. // 修改密码消失
  39. if(!_clickFlag){
  40. [self cancelPW];
  41. }
  42. }
  43. /**
  44. 密码修改成功回调成功
  45. @param sender <#sender description#>
  46. */
  47. -(void)OnPasswordLoadFinish:(ASIDownManager *)sender{
  48. NSDictionary *dic = [sender.mWebStr JSONValue];
  49. [self stopLoading];
  50. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  51. int iStatus = [[dic objectForKey:@"Status"] intValue];
  52. NSString *message=[dic objectForKey:@"Message"];
  53. if (iStatus == 0) {
  54. _clickFlag=true;
  55. [self showAlertViewText:@"密码修改成功"];
  56. [_passwordModify removeFromSuperview];
  57. return;
  58. }
  59. else{
  60. _clickFlag=false;
  61. [self showAlertViewText:message];
  62. return;
  63. }
  64. }
  65. }
  66. /**
  67. 回调失败
  68. @param sender <#sender description#>
  69. */
  70. -(void)OnPasswordLoadFail:(ASIDownManager *)sender{
  71. [self stopLoading];
  72. _clickFlag=false;
  73. [self showAlertViewText:@"密码修改失败"];
  74. return;
  75. }
  76. /**
  77. 切换用户回调成功
  78. @param sender <#sender description#>
  79. */
  80. - (void)onLoadFinish:(ASIDownManager *)sender {
  81. NSDictionary *dic = [sender.mWebStr JSONValue];
  82. [self stopLoading];
  83. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  84. int iStatus = [[dic objectForKey:@"Status"] intValue];
  85. NSString *message=[dic objectForKey:@"Message"];
  86. if (iStatus == 0) {
  87. //个人数据统统滴清除
  88. kkUserPwdOrinal=@"";
  89. kkUserPwd=@"";
  90. kkUserCode=@"";
  91. kkAccountCode=@"";
  92. [[UserInfoManager Share]ClearUserData ];
  93. //退回登录界面
  94. [Appdelegate changeViewDidLogout];
  95. }
  96. else if(iStatus==ActionResultStatusAuthError
  97. ||iStatus==ActionResultStatusNoLogin
  98. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  99. [self showReLoginDialog:message];
  100. }
  101. else {
  102. [self showAlertViewText:message];
  103. //退回登录界面
  104. [Appdelegate changeViewDidLogout];
  105. }
  106. }
  107. }
  108. /**
  109. 切换用户回调失败
  110. @param sender <#sender description#>
  111. */
  112. - (void)onLoadFail:(ASIDownManager *)sender {
  113. [self stopLoading];
  114. [self showAlertViewText:@"切换用户失败"];
  115. }
  116. #pragma mark - 私有函数
  117. /**
  118. 初始化ui
  119. */
  120. -(void)initUI{
  121. _clickFlag=true;
  122. UIView *contentView=[[UIView alloc]init];
  123. [contentView setBackgroundColor:[UIColor whiteColor]];
  124. [self.view addSubview:contentView];
  125. UIImage *pic=[UIImage imageNamed:@"banner_setting"];
  126. UIImageView *bannerView=[[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.width*pic.size.height/pic.size.width)];
  127. [bannerView setImage:pic];
  128. [self.view addSubview:bannerView];
  129. UIView *separatorView=[[UIView alloc]init];
  130. [separatorView setBackgroundColor:LineBackgroundColor];
  131. separatorView.frame=CGRectMake(0, CGRectGetMaxY(bannerView.frame), self.view.frame.size.width, 10);
  132. [self.view addSubview: separatorView];
  133. CGFloat titleHeight = 50;
  134. CGFloat lblx = 20;
  135. CGFloat fontsize = 14;
  136. CGFloat valuey = 13;
  137. CGFloat valueheight = 25;
  138. CGFloat heightLine =1;
  139. CGFloat height = 350;
  140. //头布局
  141. UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(separatorView.frame), Screen_Width, height)];
  142. UIButton *btnHead=[UIButton buttonWithType:UIButtonTypeCustom];
  143. btnHead.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  144. [self.view addSubview: headView];
  145. //名称==================
  146. UIView *vname=[UIView new];
  147. vname.frame=CGRectMake(0, 0, Screen_Width, titleHeight);
  148. [headView addSubview:vname];
  149. UILabel *lbtotal = [UILabel new];
  150. lbtotal.frame=CGRectMake(lblx, valuey, Screen_Width - 3*lblx, valueheight);
  151. lbtotal.font = [UIFont boldSystemFontOfSize:fontsize];
  152. NSString *str = [NSString stringWithFormat:@"用户名:%@(%@)",kkUserName,kkUserCode];
  153. lbtotal.text = str;
  154. [vname addSubview:lbtotal];
  155. bannerView=[[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width - lblx - 18,valuey+4,18,12.5)];
  156. [bannerView setImage:[UIImage imageNamed:@"setting_right"]];
  157. [vname addSubview:bannerView];
  158. //分割线
  159. UIView *viewBackgroud = [UIView new];
  160. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vname.frame), Screen_Width, heightLine);
  161. viewBackgroud.backgroundColor = LineBackgroundColor;
  162. [headView addSubview:viewBackgroud];
  163. float margin = 5;
  164. //切换用户==================
  165. UIView *vchangeUser=[UIView new];
  166. vchangeUser.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  167. [headView addSubview:vchangeUser];
  168. UIImageView *imgview = [UIImageView new];
  169. imgview.frame=CGRectMake(lblx, valuey+margin, 14, 19);
  170. [imgview setImage:[UIImage imageNamed:@"setting_change_user"]];
  171. [vchangeUser addSubview:imgview];
  172. UIButton *btnChangeUser = [UIButton buttonWithType:UIButtonTypeCustom];
  173. btnChangeUser.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  174. btnChangeUser.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  175. btnChangeUser.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  176. [btnChangeUser setTitle:@"切换用户" forState:UIControlStateNormal];
  177. [btnChangeUser setTitleColor:NavTitleColor forState:UIControlStateNormal];
  178. [btnChangeUser addTarget:self action:@selector(changeUser) forControlEvents:UIControlEventTouchUpInside];
  179. [vchangeUser addSubview:btnChangeUser];
  180. CGRect cg = CGRectMake(Screen_Width - lblx - 9,valuey+4,9,15 );
  181. bannerView=[[UIImageView alloc] initWithFrame:cg];
  182. [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  183. [vchangeUser addSubview:bannerView];
  184. viewBackgroud = [UIView new];
  185. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vchangeUser.frame), Screen_Width, heightLine);
  186. viewBackgroud.backgroundColor = LineBackgroundColor;
  187. [headView addSubview:viewBackgroud];
  188. // 修改密码
  189. UIView *vchangePw=[UIView new];
  190. vchangePw.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  191. [headView addSubview:vchangePw];
  192. imgview = [UIImageView new];
  193. imgview.frame=CGRectMake(lblx, valuey+margin, 14, 16);
  194. [imgview setImage:[UIImage imageNamed:@"setting_change_pw"]];
  195. [vchangePw addSubview:imgview];
  196. UIButton *btnChangePw = [UIButton buttonWithType:UIButtonTypeCustom];
  197. btnChangePw.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  198. btnChangePw.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  199. btnChangePw.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  200. [btnChangePw setTitle:@"修改密码" forState:UIControlStateNormal];
  201. [btnChangePw setTitleColor:NavTitleColor forState:UIControlStateNormal];
  202. [btnChangePw addTarget:self action:@selector(changePw) forControlEvents:UIControlEventTouchUpInside];
  203. [vchangePw addSubview:btnChangePw];
  204. bannerView=[[UIImageView alloc] initWithFrame:cg];
  205. [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  206. [vchangePw addSubview:bannerView];
  207. viewBackgroud = [UIView new];
  208. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vchangePw.frame), Screen_Width,heightLine);
  209. viewBackgroud.backgroundColor = LineBackgroundColor;
  210. [headView addSubview:viewBackgroud];
  211. // // 版本信息
  212. // UIView *vversion=[UIView new];
  213. // vversion.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  214. // [headView addSubview:vversion];
  215. //
  216. // imgview = [UIImageView new];
  217. // imgview.frame=CGRectMake(lblx, valuey+margin, 21, 16);
  218. // [imgview setImage:[UIImage imageNamed:@"setting_version"]];
  219. // [vversion addSubview:imgview];
  220. //
  221. // lblvalue = [UILabel new];
  222. // lblvalue.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, lblwidth, valueheight);
  223. // lblvalue.font = [UIFont systemFontOfSize:fontsize];
  224. // lblvalue.text=@"版本信息";
  225. // [vversion addSubview:lblvalue];
  226. //
  227. // bannerView=[[UIImageView alloc] initWithFrame:cg];
  228. // [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  229. // [vversion addSubview:bannerView];
  230. //
  231. // viewBackgroud = [UIView new];
  232. // viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vversion.frame), Screen_Width,heightLine);
  233. // viewBackgroud.backgroundColor = LineBackgroundColor;
  234. // [headView addSubview:viewBackgroud];
  235. // 退出登录
  236. UIView *vexit=[UIView new];
  237. vexit.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  238. [headView addSubview:vexit];
  239. imgview = [UIImageView new];
  240. imgview.frame=CGRectMake(lblx, valuey + margin, 15, 16);
  241. [imgview setImage:[UIImage imageNamed:@"setting_exit"]];
  242. [vexit addSubview:imgview];
  243. UIButton *btnExit= [UIButton buttonWithType:UIButtonTypeCustom];
  244. btnExit.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  245. btnExit.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  246. btnExit.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  247. [btnExit setTitle:@"退出登录" forState:UIControlStateNormal];
  248. [btnExit setTitleColor:NavTitleColor forState:UIControlStateNormal];
  249. [btnExit addTarget:self action:@selector(exitApp) forControlEvents:UIControlEventTouchUpInside];
  250. [vexit addSubview:btnExit];
  251. bannerView=[[UIImageView alloc] initWithFrame:cg];
  252. [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  253. [vexit addSubview:bannerView];
  254. viewBackgroud = [UIView new];
  255. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vexit.frame), Screen_Width,heightLine);
  256. viewBackgroud.backgroundColor = LineBackgroundColor;
  257. [headView addSubview:viewBackgroud];
  258. contentView.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
  259. }
  260. //隐藏键盘
  261. -(void)keyboardHide:(UITapGestureRecognizer*)tap{
  262. [self.view endEditing:YES];
  263. }
  264. /**
  265. 切换用户
  266. */
  267. - (void)changeUser{
  268. __weak typeof (self)weakself = self;
  269. // 初始化->
  270. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"切换用户" message:@"是否要切换用户吗?" preferredStyle:UIAlertControllerStyleAlert];
  271. // addAction->
  272. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  273. weakself.downManager = [[ASIDownManager alloc] init];
  274. weakself.downManager.delegate = self;
  275. weakself.downManager.OnImageDown = @selector(onLoadFinish:);
  276. weakself.downManager.OnImageFail = @selector(onLoadFail:);
  277. [weakself startLoading];
  278. NSString *urlStr = ServerURL;
  279. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  280. [dict setObject:@"SMDLogout" forKey:@"Action"];
  281. [dict setObject:kkAccountCode forKey:@"AccountCode"];
  282. [dict setObject:kkUserCode forKey:@"UserCode"];
  283. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  284. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  285. [weakself.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  286. }];
  287. // addAction->
  288. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
  289. }];
  290. UIColor *cancelColor=[UIColor blackColor];
  291. UIColor *sureColor=[UIColor redColor];
  292. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  293. [okAction setValue:sureColor forKey:@"titleTextColor"];
  294. [alert addAction:okAction];
  295. [alert addAction:cancelAction];
  296. // 展示->
  297. [self presentViewController:alert animated:YES completion:nil];
  298. }
  299. /**
  300. 修改密码
  301. */
  302. - (void)changePw{
  303. if(!_clickFlag){
  304. return;
  305. }
  306. _clickFlag=false;
  307. _passwordModify =[DKPWModifyAlterView alterViewWithTitle:@"密码修改" cancel:@"取消" sure:@"确定"];
  308. [self.view addSubview:_passwordModify];
  309. [[_passwordModify sureBt] addTarget:self action:@selector(surePW) forControlEvents:UIControlEventTouchUpInside];
  310. [[_passwordModify cancelBt] addTarget:self action:@selector(cancelPW) forControlEvents:UIControlEventTouchUpInside];
  311. }
  312. /**
  313. 退出app程序
  314. */
  315. - (void)exitApp{
  316. if(!_clickFlag){
  317. return;
  318. }
  319. //初始化提示框;
  320. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"退出程序" message:@"是否要退出登录吗?" preferredStyle:UIAlertControllerStyleAlert ];
  321. // addAction->
  322. UIAlertAction *okAction =[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  323. exit(0);
  324. }];
  325. // addAction->
  326. UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
  327. }];
  328. UIColor *cancelColor=[UIColor blackColor];
  329. UIColor *sureColor=[UIColor redColor];
  330. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  331. [okAction setValue:sureColor forKey:@"titleTextColor"];
  332. [alert addAction:okAction];
  333. [alert addAction:cancelAction];
  334. // 3.显示alertController:presentViewController
  335. [self presentViewController:alert animated:YES completion:nil];
  336. }
  337. /**
  338. 确定修改密码
  339. */
  340. - (void)surePW{
  341. _originalPassword= _passwordModify.originalPassword.text;
  342. if(_originalPassword==nil||[_originalPassword isEqualToString:@""]){
  343. [self showAlertViewText:@"原密码不能为空"];
  344. return;
  345. }
  346. _newsPassword=_passwordModify.nePassword.text;
  347. if(_newsPassword==nil||[_newsPassword isEqualToString:@""]){
  348. [self showAlertViewText:@"新密码不能为空"];
  349. return;
  350. }
  351. _confirmPassword=_passwordModify.confirmPassword.text;
  352. if(_confirmPassword==nil||[_confirmPassword isEqualToString:@""]){
  353. [self showAlertViewText:@"确认密码不能为空"];
  354. return;
  355. }
  356. if(![_newsPassword isEqualToString:_confirmPassword]){
  357. [self showAlertViewText:@"新密码与确认密码不一致"];
  358. return;
  359. }
  360. self.downManager = [[ASIDownManager alloc] init];
  361. [self startLoading];
  362. self.downManager.delegate = self;
  363. self.downManager.OnImageDown = @selector(OnPasswordLoadFinish:);
  364. self.downManager.OnImageFail = @selector(OnPasswordLoadFail:);
  365. NSString *urlStr = ServerURL;
  366. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  367. [dict setObject:@"SaveUserPassWordIphone" forKey:@"Action"];
  368. [dict setObject:kkAccountCode forKey:@"AccountCode"];
  369. [dict setObject:kkUserCode forKey:@"UserCode"];
  370. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  371. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  372. [dict setObject:_originalPassword forKey:@"OldUserPassWord"];
  373. [dict setObject:_newsPassword forKey:@"NewUserPassword"];
  374. [self.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  375. }
  376. /**
  377. 取消修改密码
  378. */
  379. - (void)cancelPW{
  380. _clickFlag=true;
  381. [_passwordModify removeFromSuperview];
  382. }
  383. - (void)Cancel {
  384. [self stopLoading];
  385. }
  386. @end