// // TDGroupSearchResultVC.m // smartRhino // // Created by niuzhen on 2019/12/12. // Copyright © 2019 tederen. All rights reserved. // #import "TDGroupSearchResultVC.h" #import "TDGroupSearchCell.h" #import "TDGroupInfoListVC.h" #import "MyTDGroupViewController.h" #import "ChatNewRowCell.h" @interface TDGroupSearchResultVC () @property (nonatomic, assign) NSUInteger currentPage; @property (nonatomic, assign) NSUInteger totalPage; @property (nonatomic, assign) NSUInteger totalRecord; @property (nonatomic, assign) BOOL isFresh; @property (nonatomic, strong) NSMutableArray *listArray; @end @implementation TDGroupSearchResultVC - (void)viewDidLoad { self.historySearchType = HistorySearchType_Group; [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.view.backgroundColor = RGB(255, 255, 255); self.currentPage = 1; self.totalPage = 1; self.isFresh = YES; self.tableView.delegate = self; self.tableView.dataSource = self; self.historySearchType = HistorySearchType_Group; [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { id obj = [change objectForKey:@"new"]; NSString * text = @""; if ([obj isKindOfClass:[NSString class]]) { text = obj; }else{ text = [obj stringValue]; } if (text.length > 0) { [self headRefresh]; } } #pragma mark - UItableView刷新 - (void)setTableViewRefresh{ WeakSelf(self) self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ [weakself headRefresh]; }]; self.tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{ [weakself footerRefresh]; }]; [self.tableView.mj_header beginRefreshing]; } - (void)headRefresh{ self.isFresh = YES; [self getData]; self.currentPage = 1; [self.tableView.mj_header endRefreshing]; } - (void)footerRefresh{ self.isFresh = NO; self.currentPage += 1; [self.listArray removeAllObjects]; if (self.totalRecord == self.listArray.count) { self.currentPage --; [self.tableView.mj_footer endRefreshing]; return ; } [self.tableView.mj_footer endRefreshing]; } - (void)getData { if (self.searchText.length == 0) { return; } SHOWLOADING WS(weakSelf); NSDictionary * paraDict = @{@"GroupFolderId":@(self.ParentId), @"UserId":@([AppUserModel sharedAppUserModel].Id), @"Key":self.searchText, // @"Page":@(self.currentPage), // @"PerPage":@(20), @"Sort":@"" }; [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Find) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) { REMOVESHOW NSLog(@"%@",responseObject); NoticeListModel *listModel = [[NoticeListModel alloc] initWithDictionary:responseObject error:nil]; weakSelf.totalRecord = listModel.Total; if (weakSelf.isFresh) { [weakSelf.listArray removeAllObjects]; } [weakSelf.listArray addObjectsFromArray:listModel.Items]; dispatch_async(dispatch_get_main_queue(), ^{ if (weakSelf.listArray.count > 0) { weakSelf.collectionView.hidden = YES; weakSelf.noDataView.hidden = YES; weakSelf.tableView.hidden = NO; [weakSelf.tableView reloadData]; }else{ weakSelf.noDataView.hidden = NO; weakSelf.collectionView.hidden = YES; weakSelf.tableView.hidden = YES; weakSelf.noDataL.text = @"暂无内容"; } }); } failure:^(NSError * _Nonnull error) { REMOVESHOW }]; } - (NSMutableArray *)listArray{ if (!_listArray) { _listArray = [NSMutableArray new]; } return _listArray; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.listArray.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 65.f; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NoticeModel *model = [self.listArray objectAtIndex:indexPath.row]; switch (model.AttributeValue) { case 2:{ ChatNewRowCell *cell = [ChatNewRowCell configCell1:tableView indexPath:indexPath]; cell.cell1TitleLabel.text = model.FolderName; cell.IsTopImgV.hidden = !model.IsTop; cell.cell1TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.FileCount]; cell.cell1TimeLabel.hidden = model.FileCount == 0 ? YES : NO; return cell; }break; default:{ ChatNewRowCell *cell = [ChatNewRowCell configCell2:tableView indexPath:indexPath]; [cell.cell2UserImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage]; cell.cell2TitleLabel.text = model.GroupName; cell.IsTopImgV.hidden = !model.IsTop; cell.cell2IntroLabel.text = [NSString stringWithFormat:@"共享给%ld人",(long)model.TopicSharingCount]; cell.cell2TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.TopicAllCount]; cell.cell2TimeLabel.hidden = model.TopicAllCount == 0 ? YES : NO; cell.cell2RedNumLabel.text = model.UReadTopicCount > 0 ? [NSString stringWithFormat:@"[%ld条新话题]",(long)model.UReadTopicCount] : @""; return cell; }break; } // TDGroupSearchCell *cell = [TDGroupSearchCell configCell:tableView indexPath:indexPath]; // [cell.imagV sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage]; //// cell.nameL.attributedText = [self checkOfString:model.GroupName]; // cell.nameL.attributedText = [ZYCTool checkOfString:model.GroupName withSearchText:self.searchText]; // cell.subL.text = [NSString stringWithFormat:@"共享给%ld人",(long)model.TopicSharingCount]; // if (model.ParentId == 0) { // [cell.listBtn setTitle:@"根目录" forState:UIControlStateNormal]; // [cell.listBtn setTitleColor:UIColorHex(#999999) forState:UIControlStateNormal]; // }else{ // [cell.listBtn setTitle:model.CategoryName forState:UIControlStateNormal]; // [cell.listBtn setTitleColor:UIColorHex(#1F87DB) forState:UIControlStateNormal]; // } // WS(weakSelf); // [cell.listBtn setAction:^{ // MyTDGroupViewController *vc = [[MyTDGroupViewController alloc] init]; // vc.ParentId = model.ParentId; // vc.isSubVC = YES; // vc.titleStr = model.ParentId == 0 ? @"小组" : model.CategoryName; // [weakSelf.navigationController pushViewController:vc animated:YES]; // }]; // return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NoticeModel *model = [self.listArray objectAtIndex:indexPath.row]; [tableView deselectRowAtIndexPath:indexPath animated:YES]; if(model && model != nil) { switch (model.AttributeValue) { case 2:{ MyTDGroupViewController *vc = [[MyTDGroupViewController alloc] init]; vc.ParentId = model.Id; vc.isSubVC = YES; vc.isSelect = self.isSelect; vc.titleStr = model.FolderName; [self.navigationController pushViewController:vc animated:YES]; }break; default:{ if (self.isReturn) { MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC]; vc.Id = model.GroupId; // vc.type = self.type == 0 ? CollectModel_Group : self.type; vc.type = CollectModel_Toipc; vc.isReturn = self.isReturn; vc.sendModel = self.sendModel; [self.navigationController pushViewController:vc animated:YES]; }else{ if (self.isSelect) { [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_SELECTCREATENOTEFOLDER object:nil userInfo:@{@"FolderId":@(model.GroupId),@"FolderName":model.GroupName}]; [self back1]; }else{ TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC]; vc.titleStr = model.GroupName; vc.GroupId = model.GroupId; vc.type = CollectModel_Toipc; // vc.sendModel = self.sendModel; [self.navigationController pushViewController:vc animated:YES]; } } }break; } } } - (void)back1 { if (self.isSelect) { for (NSInteger i = (self.navigationController.viewControllers.count - 1); i >= 0; i --) { UIViewController *vc = self.navigationController.viewControllers[i]; if ([vc isKindOfClass:NSClassFromString(@"MyTDTopicCreateVC")]) { [self.navigationController popToViewController:vc animated:YES]; return; } } }else{ [self.navigationController popViewControllerAnimated:YES]; } } @end