123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- //
- // NoticeUnreadVC.m
- // smartRhino
- //
- // Created by armin on 2019/11/6.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "NoticeUnreadVC.h"
- #import "NoticeUnreadCell.h"
- #import "ChatMsgSearchHistoryVC.h"
- #import "SelectModel.h"
- #import "MailListDetailVC.h"
- #import "ReadSearchVC.h"
- @interface NoticeUnreadVC ()<UITableViewDelegate,UITableViewDataSource>
- @property (strong, nonatomic) IBOutlet UITableView *tableView;
- @property (strong, nonatomic) UILabel *nodataLabel;
- @property (strong, nonatomic) IBOutlet UIView *topTitleBgView;
- @property (strong, nonatomic) IBOutlet UIView *leftTitleBgView;
- @property (strong, nonatomic) IBOutlet UIView *rightTitleBgView;
- @property (strong, nonatomic) IBOutlet UIButton *leftTitleBtn;
- @property (strong, nonatomic) IBOutlet UIButton *rightTitleBtn;
- @property (assign, nonatomic) NSInteger searchType;
- @property (strong, nonatomic) NSMutableArray *dataArray;
- @end
- @implementation NoticeUnreadVC
- +(NoticeUnreadVC *)initNoticeUnreadVC{
- NoticeUnreadVC *controller = [StoryboardManager.shared.chatMsgNotice instantiateViewControllerWithIdentifier:@"NoticeUnreadVC"];
- return controller;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.fd_prefersNavigationBarHidden = YES;
- self.view.backgroundColor = RGB(255, 255, 255);
-
- [self initTopTitleStatusView:YES];
-
- if (@available(iOS 11.0, *)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.backgroundColor = [UIColor clearColor];
- }
- -(void)initTopTitleStatusView:(BOOL)isLeft{
- if(isLeft){
- self.searchType = 1;
- [self.topTitleBgView setRadius:self.topTitleBgView.height/2 borderColor:RGB(204, 204, 204) borderWidth:0.3];
- self.leftTitleBgView.backgroundColor =RGB(230, 230, 230);
- [self.leftTitleBtn setTitleColor:RGB(10, 10, 10) forState:UIControlStateNormal];
- self.rightTitleBgView.backgroundColor = RGB(246, 246, 246);
- [self.rightTitleBtn setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal];
- }else{
- self.searchType = 2;
- [self.topTitleBgView setRadius:self.topTitleBgView.height/2 borderColor:RGB(204, 204, 204) borderWidth:0.3];
- self.leftTitleBgView.backgroundColor = RGB(246, 246, 246);
- [self.leftTitleBtn setTitleColor:RGB(153, 153, 153) forState:UIControlStateNormal];
- self.rightTitleBgView.backgroundColor = RGB(230, 230, 230);
- [self.rightTitleBtn setTitleColor:RGB(10, 10, 10) forState:UIControlStateNormal];
- }
-
- [self.leftTitleBtn setTitle:[NSString stringWithFormat:@"已读(%ld)",(long)self.readCount] forState:UIControlStateNormal];
- [self.rightTitleBtn setTitle:[NSString stringWithFormat:@"未读(%ld)",(long)self.unReadCount] forState:UIControlStateNormal];
- switch (self.type) {
- case ReadNoticeType:
- {
- [self getDataNotice];
- }
- break;
- case ReadMissiveType:
- {
- [self getDataMissive];
- }
- break;
- default:
- break;
- }
-
- WS(weakSelf);
- [self.leftTitleBtn setAction:^{
- [weakSelf initTopTitleStatusView:YES];
- }];
- [self.rightTitleBtn setAction:^{
- [weakSelf initTopTitleStatusView:NO];
- }];
- }
- - (void)getDataNotice
- {
- [self.dataArray removeAllObjects];
- NSDictionary * dict = @{@"ReadType":@(self.searchType),
- @"NoticeId":@(self.Id),
- @"Key":@""
- };
- SHOWLOADING
- WS(weakSelf);
- [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_Notice_Read) parameters:dict responseStyle:JOSN success:^(id _Nonnull responseObject) {
- REMOVESHOW
- NSLog(@"%@",responseObject);
- if ([responseObject isKindOfClass:[NSArray class]]) {
- for (NSDictionary * dic in responseObject) {
- SelectModel * model = [[SelectModel alloc] init];
- model.UserId = [[dic objectForKey:@"UserId"] integerValue];
- model.UserName = [dic objectForKey:@"Name"];
- model.AvatarUrl = [dic objectForKey:@"AvatarUrl"];
- model.DepartmentName = [dic objectForKey:@"DepartmentName"];
- model.LastModifiedDate = [dic objectForKey:@"LastModifiedDate"];
- [weakSelf.dataArray addObject:model];
- }
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- [weakSelf nodataAddToTable];
- });
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- }];
- }
- - (void)getDataMissive
- {
- [self.dataArray removeAllObjects];
- NSDictionary * dict = @{@"ReadType":@(self.searchType),
- @"MissiveId":@(self.Id),
- @"Key":@""
- };
- SHOWLOADING
- WS(weakSelf);
- [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_Missive_Read) parameters:dict responseStyle:JOSN success:^(id _Nonnull responseObject) {
- REMOVESHOW
- NSLog(@"%@",responseObject);
- if ([responseObject isKindOfClass:[NSArray class]]) {
- for (NSDictionary * dic in responseObject) {
- SelectModel * model = [[SelectModel alloc] init];
- model.UserId = [[dic objectForKey:@"UserId"] integerValue];
- model.UserName = [dic objectForKey:@"Name"];
- model.AvatarUrl = [dic objectForKey:@"AvatarUrl"];
- model.DepartmentName = [dic objectForKey:@"DepartmentName"];
- model.LastModifiedDate = [dic objectForKey:@"LastModifiedDate"];
- [weakSelf.dataArray addObject:model];
- }
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- [weakSelf nodataAddToTable];
- });
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- }];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 2;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- switch (section) {
- case 0:{
- return 1;
- }break;
- case 1:{
- return self.dataArray.count;
- }break;
- default:break;
- }
- return 0;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- switch (indexPath.section) {
- case 0:{
- return [NoticeUnreadCell configCell0Height];
- }break;
- case 1:{
- return [NoticeUnreadCell configCell1Height];
- }break;
- default:break;
- }
- return 0;
- }
-
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- switch (indexPath.section) {
- case 0:{
- NoticeUnreadCell *cell = [NoticeUnreadCell configCell0:tableView indexPath:indexPath];
- WS(weakSelf);
- [cell.cell0SearchBtn setAction:^{
- ReadSearchVC * vc = [[ReadSearchVC alloc] init];
- vc.dataArray = weakSelf.dataArray;
- [weakSelf.navigationController pushViewController:vc animated:YES];
- }];
- return cell;
- }break;
- case 1:{
- SelectModel * model = [self.dataArray objectAtIndex:indexPath.row];
- NoticeUnreadCell *cell = [NoticeUnreadCell configCell1:tableView indexPath:indexPath];
- [cell.cell1ImageView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
- cell.cell1TitleLabel.text = model.UserName;
- cell.cell1IntroLabel.text = model.DepartmentName;
- cell.cell1TimeLabel.hidden = self.searchType == 2 ? YES : NO;
- cell.cell1TimeLabel.text = [ZYCTool monthAndDayAndHoursAndMinutes:model.LastModifiedDate];
- return cell;
- }break;
- default:break;
- }
- return nil;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- if (indexPath.section > 0) {
- SelectModel * model = [self.dataArray objectAtIndex:indexPath.row];
- MailListDetailVC *vc = [MailListDetailVC initMailListDetailVC];
- vc.indexId = model.UserId;
- [self.navigationController pushViewController:vc animated:YES];
- }
- }
- -(void)nodataAddToTable{
- if(self.dataArray.count == 0){
- [self.tableView addSubview:self.nodataLabel];
- self.nodataLabel.hidden = NO;
- self.nodataLabel.frame = CGRectMake(0, (SCREEN_HEIGHT-kNavigationHeight)/2, SCREEN_WIDTH, 20);
- }else{
- self.nodataLabel.hidden = YES;
- }
- }
- -(UILabel *)nodataLabel{
- if(!_nodataLabel){
- _nodataLabel = [[UILabel alloc] init];
- _nodataLabel.font = [UIFont systemFontOfSize:12];
- _nodataLabel.textColor = RGB(153, 153, 153);
- _nodataLabel.textAlignment = NSTextAlignmentCenter;
- _nodataLabel.hidden = YES;
- _nodataLabel.text = @"暂无数据";
- }
- return _nodataLabel;
- }
- - (NSMutableArray *)dataArray
- {
- if (!_dataArray) {
- _dataArray = [NSMutableArray array];
- }
- return _dataArray;
- }
- @end
|