123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- //
- // 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 ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, assign) NSUInteger currentPage;
- @property (nonatomic, assign) NSUInteger totalPage;
- @property (nonatomic, assign) NSUInteger totalRecord;
- @property (nonatomic, assign) BOOL isFresh;
- @property (nonatomic, strong) NSMutableArray <NoticeModel*>*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<NSKeyValueChangeKey,id> *)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<NoticeModel *> *)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
|