TDGroupSearchResultVC.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. //
  2. // TDGroupSearchResultVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2019/12/12.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "TDGroupSearchResultVC.h"
  9. #import "TDGroupSearchCell.h"
  10. #import "TDGroupInfoListVC.h"
  11. #import "MyTDGroupViewController.h"
  12. #import "ChatNewRowCell.h"
  13. @interface TDGroupSearchResultVC ()<UITableViewDelegate,UITableViewDataSource>
  14. @property (nonatomic, assign) NSUInteger currentPage;
  15. @property (nonatomic, assign) NSUInteger totalPage;
  16. @property (nonatomic, assign) NSUInteger totalRecord;
  17. @property (nonatomic, assign) BOOL isFresh;
  18. @property (nonatomic, strong) NSMutableArray <NoticeModel*>*listArray;
  19. @end
  20. @implementation TDGroupSearchResultVC
  21. - (void)viewDidLoad {
  22. self.historySearchType = HistorySearchType_Group;
  23. [super viewDidLoad];
  24. self.fd_prefersNavigationBarHidden = YES;
  25. self.view.backgroundColor = RGB(255, 255, 255);
  26. self.currentPage = 1;
  27. self.totalPage = 1;
  28. self.isFresh = YES;
  29. self.tableView.delegate = self;
  30. self.tableView.dataSource = self;
  31. self.historySearchType = HistorySearchType_Group;
  32. [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil];
  33. }
  34. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  35. {
  36. id obj = [change objectForKey:@"new"];
  37. NSString * text = @"";
  38. if ([obj isKindOfClass:[NSString class]]) {
  39. text = obj;
  40. }else{
  41. text = [obj stringValue];
  42. }
  43. if (text.length > 0) {
  44. [self headRefresh];
  45. }
  46. }
  47. #pragma mark - UItableView刷新
  48. - (void)setTableViewRefresh{
  49. WeakSelf(self)
  50. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  51. [weakself headRefresh];
  52. }];
  53. self.tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
  54. [weakself footerRefresh];
  55. }];
  56. [self.tableView.mj_header beginRefreshing];
  57. }
  58. - (void)headRefresh{
  59. self.isFresh = YES;
  60. [self getData];
  61. self.currentPage = 1;
  62. [self.tableView.mj_header endRefreshing];
  63. }
  64. - (void)footerRefresh{
  65. self.isFresh = NO;
  66. self.currentPage += 1;
  67. [self.listArray removeAllObjects];
  68. if (self.totalRecord == self.listArray.count) {
  69. self.currentPage --;
  70. [self.tableView.mj_footer endRefreshing];
  71. return ;
  72. }
  73. [self.tableView.mj_footer endRefreshing];
  74. }
  75. - (void)getData
  76. {
  77. if (self.searchText.length == 0) {
  78. return;
  79. }
  80. SHOWLOADING
  81. WS(weakSelf);
  82. NSDictionary * paraDict = @{@"GroupFolderId":@(self.ParentId),
  83. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  84. @"Key":self.searchText,
  85. // @"Page":@(self.currentPage),
  86. // @"PerPage":@(20),
  87. @"Sort":@""
  88. };
  89. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Find) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  90. REMOVESHOW
  91. NSLog(@"%@",responseObject);
  92. NoticeListModel *listModel = [[NoticeListModel alloc] initWithDictionary:responseObject error:nil];
  93. weakSelf.totalRecord = listModel.Total;
  94. if (weakSelf.isFresh) {
  95. [weakSelf.listArray removeAllObjects];
  96. }
  97. [weakSelf.listArray addObjectsFromArray:listModel.Items];
  98. dispatch_async(dispatch_get_main_queue(), ^{
  99. if (weakSelf.listArray.count > 0) {
  100. weakSelf.collectionView.hidden = YES;
  101. weakSelf.noDataView.hidden = YES;
  102. weakSelf.tableView.hidden = NO;
  103. [weakSelf.tableView reloadData];
  104. }else{
  105. weakSelf.noDataView.hidden = NO;
  106. weakSelf.collectionView.hidden = YES;
  107. weakSelf.tableView.hidden = YES;
  108. weakSelf.noDataL.text = @"暂无内容";
  109. }
  110. });
  111. } failure:^(NSError * _Nonnull error) {
  112. REMOVESHOW
  113. }];
  114. }
  115. - (NSMutableArray<NoticeModel *> *)listArray{
  116. if (!_listArray) {
  117. _listArray = [NSMutableArray new];
  118. }
  119. return _listArray;
  120. }
  121. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  122. return self.listArray.count;
  123. }
  124. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  125. return 65.f;
  126. }
  127. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  128. NoticeModel *model = [self.listArray objectAtIndex:indexPath.row];
  129. switch (model.AttributeValue) {
  130. case 2:{
  131. ChatNewRowCell *cell = [ChatNewRowCell configCell1:tableView indexPath:indexPath];
  132. cell.cell1TitleLabel.text = model.FolderName;
  133. cell.IsTopImgV.hidden = !model.IsTop;
  134. cell.cell1TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.FileCount];
  135. cell.cell1TimeLabel.hidden = model.FileCount == 0 ? YES : NO;
  136. return cell;
  137. }break;
  138. default:{
  139. ChatNewRowCell *cell = [ChatNewRowCell configCell2:tableView indexPath:indexPath];
  140. [cell.cell2UserImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  141. cell.cell2TitleLabel.text = model.GroupName;
  142. cell.IsTopImgV.hidden = !model.IsTop;
  143. cell.cell2IntroLabel.text = [NSString stringWithFormat:@"共享给%ld人",(long)model.TopicSharingCount];
  144. cell.cell2TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.TopicAllCount];
  145. cell.cell2TimeLabel.hidden = model.TopicAllCount == 0 ? YES : NO;
  146. cell.cell2RedNumLabel.text = model.UReadTopicCount > 0 ? [NSString stringWithFormat:@"[%ld条新话题]",(long)model.UReadTopicCount] : @"";
  147. return cell;
  148. }break;
  149. }
  150. // TDGroupSearchCell *cell = [TDGroupSearchCell configCell:tableView indexPath:indexPath];
  151. // [cell.imagV sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  152. //// cell.nameL.attributedText = [self checkOfString:model.GroupName];
  153. // cell.nameL.attributedText = [ZYCTool checkOfString:model.GroupName withSearchText:self.searchText];
  154. // cell.subL.text = [NSString stringWithFormat:@"共享给%ld人",(long)model.TopicSharingCount];
  155. // if (model.ParentId == 0) {
  156. // [cell.listBtn setTitle:@"根目录" forState:UIControlStateNormal];
  157. // [cell.listBtn setTitleColor:UIColorHex(#999999) forState:UIControlStateNormal];
  158. // }else{
  159. // [cell.listBtn setTitle:model.CategoryName forState:UIControlStateNormal];
  160. // [cell.listBtn setTitleColor:UIColorHex(#1F87DB) forState:UIControlStateNormal];
  161. // }
  162. // WS(weakSelf);
  163. // [cell.listBtn setAction:^{
  164. // MyTDGroupViewController *vc = [[MyTDGroupViewController alloc] init];
  165. // vc.ParentId = model.ParentId;
  166. // vc.isSubVC = YES;
  167. // vc.titleStr = model.ParentId == 0 ? @"小组" : model.CategoryName;
  168. // [weakSelf.navigationController pushViewController:vc animated:YES];
  169. // }];
  170. // return cell;
  171. }
  172. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  173. {
  174. NoticeModel *model = [self.listArray objectAtIndex:indexPath.row];
  175. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  176. if(model && model != nil)
  177. {
  178. switch (model.AttributeValue) {
  179. case 2:{
  180. MyTDGroupViewController *vc = [[MyTDGroupViewController alloc] init];
  181. vc.ParentId = model.Id;
  182. vc.isSubVC = YES;
  183. vc.isSelect = self.isSelect;
  184. vc.titleStr = model.FolderName;
  185. [self.navigationController pushViewController:vc animated:YES];
  186. }break;
  187. default:{
  188. if (self.isReturn) {
  189. MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
  190. vc.Id = model.GroupId;
  191. // vc.type = self.type == 0 ? CollectModel_Group : self.type;
  192. vc.type = CollectModel_Toipc;
  193. vc.isReturn = self.isReturn;
  194. vc.sendModel = self.sendModel;
  195. [self.navigationController pushViewController:vc animated:YES];
  196. }else{
  197. if (self.isSelect) {
  198. [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_SELECTCREATENOTEFOLDER object:nil userInfo:@{@"FolderId":@(model.GroupId),@"FolderName":model.GroupName}];
  199. [self back1];
  200. }else{
  201. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  202. vc.titleStr = model.GroupName;
  203. vc.GroupId = model.GroupId;
  204. vc.type = CollectModel_Toipc;
  205. // vc.sendModel = self.sendModel;
  206. [self.navigationController pushViewController:vc animated:YES];
  207. }
  208. }
  209. }break;
  210. }
  211. }
  212. }
  213. - (void)back1
  214. {
  215. if (self.isSelect) {
  216. for (NSInteger i = (self.navigationController.viewControllers.count - 1); i >= 0; i --) {
  217. UIViewController *vc = self.navigationController.viewControllers[i];
  218. if ([vc isKindOfClass:NSClassFromString(@"MyTDTopicCreateVC")]) {
  219. [self.navigationController popToViewController:vc animated:YES];
  220. return;
  221. }
  222. }
  223. }else{
  224. [self.navigationController popViewControllerAnimated:YES];
  225. }
  226. }
  227. @end