GroupSynopsisUserSearchVC.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // GroupSynopsisUserSearchVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/1/17.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "GroupSynopsisUserSearchVC.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. @interface GroupSynopsisUserSearchVC ()<UITableViewDelegate,UITableViewDataSource>
  17. @property (nonatomic, strong) NSMutableArray *listArray;
  18. @property (strong,nonatomic) NSMutableArray *pinyinArray;
  19. @property (strong,nonatomic) NSMutableArray *pinyinArray2;
  20. @property (strong,nonatomic) NSMutableArray *nameArray;
  21. @property (strong,nonatomic) NSMutableArray <TDGroupInfoModel *>*nameModelArray;
  22. @property (strong,nonatomic) NSMutableArray *nameArray2;
  23. @property (strong,nonatomic) NSMutableArray *departmentArray;
  24. @property (strong,nonatomic) NSMutableArray *departmentArray2;
  25. @property (strong,nonatomic) NSMutableArray *cusNameArray;
  26. @property (strong,nonatomic) NSMutableArray *departAndUsersPingArray; // 存储名字拼音名字
  27. @property (strong,nonatomic) NSMutableArray *departAndUsersArray; // 存储名字
  28. @property (strong,nonatomic) NSMutableArray *departmentModelArray;
  29. @end
  30. @implementation GroupSynopsisUserSearchVC
  31. - (NSMutableArray *)listArray
  32. {
  33. if (!_listArray) {
  34. _listArray = [NSMutableArray array];
  35. }
  36. return _listArray;
  37. }
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. self.fd_prefersNavigationBarHidden = YES;
  41. self.view.backgroundColor = RGB(255, 255, 255);
  42. self.tableView.delegate = self;
  43. self.tableView.dataSource = self;
  44. switch (self.type) {
  45. case 1:
  46. {
  47. self.historySearchType = HistorySearchType_GroupInfoUser;
  48. }
  49. break;
  50. default:
  51. {
  52. self.historySearchType = HistorySearchType_SynopsisUser;
  53. }
  54. break;
  55. }
  56. [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil];
  57. }
  58. - (void)dealloc
  59. {
  60. [[NSNotificationCenter defaultCenter] removeObserver:self];
  61. }
  62. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  63. {
  64. id obj = [change objectForKey:@"new"];
  65. NSString * text = @"";
  66. if ([obj isKindOfClass:[NSString class]]) {
  67. text = obj;
  68. }else{
  69. text = [obj stringValue];
  70. }
  71. if (text.length > 0) {
  72. [self getData:text];
  73. }
  74. }
  75. - (void)getData:(NSString *)searchKey
  76. {
  77. [self.listArray removeAllObjects];
  78. for (TDGroupInfoModel * model in self.dataArray) {
  79. if ([model.Name containsString:searchKey]) {
  80. [self.listArray addObject:model];
  81. }
  82. }
  83. [self resetDataSource:self.listArray];
  84. }
  85. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  86. {
  87. return self.pinyinArray.count;
  88. }
  89. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  90. NSArray *array = [self.cusNameArray objectAtIndex:section];
  91. return [array count];
  92. }
  93. #pragma mark - section右侧index数组
  94. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
  95. return self.pinyinArray;
  96. }
  97. //点击右侧索引表项时调用 索引与section的对应关系
  98. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
  99. return index;
  100. }
  101. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  102. UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
  103. [headerView setBackgroundColor:UIColorHex(0xF5F6F8)];
  104. UILabel *sectionTitle = [[UILabel alloc] init];
  105. [headerView addSubview:sectionTitle];
  106. [sectionTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.left.mas_offset(15);
  108. make.centerY.mas_equalTo(headerView);
  109. }];
  110. sectionTitle.font = [UIFont systemFontOfSize:12];
  111. sectionTitle.textColor = RGB(153, 153, 153);
  112. sectionTitle.textAlignment = NSTextAlignmentLeft;
  113. NSString *returnStr = [self.pinyinArray objectAtIndex:section];
  114. sectionTitle.text = returnStr;
  115. return headerView;
  116. }
  117. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  118. return 30.f;
  119. }
  120. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  121. return [MailListByZuCell configCell0Height];
  122. }
  123. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  124. NSArray * array = self.cusNameArray[indexPath.section];
  125. TDGroupInfoModel * smodel = [array objectAtIndex:indexPath.row];
  126. MailListByZuCell *cell = [MailListByZuCell configCell0:tableView indexPath:indexPath];
  127. cell.cell0TitleLabel.text = smodel.Name;
  128. [cell.cell0ImgView sd_setImageWithURL:[NSURL URLWithString:smodel.AvatarUrl] placeholderImage:[UIImage imageNamed:@"chatmsg_list_testuser_img"]];
  129. return cell;
  130. }
  131. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  132. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  133. NSArray * array = self.cusNameArray[indexPath.section];
  134. TDGroupInfoModel * smodel = [array objectAtIndex:indexPath.row];
  135. MailListDetailVC * userVC = [MailListDetailVC initMailListDetailVC];
  136. userVC.indexId = smodel.UserId;
  137. [self.navigationController pushViewController:userVC animated:YES];
  138. }
  139. - (NSMutableArray *)cusNameArray
  140. {
  141. if (!_cusNameArray) {
  142. _cusNameArray = [NSMutableArray array];
  143. }
  144. return _cusNameArray;
  145. }
  146. -(void)resetDataSource:(NSMutableArray *)sArray
  147. {
  148. WS(weakSelf);
  149. [self.cusNameArray removeAllObjects];
  150. self.pinyinArray = [[NSMutableArray alloc] init];
  151. self.nameArray = [[NSMutableArray alloc] init];
  152. if (sArray.count > 0) {
  153. NSMutableArray *stringsToSort = [[NSMutableArray alloc] init];
  154. for(int i = 0;i < [sArray count];i++){
  155. TDGroupInfoModel * smodel = [sArray objectAtIndex:i];
  156. NSString * str = [NSString stringWithFormat:@"%@UserId%ld",smodel.Name,(long)smodel.UserId];
  157. [stringsToSort addObject:str];
  158. }
  159. self.pinyinArray = [ChineseString IndexArray:stringsToSort];
  160. self.nameArray = [ChineseString LetterSortArray:stringsToSort];
  161. [self.nameArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  162. NSMutableArray * subAddArray = [NSMutableArray array];
  163. for (NSString * string in obj) {
  164. NSInteger flag = 0;
  165. BOOL isAdd = NO;
  166. for (NSInteger i = 0; i < sArray.count; i ++) {
  167. TDGroupInfoModel * smodel = [sArray objectAtIndex:i];
  168. if ([string containsString:[NSString stringWithFormat:@"UserId%ld",smodel.UserId]]) {
  169. [subAddArray addObject:smodel];
  170. isAdd = YES;
  171. flag = i;
  172. }
  173. }
  174. }
  175. if (subAddArray.count > 0) {
  176. [weakSelf.cusNameArray addObject:subAddArray];
  177. }
  178. }];
  179. }
  180. dispatch_async(dispatch_get_main_queue(), ^{
  181. [weakSelf.tableView reloadData];
  182. });
  183. }
  184. @end