ChatMsgTopSearchVC.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // ChatMsgTopSearchVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/4/8.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "ChatMsgTopSearchVC.h"
  9. #import "MailListByZuCell.h"
  10. #import "MailListDetailVC.h"
  11. @interface ChatMsgTopSearchVC ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic, copy) NSMutableArray *listArray;
  13. @end
  14. @implementation ChatMsgTopSearchVC
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. self.fd_prefersNavigationBarHidden = YES;
  18. self.view.backgroundColor = RGB(255, 255, 255);
  19. self.historySearchType = HistorySearchType_XinYuan;
  20. self.tableView.delegate = self;
  21. self.tableView.dataSource = self;
  22. self.historySearchType = HistorySearchType_XinYuan;
  23. [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil];
  24. }
  25. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  26. {
  27. id obj = [change objectForKey:@"new"];
  28. NSString * text = @"";
  29. if ([obj isKindOfClass:[NSString class]]) {
  30. text = obj;
  31. }else{
  32. text = [obj stringValue];
  33. }
  34. if (text.length > 0) {
  35. [self getData];
  36. }
  37. }
  38. - (void)getData
  39. {
  40. NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
  41. [dict setObject:self.searchText forKey:@"Key"];
  42. WEAKSELF
  43. [self.listArray removeAllObjects];
  44. [[HttpManager sharedHttpManager] POSTWithUrl:AddressBookGroup_Search_Post parameters:dict success:^(id _Nonnull responseObject) {
  45. NSLog(@"搜索结果:%@",responseObject);
  46. for (NSDictionary *dic in responseObject) {
  47. SelectModel * model = [[SelectModel alloc] initDict:dic];
  48. [weakSelf.listArray addObject:model];
  49. }
  50. dispatch_async(dispatch_get_main_queue(), ^{
  51. if (weakSelf.listArray.count > 0) {
  52. weakSelf.collectionView.hidden = YES;
  53. weakSelf.noDataView.hidden = YES;
  54. weakSelf.tableView.hidden = NO;
  55. [weakSelf.tableView reloadData];
  56. }else{
  57. weakSelf.noDataView.hidden = NO;
  58. weakSelf.collectionView.hidden = YES;
  59. weakSelf.tableView.hidden = YES;
  60. weakSelf.noDataL.text = @"暂无用户";
  61. }
  62. });
  63. } failure:^(NSError * _Nonnull error) {
  64. SHOWERROR([ZYCTool handerResultData:error])
  65. }];
  66. }
  67. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  68. {
  69. return self.listArray.count;
  70. }
  71. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  72. {
  73. return [MailListByZuCell configCell2Height];
  74. }
  75. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  76. {
  77. SelectModel * model = [self.listArray objectAtIndex:indexPath.row];
  78. MailListByZuCell *cell = [MailListByZuCell configCell2:tableView indexPath:indexPath];
  79. cell.cell0TitleLabel.text = model.UserName;
  80. cell.cell0DepartMentName.text = model.DepartmentName;
  81. [cell.cell0ImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:IMG(@"chatmsg_list_testuser_img")];
  82. return cell;
  83. }
  84. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  85. {
  86. SelectModel *model = [self.listArray objectAtIndex:indexPath.row];
  87. model.SourceName = model.UserName;
  88. model.SourceId = model.UserId;
  89. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  90. MailListDetailVC *vc = [MailListDetailVC initMailListDetailVC];
  91. vc.indexId = model.UserId;
  92. [self.navigationController pushViewController:vc animated:YES];
  93. }
  94. - (NSMutableArray *)listArray{
  95. if (!_listArray) {
  96. _listArray = [NSMutableArray new];
  97. }
  98. return _listArray;
  99. }
  100. @end