TDGroupSearchResultVC.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. @interface TDGroupSearchResultVC ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic, assign) NSUInteger currentPage;
  14. @property (nonatomic, assign) NSUInteger totalPage;
  15. @property (nonatomic, assign) NSUInteger totalRecord;
  16. @property (nonatomic, assign) BOOL isFresh;
  17. @property (nonatomic, strong) NSMutableArray <NoticeModel*>*listArray;
  18. @end
  19. @implementation TDGroupSearchResultVC
  20. - (void)viewDidLoad {
  21. self.historySearchType = HistorySearchType_Group;
  22. [super viewDidLoad];
  23. self.fd_prefersNavigationBarHidden = YES;
  24. self.view.backgroundColor = RGB(255, 255, 255);
  25. self.currentPage = 1;
  26. self.totalPage = 1;
  27. self.isFresh = YES;
  28. self.tableView.delegate = self;
  29. self.tableView.dataSource = self;
  30. self.historySearchType = HistorySearchType_Group;
  31. [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil];
  32. }
  33. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  34. {
  35. id obj = [change objectForKey:@"new"];
  36. NSString * text = @"";
  37. if ([obj isKindOfClass:[NSString class]]) {
  38. text = obj;
  39. }else{
  40. text = [obj stringValue];
  41. }
  42. if (text.length > 0) {
  43. [self headRefresh];
  44. }
  45. }
  46. #pragma mark - UItableView刷新
  47. - (void)setTableViewRefresh{
  48. WeakSelf(self)
  49. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  50. [weakself headRefresh];
  51. }];
  52. self.tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
  53. [weakself footerRefresh];
  54. }];
  55. [self.tableView.mj_header beginRefreshing];
  56. }
  57. - (void)headRefresh{
  58. self.isFresh = YES;
  59. [self getData];
  60. self.currentPage = 1;
  61. [self.tableView.mj_header endRefreshing];
  62. }
  63. - (void)footerRefresh{
  64. self.isFresh = NO;
  65. self.currentPage += 1;
  66. [self.listArray removeAllObjects];
  67. if (self.totalRecord == self.listArray.count) {
  68. self.currentPage --;
  69. [self.tableView.mj_footer endRefreshing];
  70. return ;
  71. }
  72. [self.tableView.mj_footer endRefreshing];
  73. }
  74. - (void)getData
  75. {
  76. if (self.searchText.length == 0) {
  77. return;
  78. }
  79. SHOWLOADING
  80. WS(weakSelf);
  81. NSDictionary * paraDict = @{@"GroupFolderId":@(self.ParentId),
  82. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  83. @"Key":self.searchText,
  84. @"Page":@(self.currentPage),
  85. @"PerPage":@(20),
  86. @"Sort":@""
  87. };
  88. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Find) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  89. REMOVESHOW
  90. NSLog(@"%@",responseObject);
  91. NoticeListModel *listModel = [[NoticeListModel alloc] initWithDictionary:responseObject error:nil];
  92. weakSelf.totalRecord = listModel.Total;
  93. if (weakSelf.isFresh) {
  94. [weakSelf.listArray removeAllObjects];
  95. }
  96. [weakSelf.listArray addObjectsFromArray:listModel.Items];
  97. dispatch_async(dispatch_get_main_queue(), ^{
  98. if (weakSelf.listArray.count > 0) {
  99. weakSelf.collectionView.hidden = YES;
  100. weakSelf.noDataView.hidden = YES;
  101. weakSelf.tableView.hidden = NO;
  102. [weakSelf.tableView reloadData];
  103. }else{
  104. weakSelf.noDataView.hidden = NO;
  105. weakSelf.collectionView.hidden = YES;
  106. weakSelf.tableView.hidden = YES;
  107. weakSelf.noDataL.text = @"暂无内容";
  108. }
  109. });
  110. } failure:^(NSError * _Nonnull error) {
  111. REMOVESHOW
  112. }];
  113. }
  114. - (NSMutableArray<NoticeModel *> *)listArray{
  115. if (!_listArray) {
  116. _listArray = [NSMutableArray new];
  117. }
  118. return _listArray;
  119. }
  120. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  121. return self.listArray.count;
  122. }
  123. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  124. return 65.f;
  125. }
  126. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  127. NoticeModel *model = [self.listArray objectAtIndex:indexPath.row];
  128. TDGroupSearchCell *cell = [TDGroupSearchCell configCell:tableView indexPath:indexPath];
  129. [cell.imagV sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  130. // cell.nameL.attributedText = [self checkOfString:model.GroupName];
  131. cell.nameL.attributedText = [ZYCTool checkOfString:model.GroupName withSearchText:self.searchText];
  132. cell.subL.text = [NSString stringWithFormat:@"共享给%ld人",(long)model.TopicSharingCount];
  133. if (model.ParentId == 0) {
  134. [cell.listBtn setTitle:@"根目录" forState:UIControlStateNormal];
  135. [cell.listBtn setTitleColor:UIColorHex(#999999) forState:UIControlStateNormal];
  136. }else{
  137. [cell.listBtn setTitle:model.CategoryName forState:UIControlStateNormal];
  138. [cell.listBtn setTitleColor:UIColorHex(#1F87DB) forState:UIControlStateNormal];
  139. }
  140. WS(weakSelf);
  141. [cell.listBtn setAction:^{
  142. MyTDGroupViewController *vc = [[MyTDGroupViewController alloc] init];
  143. vc.ParentId = model.ParentId;
  144. vc.isSubVC = YES;
  145. vc.titleStr = model.ParentId == 0 ? @"小组" : model.CategoryName;
  146. [weakSelf.navigationController pushViewController:vc animated:YES];
  147. }];
  148. return cell;
  149. }
  150. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  151. {
  152. NoticeModel *model = [self.listArray objectAtIndex:indexPath.row];
  153. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  154. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  155. vc.GroupId = model.GroupId;
  156. vc.titleStr = model.GroupName;
  157. [self.navigationController pushViewController:vc animated:YES];
  158. }
  159. @end