NoticeUnreadVC.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. //
  2. // NoticeUnreadVC.m
  3. // smartRhino
  4. //
  5. // Created by armin on 2019/11/6.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "NoticeUnreadVC.h"
  9. #import "NoticeUnreadCell.h"
  10. #import "ChatMsgSearchHistoryVC.h"
  11. #import "SelectModel.h"
  12. #import "MailListDetailVC.h"
  13. #import "ReadSearchVC.h"
  14. @interface NoticeUnreadVC ()<UITableViewDelegate,UITableViewDataSource>
  15. @property (strong, nonatomic) IBOutlet UITableView *tableView;
  16. @property (strong, nonatomic) UILabel *nodataLabel;
  17. @property (strong, nonatomic) IBOutlet UIView *topTitleBgView;
  18. @property (strong, nonatomic) IBOutlet UIView *leftTitleBgView;
  19. @property (strong, nonatomic) IBOutlet UIView *rightTitleBgView;
  20. @property (strong, nonatomic) IBOutlet UIButton *leftTitleBtn;
  21. @property (strong, nonatomic) IBOutlet UIButton *rightTitleBtn;
  22. @property (assign, nonatomic) NSInteger searchType;
  23. @property (strong, nonatomic) NSMutableArray *dataArray;
  24. @end
  25. @implementation NoticeUnreadVC
  26. +(NoticeUnreadVC *)initNoticeUnreadVC{
  27. NoticeUnreadVC *controller = [StoryboardManager.shared.chatMsgNotice instantiateViewControllerWithIdentifier:@"NoticeUnreadVC"];
  28. return controller;
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. self.fd_prefersNavigationBarHidden = YES;
  33. self.view.backgroundColor = RGB(255, 255, 255);
  34. [self initTopTitleStatusView:YES];
  35. if (@available(iOS 11.0, *)) {
  36. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  37. } else {
  38. self.automaticallyAdjustsScrollViewInsets = NO;
  39. }
  40. self.tableView.delegate = self;
  41. self.tableView.dataSource = self;
  42. self.tableView.backgroundColor = [UIColor clearColor];
  43. }
  44. -(void)initTopTitleStatusView:(BOOL)isLeft{
  45. if(isLeft){
  46. self.searchType = 1;
  47. [self.topTitleBgView setRadius:self.topTitleBgView.height/2 borderColor:RGB(204, 204, 204) borderWidth:0.3];
  48. self.leftTitleBgView.backgroundColor =RGB(230, 230, 230);
  49. [self.leftTitleBtn setTitleColor:RGB(10, 10, 10) forState:UIControlStateNormal];
  50. self.rightTitleBgView.backgroundColor = RGB(246, 246, 246);
  51. [self.rightTitleBtn setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal];
  52. }else{
  53. self.searchType = 2;
  54. [self.topTitleBgView setRadius:self.topTitleBgView.height/2 borderColor:RGB(204, 204, 204) borderWidth:0.3];
  55. self.leftTitleBgView.backgroundColor = RGB(246, 246, 246);
  56. [self.leftTitleBtn setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal];
  57. self.rightTitleBgView.backgroundColor = RGB(230, 230, 230);
  58. [self.rightTitleBtn setTitleColor:RGB(10, 10, 10) forState:UIControlStateNormal];
  59. }
  60. [self.leftTitleBtn setTitle:[NSString stringWithFormat:@"已读(%ld)",(long)self.readCount] forState:UIControlStateNormal];
  61. [self.rightTitleBtn setTitle:[NSString stringWithFormat:@"未读(%ld)",(long)self.unReadCount] forState:UIControlStateNormal];
  62. switch (self.type) {
  63. case ReadNoticeType:
  64. {
  65. [self getDataNotice];
  66. }
  67. break;
  68. case ReadMissiveType:
  69. {
  70. [self getDataMissive];
  71. }
  72. break;
  73. default:
  74. break;
  75. }
  76. WS(weakSelf);
  77. [self.leftTitleBtn setAction:^{
  78. [weakSelf initTopTitleStatusView:YES];
  79. }];
  80. [self.rightTitleBtn setAction:^{
  81. [weakSelf initTopTitleStatusView:NO];
  82. }];
  83. }
  84. - (void)getDataNotice
  85. {
  86. [self.dataArray removeAllObjects];
  87. NSDictionary * dict = @{@"ReadType":@(self.searchType),
  88. @"NoticeId":@(self.Id),
  89. @"Key":@""
  90. };
  91. SHOWLOADING
  92. WS(weakSelf);
  93. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_Notice_Read) parameters:dict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  94. REMOVESHOW
  95. NSLog(@"%@",responseObject);
  96. if ([responseObject isKindOfClass:[NSArray class]]) {
  97. for (NSDictionary * dic in responseObject) {
  98. SelectModel * model = [[SelectModel alloc] init];
  99. model.UserId = [[dic objectForKey:@"UserId"] integerValue];
  100. model.UserName = [dic objectForKey:@"Name"];
  101. model.AvatarUrl = [dic objectForKey:@"AvatarUrl"];
  102. model.DepartmentName = [dic objectForKey:@"DepartmentName"];
  103. model.LastModifiedDate = [dic objectForKey:@"LastModifiedDate"];
  104. [weakSelf.dataArray addObject:model];
  105. }
  106. }
  107. dispatch_async(dispatch_get_main_queue(), ^{
  108. [weakSelf.tableView reloadData];
  109. [weakSelf nodataAddToTable];
  110. });
  111. } failure:^(NSError * _Nonnull error) {
  112. REMOVESHOW
  113. }];
  114. }
  115. - (void)getDataMissive
  116. {
  117. [self.dataArray removeAllObjects];
  118. NSDictionary * dict = @{@"ReadType":@(self.searchType),
  119. @"MissiveId":@(self.Id),
  120. @"Key":@""
  121. };
  122. SHOWLOADING
  123. WS(weakSelf);
  124. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_Missive_Read) parameters:dict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  125. REMOVESHOW
  126. NSLog(@"%@",responseObject);
  127. if ([responseObject isKindOfClass:[NSArray class]]) {
  128. for (NSDictionary * dic in responseObject) {
  129. SelectModel * model = [[SelectModel alloc] init];
  130. model.UserId = [[dic objectForKey:@"UserId"] integerValue];
  131. model.UserName = [dic objectForKey:@"Name"];
  132. model.AvatarUrl = [dic objectForKey:@"AvatarUrl"];
  133. model.DepartmentName = [dic objectForKey:@"DepartmentName"];
  134. model.LastModifiedDate = [dic objectForKey:@"LastModifiedDate"];
  135. [weakSelf.dataArray addObject:model];
  136. }
  137. }
  138. dispatch_async(dispatch_get_main_queue(), ^{
  139. [weakSelf.tableView reloadData];
  140. [weakSelf nodataAddToTable];
  141. });
  142. } failure:^(NSError * _Nonnull error) {
  143. REMOVESHOW
  144. }];
  145. }
  146. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  147. return 2;
  148. }
  149. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  150. switch (section) {
  151. case 0:{
  152. return 1;
  153. }break;
  154. case 1:{
  155. return self.dataArray.count;
  156. }break;
  157. default:break;
  158. }
  159. return 0;
  160. }
  161. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  162. switch (indexPath.section) {
  163. case 0:{
  164. return [NoticeUnreadCell configCell0Height];
  165. }break;
  166. case 1:{
  167. return [NoticeUnreadCell configCell1Height];
  168. }break;
  169. default:break;
  170. }
  171. return 0;
  172. }
  173. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  174. switch (indexPath.section) {
  175. case 0:{
  176. NoticeUnreadCell *cell = [NoticeUnreadCell configCell0:tableView indexPath:indexPath];
  177. WS(weakSelf);
  178. [cell.cell0SearchBtn setAction:^{
  179. ReadSearchVC * vc = [[ReadSearchVC alloc] init];
  180. vc.dataArray = weakSelf.dataArray;
  181. [weakSelf.navigationController pushViewController:vc animated:YES];
  182. }];
  183. return cell;
  184. }break;
  185. case 1:{
  186. SelectModel * model = [self.dataArray objectAtIndex:indexPath.row];
  187. NoticeUnreadCell *cell = [NoticeUnreadCell configCell1:tableView indexPath:indexPath];
  188. [cell.cell1ImageView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  189. cell.cell1TitleLabel.text = model.UserName;
  190. cell.cell1IntroLabel.text = model.DepartmentName;
  191. cell.cell1TimeLabel.hidden = self.searchType == 2 ? YES : NO;
  192. cell.cell1TimeLabel.text = [ZYCTool monthAndDayAndHoursAndMinutes:model.LastModifiedDate];
  193. return cell;
  194. }break;
  195. default:break;
  196. }
  197. return nil;
  198. }
  199. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  200. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  201. if (indexPath.section > 0) {
  202. SelectModel * model = [self.dataArray objectAtIndex:indexPath.row];
  203. MailListDetailVC *vc = [MailListDetailVC initMailListDetailVC];
  204. vc.indexId = model.UserId;
  205. [self.navigationController pushViewController:vc animated:YES];
  206. }
  207. }
  208. -(void)nodataAddToTable{
  209. if(self.dataArray.count == 0){
  210. [self.tableView addSubview:self.nodataLabel];
  211. self.nodataLabel.hidden = NO;
  212. self.nodataLabel.frame = CGRectMake(0, (SCREEN_HEIGHT-kNavigationHeight)/2, SCREEN_WIDTH, 20);
  213. }else{
  214. self.nodataLabel.hidden = YES;
  215. }
  216. }
  217. -(UILabel *)nodataLabel{
  218. if(!_nodataLabel){
  219. _nodataLabel = [[UILabel alloc] init];
  220. _nodataLabel.font = [UIFont systemFontOfSize:12];
  221. _nodataLabel.textColor = RGB(153, 153, 153);
  222. _nodataLabel.textAlignment = NSTextAlignmentCenter;
  223. _nodataLabel.hidden = YES;
  224. _nodataLabel.text = @"暂无数据";
  225. }
  226. return _nodataLabel;
  227. }
  228. - (NSMutableArray *)dataArray
  229. {
  230. if (!_dataArray) {
  231. _dataArray = [NSMutableArray array];
  232. }
  233. return _dataArray;
  234. }
  235. @end