SettingViewController.m 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. //
  2. // SettingViewController.m
  3. // IBOSS
  4. //
  5. // Created by apple on 2017/5/4.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:设置控制器
  9. //
  10. #import "SettingViewController.h"
  11. #import "PWModifyViewController.h"
  12. #import "Reachability.h"
  13. #import "Util.h"
  14. @interface SettingViewController (){
  15. /**
  16. 缓存文本
  17. */
  18. UILabel *lbSize;
  19. }
  20. /**
  21. ASIDownManager请求对象
  22. */
  23. @property (nonatomic,strong) ASIDownManager *downManager;
  24. /**
  25. 原密码
  26. */
  27. @property (nonatomic,strong) NSString *originalPassword;
  28. /**
  29. 新密码
  30. */
  31. @property (nonatomic,strong) NSString *newsPassword;
  32. /**
  33. 确认密码
  34. */
  35. @property (nonatomic,strong) NSString *confirmPassword;
  36. @end
  37. @implementation SettingViewController
  38. #pragma mark - 公共函数
  39. /**
  40. viewDidLoad
  41. */
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. self.navigationItem.title = @"iBOSS";
  45. UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
  46. //设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。
  47. tapGestureRecognizer.cancelsTouchesInView = NO;
  48. //将触摸事件添加到当前view
  49. [self.view addGestureRecognizer:tapGestureRecognizer];
  50. _staffList=[[NSMutableArray alloc]init];
  51. [self initUI];
  52. [self loadStaffData];
  53. }
  54. /**
  55. didReceiveMemoryWarning
  56. */
  57. - (void)didReceiveMemoryWarning {
  58. [super didReceiveMemoryWarning];
  59. }
  60. /**
  61. viewWillAppear
  62. @param animated <#animated description#>
  63. */
  64. - (void)viewWillAppear:(BOOL)animated{
  65. // 修改密码消失
  66. if(!_clickFlag){
  67. [self cancelPW];
  68. }
  69. [self updateCacheSize:lbSize];
  70. }
  71. #pragma mark - 回调函数
  72. /**
  73. 密码修改成功回调成功
  74. @param sender <#sender description#>
  75. */
  76. - (void)OnPasswordLoadFinish:(ASIDownManager *)sender{
  77. // 取消进度条
  78. [self stopLoading];
  79. // 服务器返回数据
  80. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  81. // 服务器返回数据状态值
  82. int iStatus = resultModel.status;
  83. // 服务器返回数据消息
  84. NSString *message = resultModel.message;
  85. // 服务器返回数据状态值正确
  86. if (iStatus == 0) {
  87. _clickFlag = true;
  88. [self showAlertViewText:@"密码修改成功"];
  89. [_passwordModify removeFromSuperview];
  90. return;
  91. }
  92. else{
  93. _clickFlag = false;
  94. [self showAlertViewText:message];
  95. return;
  96. }
  97. }
  98. /**
  99. 回调失败
  100. @param sender <#sender description#>
  101. */
  102. - (void)OnPasswordLoadFail:(ASIDownManager *)sender{
  103. [self stopLoading];
  104. _clickFlag = false;
  105. [self showAlertViewText:@"密码修改失败"];
  106. return;
  107. }
  108. /**
  109. 切换用户回调成功
  110. @param sender <#sender description#>
  111. */
  112. - (void)onLoadFinish:(ASIDownManager *)sender {
  113. [self stopLoading];
  114. // 服务器返回数据转换model
  115. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  116. // 服务器返回数据状态值
  117. int iStatus = resultModel.status;
  118. // 服务器返回数据消息
  119. NSString *message = resultModel.message;
  120. // 服务器返回数据状态值正确
  121. if (iStatus == 0) {
  122. //个人数据统统滴清除
  123. kkUserPwdOrinal = @"";
  124. kkUserPwd = @"";
  125. kkUserCode = @"";
  126. kkAccountCode = @"";
  127. [[UserInfoManager Share]ClearUserData ];
  128. //退回登录界面
  129. [Appdelegate changeViewDidLogout];
  130. }
  131. else if(iStatus == ActionResultStatusAuthError
  132. ||iStatus == ActionResultStatusNoLogin
  133. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  134. [self showReLoginDialog:message];
  135. }
  136. else {
  137. [self showAlertViewText:message];
  138. // 退回登录界面
  139. [Appdelegate changeViewDidLogout];
  140. }
  141. }
  142. /**
  143. 切换用户回调失败
  144. @param sender <#sender description#>
  145. */
  146. - (void)onLoadFail:(ASIDownManager *)sender {
  147. [self stopLoading];
  148. [self showAlertViewText:@"切换用户失败"];
  149. }
  150. #pragma mark - 私有函数
  151. /**
  152. 初始化ui
  153. */
  154. - (void)initUI{
  155. _clickFlag = true;
  156. [self.view setBackgroundColor:[UIColor whiteColor]];
  157. UIImage *pic = [UIImage imageNamed:@"banner_setting"];
  158. UIImageView *bannerView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.width*pic.size.height/pic.size.width)];
  159. [bannerView setImage:pic];
  160. [self.view addSubview:bannerView];
  161. UIView *separatorView = [[UIView alloc]init];
  162. [separatorView setBackgroundColor:LineBackgroundColor];
  163. separatorView.frame=CGRectMake(0, CGRectGetMaxY(bannerView.frame), self.view.frame.size.width, 10);
  164. [self.view addSubview: separatorView];
  165. CGFloat titleHeight = 50;
  166. CGFloat lblx = 20;
  167. CGFloat fontsize = 14;
  168. CGFloat valuey = 13;
  169. CGFloat valueheight = 25;
  170. CGFloat heightLine =1;
  171. CGFloat height = 350;
  172. //头布局
  173. UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(separatorView.frame), Screen_Width, height)];
  174. UIButton *btnHead = [UIButton buttonWithType:UIButtonTypeCustom];
  175. btnHead.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  176. [self.view addSubview: headView];
  177. //名称 —————————
  178. UIView *vname = [UIView new];
  179. vname.frame=CGRectMake(0, 0, Screen_Width, titleHeight);
  180. [headView addSubview:vname];
  181. UILabel *lbtotal = [UILabel new];
  182. lbtotal.frame=CGRectMake(lblx, valuey, Screen_Width - 3*lblx, valueheight);
  183. lbtotal.font = [UIFont boldSystemFontOfSize:fontsize];
  184. NSString *str = [NSString stringWithFormat:@"用户名:%@(%@)",kkUserName,kkUserCode];
  185. lbtotal.text = str;
  186. [vname addSubview:lbtotal];
  187. bannerView = [[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width - lblx - 18,valuey+4,18,12.5)];
  188. [bannerView setImage:[UIImage imageNamed:@"setting_right"]];
  189. [vname addSubview:bannerView];
  190. //分割线
  191. UIView *viewBackgroud = [UIView new];
  192. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vname.frame), Screen_Width, heightLine);
  193. viewBackgroud.backgroundColor = LineBackgroundColor;
  194. [headView addSubview:viewBackgroud];
  195. height=CGRectGetMaxY(viewBackgroud.frame);
  196. //名称 —————————
  197. if([kkRights rangeOfString:FUNCTION_SALEMAN_BACKAMOUT_IPHONE].location!=NSNotFound){
  198. UIView *vAmount = [UIView new];
  199. vAmount.frame=CGRectMake(0, height, Screen_Width, titleHeight+20);
  200. [headView addSubview:vAmount];
  201. UILabel *lblOldAmountTitle = [UILabel new];
  202. lblOldAmountTitle.frame=CGRectMake(lblx, valuey,170, valueheight);
  203. lblOldAmountTitle.font = [UIFont boldSystemFontOfSize:fontsize];
  204. lblOldAmountTitle.textColor=[UIColor redColor];
  205. lblOldAmountTitle.text = @"昨日老客户回款累计(元)";
  206. [vAmount addSubview:lblOldAmountTitle];
  207. UILabel *lblOldAmount = [UILabel new];
  208. lblOldAmount.frame=CGRectMake(lblx,CGRectGetMaxY(lblOldAmountTitle.frame),170, valueheight);
  209. lblOldAmount.textColor=[UIColor redColor];
  210. lblOldAmount.font = [UIFont boldSystemFontOfSize:fontsize];
  211. lblOldAmount.textAlignment=NSTextAlignmentCenter;
  212. lblOldAmount.text = kkOldAmountValue;
  213. [vAmount addSubview:lblOldAmount];
  214. UILabel *lblNewAmountTitle = [UILabel new];
  215. lblNewAmountTitle.frame=CGRectMake(Screen_Width/2, valuey,170, valueheight);
  216. lblNewAmountTitle.font = [UIFont boldSystemFontOfSize:fontsize];
  217. lblNewAmountTitle.textColor=[UIColor redColor];
  218. lblNewAmountTitle.text = @"昨日新客户回款累计(元)";
  219. [vAmount addSubview:lblNewAmountTitle];
  220. UILabel *lblNewAmount = [UILabel new];
  221. lblNewAmount.frame=CGRectMake(Screen_Width/2,CGRectGetMaxY(lblNewAmountTitle.frame),170, valueheight);
  222. lblNewAmount.textColor=[UIColor redColor];
  223. lblNewAmount.font = [UIFont boldSystemFontOfSize:fontsize];
  224. lblNewAmount.text = kkNewAmountValue;
  225. lblNewAmount.textAlignment=NSTextAlignmentCenter;
  226. [vAmount addSubview:lblNewAmount];
  227. //分割线
  228. viewBackgroud = [UIView new];
  229. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vAmount.frame), Screen_Width, heightLine);
  230. viewBackgroud.backgroundColor = LineBackgroundColor;
  231. [headView addSubview:viewBackgroud];
  232. height=CGRectGetMaxY(viewBackgroud.frame);
  233. }
  234. float margin = 5;
  235. //切换用户 —————————
  236. UIView *vchangeUser = [UIView new];
  237. vchangeUser.frame=CGRectMake(0, height, Screen_Width, titleHeight);
  238. [headView addSubview:vchangeUser];
  239. UIImageView *imgview = [UIImageView new];
  240. imgview.frame=CGRectMake(lblx, valuey+margin, 14, 19);
  241. [imgview setImage:[UIImage imageNamed:@"setting_change_user"]];
  242. [vchangeUser addSubview:imgview];
  243. UIButton *btnChangeUser = [UIButton buttonWithType:UIButtonTypeCustom];
  244. btnChangeUser.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  245. btnChangeUser.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  246. btnChangeUser.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  247. [btnChangeUser setTitle:@"切换用户" forState:UIControlStateNormal];
  248. [btnChangeUser setTitleColor:NavTitleColor forState:UIControlStateNormal];
  249. [btnChangeUser addTarget:self action:@selector(changeUser) forControlEvents:UIControlEventTouchUpInside];
  250. [vchangeUser addSubview:btnChangeUser];
  251. CGRect cg = CGRectMake(Screen_Width - lblx - 9,valuey+4,9,15 );
  252. bannerView = [[UIImageView alloc] initWithFrame:cg];
  253. [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  254. [vchangeUser addSubview:bannerView];
  255. viewBackgroud = [UIView new];
  256. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vchangeUser.frame), Screen_Width, heightLine);
  257. viewBackgroud.backgroundColor = LineBackgroundColor;
  258. [headView addSubview:viewBackgroud];
  259. // 修改密码
  260. UIView *vchangePw = [UIView new];
  261. vchangePw.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  262. [headView addSubview:vchangePw];
  263. imgview = [UIImageView new];
  264. imgview.frame=CGRectMake(lblx, valuey+margin, 14, 16);
  265. [imgview setImage:[UIImage imageNamed:@"setting_change_pw"]];
  266. [vchangePw addSubview:imgview];
  267. UIButton *btnChangePw = [UIButton buttonWithType:UIButtonTypeCustom];
  268. btnChangePw.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  269. btnChangePw.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  270. btnChangePw.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  271. [btnChangePw setTitle:@"修改密码" forState:UIControlStateNormal];
  272. [btnChangePw setTitleColor:NavTitleColor forState:UIControlStateNormal];
  273. [btnChangePw addTarget:self action:@selector(changePw) forControlEvents:UIControlEventTouchUpInside];
  274. [vchangePw addSubview:btnChangePw];
  275. bannerView = [[UIImageView alloc] initWithFrame:cg];
  276. [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  277. [vchangePw addSubview:bannerView];
  278. viewBackgroud = [UIView new];
  279. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vchangePw.frame), Screen_Width,heightLine);
  280. viewBackgroud.backgroundColor = LineBackgroundColor;
  281. [headView addSubview:viewBackgroud];
  282. //清除缓存
  283. UIView *vClear = [UIView new];
  284. vClear.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  285. [headView addSubview:vClear];
  286. imgview = [UIImageView new];
  287. imgview.frame=CGRectMake(lblx-3, valuey+2, 19, 19);
  288. [imgview setImage:[UIImage imageNamed:@"icon_clear"]];
  289. [vClear addSubview:imgview];
  290. UIButton *btnClear = [UIButton buttonWithType:UIButtonTypeCustom];
  291. btnClear.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin-2, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  292. btnClear.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  293. btnClear.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  294. [btnClear setTitle:@"清除缓存" forState:UIControlStateNormal];
  295. [btnClear setTitleColor:NavTitleColor forState:UIControlStateNormal];
  296. [btnClear addTarget:self action:@selector(clearData) forControlEvents:UIControlEventTouchUpInside];
  297. [vClear addSubview:btnClear];
  298. bannerView = [[UIImageView alloc] initWithFrame:cg];
  299. [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  300. [vClear addSubview:bannerView];
  301. lbSize = [[UILabel alloc] init];
  302. [self updateCacheSize:lbSize];
  303. lbSize.font = [UIFont systemFontOfSize:13];
  304. lbSize.textColor = [UIColor grayColor];
  305. [lbSize sizeToFit];
  306. lbSize.frame = CGRectMake(CGRectGetMaxX(bannerView.frame)- CGRectGetWidth(bannerView.frame)-CGRectGetWidth(lbSize.frame)-10, valuey+4, CGRectGetWidth(lbSize.frame), CGRectGetHeight(lbSize.frame));
  307. [vClear addSubview:lbSize];
  308. viewBackgroud = [UIView new];
  309. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vClear.frame), Screen_Width,heightLine);
  310. viewBackgroud.backgroundColor = LineBackgroundColor;
  311. [headView addSubview:viewBackgroud];
  312. // UIView *vPerformanceRank = [UIView new];
  313. // vPerformanceRank.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  314. // [headView addSubview:vPerformanceRank];
  315. //
  316. // imgview = [UIImageView new];
  317. // imgview.frame=CGRectMake(lblx, valuey + margin, 15, 16);
  318. // [imgview setImage:[UIImage imageNamed:@"performancerank"]];
  319. // [vPerformanceRank addSubview:imgview];
  320. //
  321. // UIButton *btnPerformanceRank= [UIButton buttonWithType:UIButtonTypeCustom];
  322. // btnPerformanceRank.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  323. // btnPerformanceRank.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  324. // btnPerformanceRank.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  325. // [btnPerformanceRank setTitle:@"业绩排行" forState:UIControlStateNormal];
  326. // [btnPerformanceRank setTitleColor:NavTitleColor forState:UIControlStateNormal];
  327. // [btnPerformanceRank addTarget:self action:@selector(performanceRank) forControlEvents:UIControlEventTouchUpInside];
  328. // [vPerformanceRank addSubview:btnPerformanceRank];
  329. //
  330. // bannerView = [[UIImageView alloc] initWithFrame:cg];
  331. // [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  332. // [vPerformanceRank addSubview:bannerView];
  333. //
  334. // viewBackgroud = [UIView new];
  335. // viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vPerformanceRank.frame), Screen_Width,heightLine);
  336. // viewBackgroud.backgroundColor = LineBackgroundColor;
  337. // [headView addSubview:viewBackgroud];
  338. // UIView *vNotification = [UIView new];
  339. // vNotification.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  340. // [headView addSubview:vNotification];
  341. //
  342. // imgview = [UIImageView new];
  343. // imgview.frame=CGRectMake(lblx, valuey + margin, 15, 15);
  344. // [imgview setImage:[UIImage imageNamed:@"notification"]];
  345. // [vNotification addSubview:imgview];
  346. //
  347. // UIButton *btnNotification= [UIButton buttonWithType:UIButtonTypeCustom];
  348. // btnNotification.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  349. // btnNotification.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  350. // btnNotification.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  351. // [btnNotification setTitle:@"通知公告" forState:UIControlStateNormal];
  352. // [btnNotification setTitleColor:NavTitleColor forState:UIControlStateNormal];
  353. // [btnNotification addTarget:self action:@selector(notification) forControlEvents:UIControlEventTouchUpInside];
  354. // [vNotification addSubview:btnNotification];
  355. //
  356. // bannerView = [[UIImageView alloc] initWithFrame:cg];
  357. // [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  358. // [vNotification addSubview:bannerView];
  359. //
  360. // viewBackgroud = [UIView new];
  361. // viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vNotification.frame), Screen_Width,heightLine);
  362. // viewBackgroud.backgroundColor = LineBackgroundColor;
  363. // [headView addSubview:viewBackgroud];
  364. // 退出登录
  365. UIView *vexit = [UIView new];
  366. vexit.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  367. [headView addSubview:vexit];
  368. imgview = [UIImageView new];
  369. imgview.frame=CGRectMake(lblx, valuey + margin, 15, 16);
  370. [imgview setImage:[UIImage imageNamed:@"setting_exit"]];
  371. [vexit addSubview:imgview];
  372. UIButton *btnExit= [UIButton buttonWithType:UIButtonTypeCustom];
  373. btnExit.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  374. btnExit.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  375. btnExit.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  376. [btnExit setTitle:@"退出登录" forState:UIControlStateNormal];
  377. [btnExit setTitleColor:NavTitleColor forState:UIControlStateNormal];
  378. [btnExit addTarget:self action:@selector(exitApp) forControlEvents:UIControlEventTouchUpInside];
  379. [vexit addSubview:btnExit];
  380. bannerView = [[UIImageView alloc] initWithFrame:cg];
  381. [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  382. [vexit addSubview:bannerView];
  383. viewBackgroud = [UIView new];
  384. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vexit.frame), Screen_Width,heightLine);
  385. viewBackgroud.backgroundColor = LineBackgroundColor;
  386. [headView addSubview:viewBackgroud];
  387. headView.frame=CGRectMake(0, CGRectGetMaxY(separatorView.frame), Screen_Width, CGRectGetMaxY(viewBackgroud.frame));
  388. }
  389. /**
  390. 隐藏键盘
  391. @param tap <#tap description#>
  392. */
  393. - (void)keyboardHide:(UITapGestureRecognizer*)tap{
  394. [self.view endEditing:YES];
  395. }
  396. /**
  397. 切换用户
  398. */
  399. - (void)changeUser{
  400. __weak typeof (self)weakself = self;
  401. // 初始化->
  402. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"切换用户" message:@"是否要切换用户吗?" preferredStyle:UIAlertControllerStyleAlert];
  403. // addAction->
  404. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  405. weakself.downManager = [[ASIDownManager alloc] init];
  406. weakself.downManager.delegate = self;
  407. weakself.downManager.onRequestSuccess = @selector(onLoadFinish:);
  408. weakself.downManager.onRequestFail = @selector(onLoadFail:);
  409. [weakself startLoading];
  410. NSString *urlStr = ServerURL;
  411. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  412. [dict setObject:@"SMDLogout" forKey:@"Action"];
  413. [dict setObject:kkAccountCode forKey:@"AccountCode"];
  414. [dict setObject:kkUserCode forKey:@"UserCode"];
  415. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  416. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  417. [weakself.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  418. }];
  419. // addAction->
  420. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
  421. }];
  422. UIColor *cancelColor = [UIColor blackColor];
  423. UIColor *sureColor = [UIColor redColor];
  424. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  425. [okAction setValue:sureColor forKey:@"titleTextColor"];
  426. [alert addAction:okAction];
  427. [alert addAction:cancelAction];
  428. // 展示->
  429. [self presentViewController:alert animated:YES completion:nil];
  430. }
  431. /**
  432. 修改密码
  433. */
  434. - (void)changePw{
  435. if(!_clickFlag){
  436. return;
  437. }
  438. _clickFlag = false;
  439. _passwordModify = [DKPWModifyAlterView alterViewWithTitle:@"密码修改" cancel:@"取消" sure:@"确定"];
  440. [self.view addSubview:_passwordModify];
  441. [[_passwordModify sureBt] addTarget:self action:@selector(surePW) forControlEvents:UIControlEventTouchUpInside];
  442. [[_passwordModify cancelBt] addTarget:self action:@selector(cancelPW) forControlEvents:UIControlEventTouchUpInside];
  443. }
  444. /**
  445. 退出app程序
  446. */
  447. - (void)exitApp{
  448. // NSMutableArray *arr = [NSMutableArray array];
  449. // NSLog(@"%@",arr[10]);
  450. if(!_clickFlag){
  451. return;
  452. }
  453. //初始化提示框;
  454. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"退出程序" message:@"是否要退出登录吗?" preferredStyle:UIAlertControllerStyleAlert ];
  455. // addAction->
  456. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  457. [self exit];
  458. }];
  459. // addAction->
  460. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
  461. }];
  462. UIColor *cancelColor = [UIColor blackColor];
  463. UIColor *sureColor = [UIColor redColor];
  464. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  465. [okAction setValue:sureColor forKey:@"titleTextColor"];
  466. [alert addAction:okAction];
  467. [alert addAction:cancelAction];
  468. // 3.显示alertController:presentViewController
  469. [self presentViewController:alert animated:YES completion:nil];
  470. }
  471. /**
  472. 退出登录
  473. */
  474. - (void) exit{
  475. if([[Util getNetWorkStates] isEqualToString:@"无网络"]){
  476. exit(0);
  477. return;
  478. }
  479. [self startLoading];
  480. NSString *urlStr = ServerURL;
  481. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  482. [dict setObject:@"SMDLogout" forKey:@"Action"];
  483. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  484. [dict setObject:kkUserCode forKey:@"UserCode"];
  485. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  486. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  487. self.downManager = [[ASIDownManager alloc] init];
  488. _downManager.delegate = self;
  489. _downManager.onRequestSuccess = @selector(onExitFinish:);
  490. _downManager.onRequestFail = @selector(onExitFail:);
  491. [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  492. }
  493. - (void) onExitFinish:(ASIDownManager *) sender {
  494. exit(0);
  495. }
  496. - (void) onExitFail:(ASIDownManager *) sender {
  497. exit(0);
  498. }
  499. -(void)loadStaffData{
  500. NSString *urlStr = ServerURL;
  501. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  502. [dict setObject:@"GetStaffRelations" forKey:@"Action"];
  503. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  504. [dict setObject:kkUserCode forKey:@"UserCode"];
  505. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  506. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  507. [dict setObject:kkUserID forKey:@"UserID"];
  508. self.downManager = [[ASIDownManager alloc] init];
  509. _downManager.delegate = self;
  510. _downManager.onRequestSuccess = @selector(onStaffLoadFinish:);
  511. _downManager.onRequestFail = @selector(onStaffLoadFail:);
  512. [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  513. }
  514. /**
  515. 加载数据成功回调
  516. @param sender <#sender description#>
  517. */
  518. - (void)onStaffLoadFinish:(ASIDownManager *)sender {
  519. // 服务器返回数据
  520. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  521. // 服务器返回数据状态值
  522. int iStatus = resultModel.status;
  523. // 服务器返回数据消息
  524. NSString *message = resultModel.message;
  525. // 服务器返回数据状态值正确
  526. if (iStatus == 0) {
  527. // 服务器返回数据结果
  528. NSArray * infoArr = (NSArray *)resultModel.result;
  529. if(infoArr!=nil&&infoArr.count>0){
  530. for(int i=0;i<infoArr.count;i++){
  531. NSDictionary *dic=[infoArr objectAtIndex:i];
  532. StaffModel *staffModel=[ StaffModel dk_modelWithDictionary:dic];
  533. [_staffList addObject:staffModel];
  534. }
  535. }
  536. }
  537. //
  538. // else if(iStatus == ActionResultStatusAuthError
  539. // ||iStatus == ActionResultStatusNoLogin
  540. // ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  541. // [self showReLoginDialog:message];
  542. // }
  543. // else {
  544. //
  545. // [self showAlertViewText:message];
  546. // }
  547. }
  548. /**
  549. 数据加载失败回调
  550. @param sender <#sender description#>
  551. */
  552. - (void)onStaffLoadFail:(ASIDownManager *)sender {
  553. [self showAlertViewText:@"网络异常"];
  554. }
  555. /**
  556. 确定修改密码
  557. */
  558. - (void)surePW{
  559. _originalPassword= _passwordModify.originalPassword.text;
  560. if(_originalPassword == nil||[_originalPassword isEqualToString:@""]){
  561. [self showAlertViewText:@"原密码不能为空"];
  562. return;
  563. }
  564. _newsPassword=_passwordModify.nePassword.text;
  565. if(_newsPassword == nil||[_newsPassword isEqualToString:@""]){
  566. [self showAlertViewText:@"新密码不能为空"];
  567. return;
  568. }
  569. _confirmPassword=_passwordModify.confirmPassword.text;
  570. if(_confirmPassword == nil||[_confirmPassword isEqualToString:@""]){
  571. [self showAlertViewText:@"确认密码不能为空"];
  572. return;
  573. }
  574. if(![_newsPassword isEqualToString:_confirmPassword]){
  575. [self showAlertViewText:@"新密码与确认密码不一致"];
  576. return;
  577. }
  578. self.downManager = [[ASIDownManager alloc] init];
  579. [self startLoading];
  580. self.downManager.delegate = self;
  581. self.downManager.onRequestSuccess = @selector(OnPasswordLoadFinish:);
  582. self.downManager.onRequestFail = @selector(OnPasswordLoadFail:);
  583. NSString *urlStr = ServerURL;
  584. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  585. [dict setObject:@"SaveUserPassWordIphone" forKey:@"Action"];
  586. [dict setObject:kkAccountCode forKey:@"AccountCode"];
  587. [dict setObject:kkUserCode forKey:@"UserCode"];
  588. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  589. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  590. [dict setObject:_originalPassword forKey:@"OldUserPassWord"];
  591. [dict setObject:_newsPassword forKey:@"NewUserPassword"];
  592. [self.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  593. }
  594. /**
  595. 取消修改密码
  596. */
  597. - (void)cancelPW{
  598. _clickFlag = true;
  599. [_passwordModify removeFromSuperview];
  600. }
  601. -(void)clearData{
  602. // // 找到Documents文件夹路径
  603. // NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  604. // NSString *dataFilePath = [documentsPath stringByAppendingPathComponent:@"IBOSSERROR"];
  605. //
  606. // NSFileManager *fileManager = [NSFileManager defaultManager];
  607. //
  608. // BOOL isDir = NO;
  609. //
  610. // // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  611. // BOOL existed = [fileManager fileExistsAtPath:dataFilePath isDirectory:&isDir];
  612. // NSError *error = nil;
  613. // if ( (isDir == YES && existed == YES) ) {
  614. // NSArray *fileList = [[NSArray alloc] init];
  615. // fileList = [fileManager contentsOfDirectoryAtPath:dataFilePath error:&error];
  616. // NSString* str = fileList.firstObject;
  617. // NSString *resultStr = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",dataFilePath,str] encoding:NSUTF8StringEncoding error:nil];
  618. // NSLog(@"%@",resultStr);
  619. // }
  620. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"清除缓存" message:@"确定要清除所有缓存吗?" preferredStyle:UIAlertControllerStyleAlert ];
  621. // addAction->
  622. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  623. [self deleteFile:IBOSSERROR];
  624. [self deleteFile:IBOSSIMAGE];
  625. [self deleteFile:IBOSSSOUND];
  626. [self updateCacheSize:lbSize];
  627. }];
  628. // addAction->
  629. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
  630. }];
  631. UIColor *cancelColor = [UIColor blackColor];
  632. UIColor *sureColor = [UIColor redColor];
  633. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  634. [okAction setValue:sureColor forKey:@"titleTextColor"];
  635. [alert addAction:okAction];
  636. [alert addAction:cancelAction];
  637. // 3.显示alertController:presentViewController
  638. [self presentViewController:alert animated:YES completion:nil];
  639. }
  640. /**
  641. 更新缓存大小
  642. @param lbSize <#lbSize description#>
  643. */
  644. - (void)updateCacheSize:(UILabel *) lbSize{
  645. CGFloat sizeIBOSSERROR = [self folderSizeAtPath: IBOSSERROR];
  646. CGFloat sizeIBOSSIMAGE = [self folderSizeAtPath: IBOSSIMAGE];
  647. CGFloat sizeIBOSSSOUND = [self folderSizeAtPath: IBOSSSOUND];
  648. CGFloat sum = sizeIBOSSERROR+sizeIBOSSIMAGE+sizeIBOSSSOUND;
  649. if(sum == 0){
  650. lbSize.hidden = YES;
  651. }else{
  652. lbSize.hidden = NO;
  653. }
  654. lbSize.text = [NSString stringWithFormat:@"约%.2fM",sum];
  655. [lbSize sizeToFit];
  656. }
  657. /**
  658. 删除Document下文件夹
  659. @param fileName <#fileName description#>
  660. */
  661. - (void)deleteFile:(NSString *) fileName{
  662. NSFileManager* fileManager=[NSFileManager defaultManager];
  663. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
  664. //文件名
  665. NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];
  666. BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];
  667. if (!blHave) {
  668. NSLog(@"no have");
  669. return ;
  670. }else {
  671. NSLog(@" have");
  672. BOOL blDele= [fileManager removeItemAtPath:uniquePath error:nil];
  673. if (blDele) {
  674. NSLog(@"dele success");
  675. }else {
  676. NSLog(@"dele fail");
  677. }
  678. }
  679. }
  680. //遍历文件夹获得文件夹大小,返回多少M
  681. - (float )folderSizeAtPath:(NSString*) folderPath{
  682. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
  683. //文件名
  684. folderPath=[[paths objectAtIndex:0] stringByAppendingPathComponent:folderPath];
  685. NSFileManager* manager = [NSFileManager defaultManager];
  686. if (![manager fileExistsAtPath:folderPath]) return 0;
  687. NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
  688. NSString* fileName;
  689. long long folderSize = 0;
  690. while ((fileName = [childFilesEnumerator nextObject]) != nil){
  691. NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
  692. folderSize += [self fileSizeAtPath:fileAbsolutePath];
  693. }
  694. return folderSize/(1024.0*1024.0);
  695. }
  696. //单个文件的大小
  697. - (long long) fileSizeAtPath:(NSString*) filePath{
  698. NSFileManager* manager = [NSFileManager defaultManager];
  699. if ([manager fileExistsAtPath:filePath]){
  700. return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
  701. }
  702. return 0;
  703. }
  704. -(void)performanceRank{
  705. PerformanceRankListVc *rankVc=[[PerformanceRankListVc alloc]init];
  706. self.hidesBottomBarWhenPushed=YES;
  707. rankVc.staffList=_staffList;
  708. [self.navigationController setNavigationBarHidden:NO animated:YES];
  709. [self.navigationController pushViewController:rankVc animated:YES];
  710. self.hidesBottomBarWhenPushed=NO;
  711. }
  712. -(void)notification{
  713. self.hidesBottomBarWhenPushed=YES;
  714. NotificationHomeVc *homeVC = [[NotificationHomeVc alloc] init];
  715. [self.navigationController pushViewController:homeVC animated:YES];
  716. [self.navigationController setNavigationBarHidden:NO animated:YES];
  717. self.hidesBottomBarWhenPushed=NO;
  718. }
  719. @end