GroupSynopsisUserVC.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // GroupSynopsisUserVC.m
  3. // smartRhino
  4. //
  5. // Created by armin on 2019/11/6.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "GroupSynopsisUserVC.h"
  9. #import "MailListCell.h"
  10. #import "ChineseString.h"
  11. #import "MailListByZuCell.h"
  12. #import "MailListDetailVC.h"
  13. #import "MailListSearchVC.h"
  14. #import "MyTDGroupView.h"
  15. #import "TDGroupInfoModel.h"
  16. #import "GroupSynopsisUserSearchVC.h"
  17. @interface GroupSynopsisUserVC ()<UITableViewDelegate,UITableViewDataSource>
  18. @property (weak, nonatomic) IBOutlet UIView *HeadView;
  19. @property (strong, nonatomic) MyTDGroupView *SearchView;
  20. @property (strong,nonatomic) IBOutlet UITableView *tableView;
  21. //菜单列表数据源
  22. @property (strong,nonatomic) NSMutableArray *pinyinArray;
  23. @property (strong,nonatomic) NSMutableArray *pinyinArray2;
  24. @property (strong,nonatomic) NSMutableArray *nameArray;
  25. @property (strong,nonatomic) NSMutableArray <TDGroupInfoModel *>*nameModelArray;
  26. @property (strong,nonatomic) NSMutableArray *nameArray2;
  27. @property (strong,nonatomic) NSMutableArray *departmentArray;
  28. @property (strong,nonatomic) NSMutableArray *departmentArray2;
  29. @property (strong,nonatomic) NSMutableArray *cusNameArray;
  30. @property (strong,nonatomic) NSMutableArray *departAndUsersPingArray; // 存储名字拼音名字
  31. @property (strong,nonatomic) NSMutableArray *departAndUsersArray; // 存储名字
  32. @property (strong,nonatomic) NSMutableArray *departmentModelArray;
  33. @end
  34. @implementation GroupSynopsisUserVC
  35. #pragma mark - 批量编辑
  36. - (MyTDGroupView *)SearchView
  37. {
  38. if (!_SearchView) {
  39. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  40. }
  41. return _SearchView;
  42. }
  43. - (NSMutableArray<TDGroupInfoModel *> *)nameModelArray{
  44. if (!_nameModelArray) {
  45. _nameModelArray = [NSMutableArray array];
  46. }
  47. return _nameModelArray;
  48. }
  49. #pragma mark - 初始化
  50. +(GroupSynopsisUserVC *)initGroupSynopsisUserVC{
  51. GroupSynopsisUserVC *controller = [StoryboardManager.shared.Source instantiateViewControllerWithIdentifier:@"GroupSynopsisUserVC"];
  52. return controller;
  53. }
  54. - (void)viewDidLoad {
  55. [super viewDidLoad];
  56. [self resetDataSource:self.dataArray];
  57. self.fd_prefersNavigationBarHidden = YES;
  58. self.view.backgroundColor = RGB(255, 255, 255);
  59. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  60. self.tableView.delegate = self;
  61. self.tableView.dataSource = self;
  62. self.tableView.backgroundColor = [UIColor clearColor];
  63. [self.HeadView addSubview:self.SearchView];
  64. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.mas_offset(6);
  66. make.left.right.mas_equalTo(self.HeadView);
  67. make.height.mas_offset(36);
  68. }];
  69. WS(weakSelf);
  70. [self.SearchView.button setAction:^{
  71. GroupSynopsisUserSearchVC * vc = [[GroupSynopsisUserSearchVC alloc] init];
  72. vc.dataArray = weakSelf.dataArray;
  73. [weakSelf.navigationController pushViewController:vc animated:YES];
  74. }];
  75. }
  76. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  77. {
  78. return self.pinyinArray.count;
  79. }
  80. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  81. NSArray *array = [self.cusNameArray objectAtIndex:section];
  82. return [array count];
  83. }
  84. #pragma mark - section右侧index数组
  85. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
  86. return self.pinyinArray;
  87. }
  88. //点击右侧索引表项时调用 索引与section的对应关系
  89. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
  90. return index;
  91. }
  92. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  93. UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
  94. [headerView setBackgroundColor:UIColorHex(0xF5F6F8)];
  95. UILabel *sectionTitle = [[UILabel alloc] init];
  96. [headerView addSubview:sectionTitle];
  97. [sectionTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.left.mas_offset(15);
  99. make.centerY.mas_equalTo(headerView);
  100. }];
  101. sectionTitle.font = [UIFont systemFontOfSize:12];
  102. sectionTitle.textColor = RGB(153, 153, 153);
  103. sectionTitle.textAlignment = NSTextAlignmentLeft;
  104. NSString *returnStr = [self.pinyinArray objectAtIndex:section];
  105. sectionTitle.text = returnStr;
  106. return headerView;
  107. }
  108. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  109. return 30.f;
  110. }
  111. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  112. return [MailListByZuCell configCell0Height];
  113. }
  114. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  115. NSArray * array = self.cusNameArray[indexPath.section];
  116. TDGroupInfoModel * smodel = [array objectAtIndex:indexPath.row];
  117. MailListByZuCell *cell = [MailListByZuCell configCell0:tableView indexPath:indexPath];
  118. cell.cell0TitleLabel.text = smodel.Name;
  119. [cell.cell0ImgView sd_setImageWithURL:[NSURL URLWithString:smodel.AvatarUrl] placeholderImage:[UIImage imageNamed:@"chatmsg_list_testuser_img"]];
  120. return cell;
  121. }
  122. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  123. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  124. NSArray * array = self.cusNameArray[indexPath.section];
  125. TDGroupInfoModel * smodel = [array objectAtIndex:indexPath.row];
  126. MailListDetailVC * userVC = [MailListDetailVC initMailListDetailVC];
  127. userVC.indexId = smodel.UserId;
  128. [self.navigationController pushViewController:userVC animated:YES];
  129. }
  130. - (NSMutableArray *)cusNameArray
  131. {
  132. if (!_cusNameArray) {
  133. _cusNameArray = [NSMutableArray array];
  134. }
  135. return _cusNameArray;
  136. }
  137. -(void)resetDataSource:(NSArray *)sArray
  138. {
  139. WS(weakSelf);
  140. [self.cusNameArray removeAllObjects];
  141. self.pinyinArray = [[NSMutableArray alloc] init];
  142. self.nameArray = [[NSMutableArray alloc] init];
  143. if (sArray.count > 0) {
  144. NSMutableArray *stringsToSort = [[NSMutableArray alloc] init];
  145. for(int i = 0;i < [sArray count];i++){
  146. TDGroupInfoModel * smodel = [sArray objectAtIndex:i];
  147. NSString * str = [NSString stringWithFormat:@"%@UserId%ld",smodel.Name,(long)smodel.UserId];
  148. [stringsToSort addObject:str];
  149. }
  150. self.pinyinArray = [ChineseString IndexArray:stringsToSort];
  151. self.nameArray = [ChineseString LetterSortArray:stringsToSort];
  152. [self.nameArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  153. NSMutableArray * subAddArray = [NSMutableArray array];
  154. for (NSString * string in obj) {
  155. NSInteger flag = 0;
  156. BOOL isAdd = NO;
  157. for (NSInteger i = 0; i < sArray.count; i ++) {
  158. TDGroupInfoModel * smodel = [sArray objectAtIndex:i];
  159. if ([string containsString:[NSString stringWithFormat:@"UserId%ld",smodel.UserId]]) {
  160. [subAddArray addObject:smodel];
  161. isAdd = YES;
  162. flag = i;
  163. }
  164. }
  165. }
  166. if (subAddArray.count > 0) {
  167. [weakSelf.cusNameArray addObject:subAddArray];
  168. }
  169. }];
  170. }
  171. dispatch_async(dispatch_get_main_queue(), ^{
  172. [weakSelf.tableView reloadData];
  173. });
  174. }
  175. @end