JXSelecAttionPerson.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. //
  2. // JXSelectFriendsVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2018/7/2.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXSelecAttionPerson.h"
  9. #import "JXLabel.h"
  10. #import "JXImageView.h"
  11. #import "JXCell.h"
  12. #import "JXRoomPool.h"
  13. #import "JXTableView.h"
  14. #import "menuImageView.h"
  15. #import "QCheckBox.h"
  16. #import "JXRoomObject.h"
  17. #import "NSString+ContainStr.h"
  18. #import "JXMessageObject.h"
  19. #import "BMChineseSort.h"
  20. #import "JXChatChineseString.h"
  21. #define HEIGHT 55
  22. @interface JXSelecAttionPerson ()<UITextFieldDelegate, UIAlertViewDelegate,JXRoomObjectDelegate>
  23. @property (nonatomic, strong) UIButton* finishBtn;
  24. @property (nonatomic, strong) NSMutableArray *checkBoxArr;
  25. @property (nonatomic, strong) UIView *backView;
  26. @end
  27. @implementation JXSelecAttionPerson
  28. - (void)viewDidLoad
  29. {
  30. [super viewDidLoad];
  31. _userIds = [NSMutableArray array];
  32. _userNames = [NSMutableArray array];
  33. _set = [[NSMutableSet alloc] init];
  34. _indexArray = [NSMutableArray array];
  35. _letterResultArr = [NSMutableArray array];
  36. _checkBoxArr = [NSMutableArray array];
  37. _selMenu = 0;
  38. _array=[NSMutableArray array];
  39. _finishBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  40. [_finishBtn setTitle:Localized(@"JX_Confirm") forState:UIControlStateNormal];
  41. [_finishBtn setTitle:Localized(@"JX_Confirm") forState:UIControlStateHighlighted];
  42. [_finishBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  43. _finishBtn.layer.masksToBounds = YES;
  44. _finishBtn.layer.cornerRadius = 3.f;
  45. [_finishBtn setBackgroundColor:THEMECOLOR];
  46. [_finishBtn.titleLabel setFont:SYSFONT(15)];
  47. _finishBtn.frame = CGRectMake(JX_SCREEN_WIDTH - 51 - 15, JX_SCREEN_TOP - 8 - 29, 51, 29);
  48. [_finishBtn addTarget:self action:@selector(onAdd) forControlEvents:UIControlEventTouchUpInside];
  49. [self getDataArrayByType];
  50. }
  51. -(void)getDataArrayByType{
  52. _letterResultArr = [JXChatChineseString LetterSortArray:_addressBookArr];
  53. [_letterResultArr enumerateObjectsUsingBlock:^(NSArray * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  54. [obj enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull dict, NSUInteger idx, BOOL * _Nonnull stop) {
  55. [_indexArray addObject:dict[@"title"]];
  56. }];
  57. }];
  58. _indexArray = [JXChatChineseString IndexArray:_indexArray];
  59. }
  60. -(JXImageView*)createButton:(NSString*)title drawTop:(BOOL)drawTop drawBottom:(BOOL)drawBottom icon:(NSString*)icon click:(SEL)click{
  61. JXImageView* btn = [[JXImageView alloc] init];
  62. btn.backgroundColor = [UIColor whiteColor];
  63. btn.userInteractionEnabled = YES;
  64. btn.didTouch = click;
  65. btn.delegate = self;
  66. [self.backView addSubview:btn];
  67. JXLabel* p = [[JXLabel alloc] initWithFrame:CGRectMake(15, 0, JX_SCREEN_WIDTH-100, HEIGHT)];
  68. p.text = title;
  69. p.font = g_factory.font16;
  70. p.backgroundColor = [UIColor clearColor];
  71. p.textColor = [UIColor blackColor];
  72. p.delegate = self;
  73. p.didTouch = click;
  74. [btn addSubview:p];
  75. if(icon){
  76. UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(10, (HEIGHT-20)/2, 20, 20)];
  77. iv.image = [UIImage imageNamed:icon];
  78. [btn addSubview:iv];
  79. }
  80. if(drawTop){
  81. UIView* line = [[UIView alloc] initWithFrame:CGRectMake(15,0,JX_SCREEN_WIDTH-15,LINE_WH)];
  82. line.backgroundColor = THE_LINE_COLOR;
  83. [btn addSubview:line];
  84. }
  85. if(drawBottom){
  86. UIView* line = [[UIView alloc] initWithFrame:CGRectMake(15,HEIGHT-LINE_WH,JX_SCREEN_WIDTH-15,LINE_WH)];
  87. line.backgroundColor = THE_LINE_COLOR;
  88. [btn addSubview:line];
  89. }
  90. if(click){
  91. UIImageView* iv;
  92. iv = [[UIImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-15-7, (HEIGHT-13)/2, 7, 13)];
  93. iv.image = [UIImage imageNamed:@"new_icon_>"];
  94. [btn addSubview:iv];
  95. }
  96. return btn;
  97. }
  98. - (void) cancelBtnAction {
  99. [self getDataArrayByType];
  100. }
  101. #pragma mark ---------tableView协议----------------
  102. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  103. {
  104. return [self.indexArray count];
  105. }
  106. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  107. return [self.indexArray objectAtIndex:section];
  108. }
  109. -(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
  110. UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
  111. header.tintColor = HEXCOLOR(0xF2F2F2);
  112. [header.textLabel setTextColor:HEXCOLOR(0x999999)];
  113. [header.textLabel setFont:SYSFONT(15)];
  114. }
  115. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  116. {
  117. return [(NSArray *)[self.letterResultArr objectAtIndex:section] count];
  118. }
  119. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
  120. return self.indexArray;
  121. }
  122. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
  123. return index;
  124. }
  125. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  126. {
  127. JXCell *cell=nil;
  128. if (!cell) {
  129. cell = [[JXCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellNames"];
  130. }
  131. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  132. NSDictionary *dict= [[self.letterResultArr objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
  133. memberData *member=dict[@"model"];
  134. [_table addToPool:cell];
  135. cell.title = member.userNickName;
  136. cell.isSmall = YES;
  137. [cell headImageViewImageWithUserId:nil roomId:nil];
  138. QCheckBox* btn = [[QCheckBox alloc] initWithDelegate:self];
  139. btn.frame = CGRectMake(JX_SCREEN_WIDTH-45, 18.5, 22, 22);
  140. btn.tag = (indexPath.section+1) * 100000 + (indexPath.row+1);
  141. BOOL b = NO;
  142. NSString* s = [NSString stringWithFormat:@"%ld",member.userId];
  143. b = [_existSet containsObject:s];
  144. btn.selected = b;
  145. btn.userInteractionEnabled = !b;
  146. [cell addSubview:btn];
  147. [_checkBoxArr addObject:btn];
  148. return cell;
  149. }
  150. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  151. {
  152. NSDictionary *dict= [[self.letterResultArr objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
  153. memberData *user=dict[@"model"];
  154. if (![_existSet containsObject:[NSString stringWithFormat:@"%ld",user.userId]]) {
  155. QCheckBox *checkBox = nil;
  156. JXCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  157. checkBox = [cell viewWithTag:(indexPath.section+1) * 100000 + (indexPath.row+1)];
  158. checkBox.selected = !checkBox.selected;
  159. [self didSelectedCheckBox:checkBox checked:checkBox.selected];
  160. }
  161. }
  162. -(void)reomveExistsSet{
  163. for(NSInteger i=[_array count]-1;i>=0;i--){
  164. memberData* p = [_array objectAtIndex:i];
  165. if([self.existSet containsObject:[NSString stringWithFormat:@"%ld",p.userId]]>0)
  166. [_array removeObjectAtIndex:i];
  167. }
  168. }
  169. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  170. {
  171. return 59;
  172. }
  173. - (void)didSelectedCheckBox:(QCheckBox *)checkbox checked:(BOOL)checked{
  174. if (!checkbox.enabled) {
  175. return;
  176. }
  177. if ( checked && self.maxSize > 0 && _userIds.count == self.maxSize) {
  178. checkbox.selected = NO;
  179. [JXMyTools showTipView:@"群成员已达上限"];
  180. return;
  181. }
  182. NSDictionary *dict = [[self.letterResultArr objectAtIndex:checkbox.tag / 100000-1] objectAtIndex:checkbox.tag % 100000-1];
  183. memberData *user=dict[@"model"];
  184. NSString *userId;
  185. NSString *userNickname;
  186. memberData *member = (memberData *)user;
  187. userId = [NSString stringWithFormat:@"%ld",member.userId];
  188. userNickname = [NSString stringWithFormat:@"%@",member.userNickName];
  189. if(checked){ // 选定
  190. if (![_userIds containsObject:userId]) { // 所有id包含选择id
  191. [_userIds addObject:userId];
  192. [_userNames addObject:userNickname];
  193. }
  194. if (![_set containsObject:[NSNumber numberWithInteger:checkbox.tag]]) {
  195. [_set addObject:[NSNumber numberWithInteger:checkbox.tag]];
  196. }
  197. }
  198. else{ // 取消选定
  199. if ([_userIds containsObject:userId]) {
  200. NSInteger index = [_userIds indexOfObject:userId];
  201. [_userIds removeObject:userId];
  202. [_userNames removeObjectAtIndex:index];
  203. [_set removeObject:[NSNumber numberWithInteger:checkbox.tag]];
  204. }
  205. }
  206. }
  207. -(void)onAdd {
  208. if (!self.addressBookArr || self.addressBookArr.count <= 0) {
  209. if (self.isForRoom) {
  210. if (![_userIds containsObject:self.forRoomUser.userId]) {
  211. [_userIds addObject:self.forRoomUser.userId];
  212. [_userNames addObject:self.forRoomUser.userNickname];
  213. }
  214. }
  215. }
  216. [self actionQuit];
  217. }
  218. @end