ReadSearchVC.m 3.2 KB

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