// // ChatMsgTopSearchVC.m // smartRhino // // Created by niuzhen on 2020/4/8. // Copyright © 2020 tederen. All rights reserved. // #import "ChatMsgTopSearchVC.h" #import "MailListByZuCell.h" #import "MailListDetailVC.h" @interface ChatMsgTopSearchVC () @property (nonatomic, copy) NSMutableArray *listArray; @end @implementation ChatMsgTopSearchVC - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.view.backgroundColor = RGB(255, 255, 255); self.historySearchType = HistorySearchType_XinYuan; self.tableView.delegate = self; self.tableView.dataSource = self; self.historySearchType = HistorySearchType_XinYuan; [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)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 getData]; } } - (void)getData { NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; [dict setObject:self.searchText forKey:@"Key"]; WEAKSELF [self.listArray removeAllObjects]; [[HttpManager sharedHttpManager] POSTWithUrl:AddressBookGroup_Search_Post parameters:dict success:^(id _Nonnull responseObject) { NSLog(@"搜索结果:%@",responseObject); for (NSDictionary *dic in responseObject) { SelectModel * model = [[SelectModel alloc] initDict:dic]; [weakSelf.listArray addObject:model]; } 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) { SHOWERROR([ZYCTool handerResultData:error]) }]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.listArray.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [MailListByZuCell configCell2Height]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { SelectModel * model = [self.listArray objectAtIndex:indexPath.row]; MailListByZuCell *cell = [MailListByZuCell configCell2:tableView indexPath:indexPath]; cell.cell0TitleLabel.text = model.UserName; cell.cell0DepartMentName.text = model.DepartmentName; [cell.cell0ImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:IMG(@"chatmsg_list_testuser_img")]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { SelectModel *model = [self.listArray objectAtIndex:indexPath.row]; model.SourceName = model.UserName; model.SourceId = model.UserId; [tableView deselectRowAtIndexPath:indexPath animated:YES]; MailListDetailVC *vc = [MailListDetailVC initMailListDetailVC]; vc.indexId = model.UserId; [self.navigationController pushViewController:vc animated:YES]; } - (NSMutableArray *)listArray{ if (!_listArray) { _listArray = [NSMutableArray new]; } return _listArray; } @end