MainTabVC.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. //
  2. // MainTabVC.m
  3. // IBOSS
  4. //
  5. // Created by iHope on 14-6-5.
  6. // Copyright (c) 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. #import "MainTabVC.h"
  9. #import "BusinessInfoViewController.h"
  10. #import "UITabBar+badge.h"
  11. @interface MainTabVC ()
  12. @end
  13. // MainTabVC对象
  14. static MainTabVC *gHomeCtrl = nil;
  15. @implementation MainTabVC
  16. #pragma 公共函数
  17. /**
  18. 初始化
  19. @param nibNameOrNil <#nibNameOrNil description#>
  20. @param nibBundleOrNil <#nibBundleOrNil description#>
  21. @return <#return value description#>
  22. */
  23. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  24. {
  25. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  26. if (self) {
  27. gHomeCtrl = self;
  28. }
  29. return self;
  30. }
  31. /**
  32. uicontroller
  33. @return <#return value description#>
  34. */
  35. + (UIViewController *)mRootCtrl {
  36. return gHomeCtrl;
  37. }
  38. /**
  39. viewDidLoad事件
  40. */
  41. - (void)viewDidLoad
  42. {
  43. [super viewDidLoad];
  44. // 业务处理
  45. self.businessvc = [[BusinessInfoViewController alloc] init];
  46. self.businessnavvc = [[BusinessNavVC alloc]initWithRootViewController:self.businessvc];
  47. self.businessnavvc.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:16]};
  48. self.businessnavvc.navigationBar.barTintColor = NavigationBarTintColor;
  49. self.businessnavvc.navigationBar.translucent=NO;
  50. [self.businessnavvc.navigationBar setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
  51. UITabBarItem *messageItem= [[UITabBarItem alloc] initWithTitle: @"业务处理" image: nil tag: 0];
  52. messageItem.image= [UIImage imageNamed:@"icon_business@2x.png"];
  53. UIImage *businessPressedImg= [UIImage imageNamed:@"icon_business_pressed@2x.png"];
  54. businessPressedImg = [businessPressedImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  55. [messageItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0.654 green:0 blue:0.027 alpha:1]} forState:UIControlStateSelected];
  56. messageItem.selectedImage= businessPressedImg;
  57. self.businessnavvc.tabBarItem = messageItem;
  58. //服务回执
  59. self.receiptvc = [[ReceiptInfoViewController alloc] init];
  60. self.receiptnavvc = [[ReceiptNavVC alloc]initWithRootViewController:self.receiptvc];
  61. self.receiptnavvc.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:16]};
  62. self.receiptnavvc.navigationBar.barTintColor = NavigationBarTintColor;
  63. self.receiptnavvc.navigationBar.translucent=NO;
  64. [self.receiptnavvc.navigationBar setShadowImage:[UIImage new]];
  65. [self.receiptnavvc.navigationBar setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
  66. UITabBarItem *receiptItem= [[UITabBarItem alloc] initWithTitle: @"服务回执" image: nil tag: 0];
  67. receiptItem.image= [UIImage imageNamed:@"receipt"];
  68. UIImage *receiptPressedImg= [UIImage imageNamed:@"receipt_pressed"];
  69. receiptPressedImg = [receiptPressedImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  70. [receiptItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0.654 green:0 blue:0.027 alpha:1]} forState:UIControlStateSelected];
  71. receiptItem.selectedImage= receiptPressedImg;
  72. self.receiptnavvc.tabBarItem = receiptItem;
  73. // 业务报表
  74. self.reportvc = [[ReportInfoViewController alloc] init];
  75. self.reportnavvc = [[ReportNavVC alloc] initWithRootViewController: self.reportvc];
  76. self.reportnavvc.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:16]};
  77. self.reportnavvc.navigationBar.barTintColor = NavigationBarTintColor;
  78. self.reportnavvc.navigationBar.translucent=NO;
  79. [self.reportnavvc.navigationBar setShadowImage:[UIImage new]];
  80. [self.reportnavvc.navigationBar setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
  81. UITabBarItem *customerItem = [[UITabBarItem alloc] initWithTitle: @"业务报表" image: nil tag: 1];
  82. customerItem.image = [UIImage imageNamed:@"icon_report@2x.png"];
  83. UIImage *reportPressedImg= [UIImage imageNamed:@"icon_report_pressed@2x.png"];
  84. reportPressedImg = [reportPressedImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  85. [customerItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0.654 green:0 blue:0.027 alpha:1]} forState:UIControlStateSelected];
  86. customerItem.selectedImage=reportPressedImg;
  87. self.reportvc.tabBarItem = customerItem;
  88. // 我的
  89. self.setvc = [[SettingViewController alloc] init];
  90. self.minenavvc = [[MineInfoNavVC alloc]initWithRootViewController:self.setvc];
  91. self.minenavvc.navigationBar.translucent=NO;
  92. [self.minenavvc.navigationBar setShadowImage:[UIImage new]];
  93. [self.minenavvc.navigationBar setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
  94. self.minenavvc.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:16]};
  95. self.minenavvc.navigationBar.barTintColor = NavigationBarTintColor;
  96. UITabBarItem *moreinfoItem= [[UITabBarItem alloc] initWithTitle: @"我的" image: nil tag: 2];
  97. moreinfoItem.image = [UIImage imageNamed:@"icon_mine@2x.png"];
  98. UIImage *minePressedImg= [UIImage imageNamed:@"icon_mine_pressed@2x.png"];
  99. minePressedImg = [minePressedImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  100. [moreinfoItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0.654 green:0 blue:0.027 alpha:1]} forState:UIControlStateSelected];
  101. moreinfoItem.selectedImage=minePressedImg;
  102. self.minenavvc.tabBarItem = moreinfoItem;
  103. [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
  104. NSArray *array = [NSArray arrayWithObjects:self.businessnavvc,self.receiptnavvc,self.reportnavvc,self.minenavvc,nil];
  105. self.viewControllers = array;
  106. NSString *currentDate= [DateFormat getCurrentDate];
  107. if([kkCurrentDate isEqualToString:@""]||kkCurrentDate==nil)
  108. {
  109. if(kkOldAmountValue!=nil&&kkOldAmountValue.length>0)
  110. {
  111. self.selectedIndex = 3;
  112. kkCurrentDate=currentDate;
  113. }
  114. else
  115. {
  116. self.selectedIndex = 0;
  117. }
  118. }
  119. else
  120. {
  121. if([currentDate isEqualToString:kkCurrentDate])
  122. {
  123. self.selectedIndex = 0;
  124. }
  125. else{
  126. self.selectedIndex = 3;
  127. }
  128. kkCurrentDate=currentDate;
  129. }
  130. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationHandler:) name:@"approveChange" object:nil];
  131. [self getApproveCount];
  132. }
  133. /**
  134. didReceiveMemoryWarning事件
  135. */
  136. - (void)didReceiveMemoryWarning
  137. {
  138. [super didReceiveMemoryWarning];
  139. }
  140. //!!!重点在viewWillAppear方法里调用下面两个方法
  141. -(void)viewWillAppear:(BOOL)animated{
  142. [self preferredStatusBarStyle];
  143. [self setStatusBarBackgroundColor:NavigationBarColor];
  144. }
  145. //设置状态栏颜色
  146. - (void)setStatusBarBackgroundColor:(UIColor *)color {
  147. self.selectedIndex = 3;
  148. if (@available(iOS 13.0, *)) {
  149. // iOS 13 弃用keyWindow属性 从所有windowl数组中取
  150. UIView *statusBar = [[UIView alloc]initWithFrame:[UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame] ;
  151. statusBar.backgroundColor = color;
  152. [[UIApplication sharedApplication].keyWindow addSubview:statusBar];
  153. } else{
  154. UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
  155. if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
  156. statusBar.backgroundColor = color;
  157. }
  158. }
  159. self.selectedIndex = 0;
  160. }
  161. - (void)setNeedsStatusBarAppearanceUpdate{
  162. [super setNeedsStatusBarAppearanceUpdate];
  163. }
  164. //设置状态栏的白色
  165. -(UIStatusBarStyle)preferredStatusBarStyle
  166. {
  167. return UIStatusBarStyleLightContent;
  168. }
  169. #pragma 委托函数
  170. /**
  171. 数据加载成功函数
  172. @param sender <#sender description#>
  173. */
  174. - (void)onLoadFinish:(ASIDownManager *)sender {
  175. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  176. int status= resultModel.status;
  177. NSString *message=resultModel.message;
  178. if(status==0){
  179. NSArray *arrResult=(NSArray*)resultModel.result;
  180. if(arrResult.count==0){
  181. [self.tabBar hideBadgeOnItemIndex:0];
  182. }
  183. else{
  184. [self.tabBar showBadgeOnItemIndex:0];
  185. }
  186. }
  187. }
  188. /**
  189. 数据加载失败函数
  190. @param sender sender description
  191. */
  192. - (void)onLoadFail:(ASIDownManager *)sender{
  193. [self showAlertViewText:@"网络异常"];
  194. }
  195. #pragma 私有函数
  196. /**
  197. 加载审批数据
  198. */
  199. - (void)getApproveCount{
  200. self.mDownManager = [[ASIDownManager alloc] init];
  201. _mDownManager.delegate = self;
  202. _mDownManager.onRequestSuccess = @selector(onLoadFinish:);
  203. _mDownManager.onRequestFail = @selector(onLoadFail:);
  204. NSString *urlStr = ServerURL;
  205. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  206. [dict setObject:@"GetAuditList" forKey:@"Action"];
  207. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  208. [dict setObject:kkUserCode forKey:@"UserCode"];
  209. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  210. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  211. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  212. }
  213. /**
  214. 显示消息
  215. @param text <#text description#>
  216. */
  217. - (void)showAlertViewText:(NSString *)text
  218. {
  219. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:text preferredStyle:UIAlertControllerStyleAlert ];
  220. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  221. }]];
  222. // 3.显示alertController:presentViewController
  223. [self presentViewController:alert animated:YES completion:nil];
  224. }
  225. /**
  226. 自定义接收信息和处理的方法
  227. @param notification <#notification description#>
  228. */
  229. - (void) notificationHandler:(NSNotification *) notification{
  230. [self getApproveCount];
  231. }
  232. @end