123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- //
- // GroupSynopsisUserSearchVC.m
- // smartRhino
- //
- // Created by niuzhen on 2020/1/17.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "GroupSynopsisUserSearchVC.h"
- #import "MailListCell.h"
- #import "ChineseString.h"
- #import "MailListByZuCell.h"
- #import "MailListDetailVC.h"
- #import "MailListSearchVC.h"
- #import "MyTDGroupView.h"
- #import "TDGroupInfoModel.h"
- @interface GroupSynopsisUserSearchVC ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) NSMutableArray *listArray;
- @property (strong,nonatomic) NSMutableArray *pinyinArray;
- @property (strong,nonatomic) NSMutableArray *pinyinArray2;
- @property (strong,nonatomic) NSMutableArray *nameArray;
- @property (strong,nonatomic) NSMutableArray <TDGroupInfoModel *>*nameModelArray;
- @property (strong,nonatomic) NSMutableArray *nameArray2;
- @property (strong,nonatomic) NSMutableArray *departmentArray;
- @property (strong,nonatomic) NSMutableArray *departmentArray2;
- @property (strong,nonatomic) NSMutableArray *cusNameArray;
- @property (strong,nonatomic) NSMutableArray *departAndUsersPingArray; // 存储名字拼音名字
- @property (strong,nonatomic) NSMutableArray *departAndUsersArray; // 存储名字
- @property (strong,nonatomic) NSMutableArray *departmentModelArray;
- @end
- @implementation GroupSynopsisUserSearchVC
- - (NSMutableArray *)listArray
- {
- if (!_listArray) {
- _listArray = [NSMutableArray array];
- }
- return _listArray;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.fd_prefersNavigationBarHidden = YES;
- self.view.backgroundColor = RGB(255, 255, 255);
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- switch (self.type) {
- case 1:
- {
- self.historySearchType = HistorySearchType_GroupInfoUser;
- }
- break;
- default:
- {
- self.historySearchType = HistorySearchType_SynopsisUser;
- }
- break;
- }
- [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil];
- }
- - (void)dealloc
- {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)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:text];
- }
- }
- - (void)getData:(NSString *)searchKey
- {
- [self.listArray removeAllObjects];
- for (TDGroupInfoModel * model in self.dataArray) {
- if ([model.Name containsString:searchKey]) {
- [self.listArray addObject:model];
- }
- }
- [self resetDataSource:self.listArray];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return self.pinyinArray.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- NSArray *array = [self.cusNameArray objectAtIndex:section];
- return [array count];
- }
- #pragma mark - section右侧index数组
- -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
- return self.pinyinArray;
- }
- //点击右侧索引表项时调用 索引与section的对应关系
- - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
- return index;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
- [headerView setBackgroundColor:UIColorHex(0xF5F6F8)];
- UILabel *sectionTitle = [[UILabel alloc] init];
- [headerView addSubview:sectionTitle];
- [sectionTitle mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_offset(15);
- make.centerY.mas_equalTo(headerView);
- }];
- sectionTitle.font = [UIFont systemFontOfSize:12];
- sectionTitle.textColor = RGB(153, 153, 153);
- sectionTitle.textAlignment = NSTextAlignmentLeft;
- NSString *returnStr = [self.pinyinArray objectAtIndex:section];
- sectionTitle.text = returnStr;
- return headerView;
- }
-
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return 30.f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return [MailListByZuCell configCell0Height];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- NSArray * array = self.cusNameArray[indexPath.section];
- TDGroupInfoModel * smodel = [array objectAtIndex:indexPath.row];
- MailListByZuCell *cell = [MailListByZuCell configCell0:tableView indexPath:indexPath];
- cell.cell0TitleLabel.text = smodel.Name;
- [cell.cell0ImgView sd_setImageWithURL:[NSURL URLWithString:smodel.AvatarUrl] placeholderImage:[UIImage imageNamed:@"chatmsg_list_testuser_img"]];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- NSArray * array = self.cusNameArray[indexPath.section];
- TDGroupInfoModel * smodel = [array objectAtIndex:indexPath.row];
- MailListDetailVC * userVC = [MailListDetailVC initMailListDetailVC];
- userVC.indexId = smodel.UserId;
- [self.navigationController pushViewController:userVC animated:YES];
- }
- - (NSMutableArray *)cusNameArray
- {
- if (!_cusNameArray) {
- _cusNameArray = [NSMutableArray array];
- }
- return _cusNameArray;
- }
- -(void)resetDataSource:(NSMutableArray *)sArray
- {
- WS(weakSelf);
- [self.cusNameArray removeAllObjects];
- self.pinyinArray = [[NSMutableArray alloc] init];
- self.nameArray = [[NSMutableArray alloc] init];
- if (sArray.count > 0) {
- NSMutableArray *stringsToSort = [[NSMutableArray alloc] init];
- for(int i = 0;i < [sArray count];i++){
- TDGroupInfoModel * smodel = [sArray objectAtIndex:i];
- NSString * str = [NSString stringWithFormat:@"%@UserId%ld",smodel.Name,(long)smodel.UserId];
- [stringsToSort addObject:str];
- }
- self.pinyinArray = [ChineseString IndexArray:stringsToSort];
- self.nameArray = [ChineseString LetterSortArray:stringsToSort];
- [self.nameArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- NSMutableArray * subAddArray = [NSMutableArray array];
- for (NSString * string in obj) {
- NSInteger flag = 0;
- BOOL isAdd = NO;
- for (NSInteger i = 0; i < sArray.count; i ++) {
- TDGroupInfoModel * smodel = [sArray objectAtIndex:i];
- if ([string containsString:[NSString stringWithFormat:@"UserId%ld",smodel.UserId]]) {
- [subAddArray addObject:smodel];
- isAdd = YES;
- flag = i;
- }
- }
- }
- if (subAddArray.count > 0) {
- [weakSelf.cusNameArray addObject:subAddArray];
- }
- }];
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- });
- }
- @end
|