// // GroupSynopsisUserVC.m // smartRhino // // Created by armin on 2019/11/6. // Copyright © 2019 tederen. All rights reserved. // #import "GroupSynopsisUserVC.h" #import "MailListCell.h" #import "ChineseString.h" #import "MailListByZuCell.h" #import "MailListDetailVC.h" #import "MailListSearchVC.h" #import "MyTDGroupView.h" #import "TDGroupInfoModel.h" #import "GroupSynopsisUserSearchVC.h" @interface GroupSynopsisUserVC () @property (weak, nonatomic) IBOutlet UIView *HeadView; @property (strong, nonatomic) MyTDGroupView *SearchView; @property (strong,nonatomic) IBOutlet UITableView *tableView; //菜单列表数据源 @property (strong,nonatomic) NSMutableArray *pinyinArray; @property (strong,nonatomic) NSMutableArray *pinyinArray2; @property (strong,nonatomic) NSMutableArray *nameArray; @property (strong,nonatomic) NSMutableArray *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 GroupSynopsisUserVC #pragma mark - 批量编辑 - (MyTDGroupView *)SearchView { if (!_SearchView) { _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)]; } return _SearchView; } - (NSMutableArray *)nameModelArray{ if (!_nameModelArray) { _nameModelArray = [NSMutableArray array]; } return _nameModelArray; } #pragma mark - 初始化 +(GroupSynopsisUserVC *)initGroupSynopsisUserVC{ GroupSynopsisUserVC *controller = [StoryboardManager.shared.Source instantiateViewControllerWithIdentifier:@"GroupSynopsisUserVC"]; return controller; } - (void)viewDidLoad { [super viewDidLoad]; [self resetDataSource:self.dataArray]; self.fd_prefersNavigationBarHidden = YES; self.view.backgroundColor = RGB(255, 255, 255); self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.backgroundColor = [UIColor clearColor]; [self.HeadView addSubview:self.SearchView]; [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_offset(6); make.left.right.mas_equalTo(self.HeadView); make.height.mas_offset(36); }]; WS(weakSelf); [self.SearchView.button setAction:^{ GroupSynopsisUserSearchVC * vc = [[GroupSynopsisUserSearchVC alloc] init]; vc.dataArray = weakSelf.dataArray; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; } - (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:(NSArray *)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