// // 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" @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]; 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]; TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC]; vc.GroupId = model.GroupId; vc.titleStr = model.GroupName; [self.navigationController pushViewController:vc animated:YES]; } @end