// // JXSelectFriendsVC.m // shiku_im // // Created by p on 2018/7/2. // Copyright © 2018年 Reese. All rights reserved. // #import "JXSelecAttionPerson.h" #import "JXLabel.h" #import "JXImageView.h" #import "JXCell.h" #import "JXRoomPool.h" #import "JXTableView.h" #import "menuImageView.h" #import "QCheckBox.h" #import "JXRoomObject.h" #import "NSString+ContainStr.h" #import "JXMessageObject.h" #import "BMChineseSort.h" #import "JXChatChineseString.h" #define HEIGHT 55 @interface JXSelecAttionPerson () @property (nonatomic, strong) UIButton* finishBtn; @property (nonatomic, strong) NSMutableArray *checkBoxArr; @property (nonatomic, strong) UIView *backView; @end @implementation JXSelecAttionPerson - (void)viewDidLoad { [super viewDidLoad]; _userIds = [NSMutableArray array]; _userNames = [NSMutableArray array]; _set = [[NSMutableSet alloc] init]; _indexArray = [NSMutableArray array]; _letterResultArr = [NSMutableArray array]; _checkBoxArr = [NSMutableArray array]; _selMenu = 0; _array=[NSMutableArray array]; _finishBtn = [UIButton buttonWithType:UIButtonTypeSystem]; [_finishBtn setTitle:Localized(@"JX_Confirm") forState:UIControlStateNormal]; [_finishBtn setTitle:Localized(@"JX_Confirm") forState:UIControlStateHighlighted]; [_finishBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; _finishBtn.layer.masksToBounds = YES; _finishBtn.layer.cornerRadius = 3.f; [_finishBtn setBackgroundColor:THEMECOLOR]; [_finishBtn.titleLabel setFont:SYSFONT(15)]; _finishBtn.frame = CGRectMake(JX_SCREEN_WIDTH - 51 - 15, JX_SCREEN_TOP - 8 - 29, 51, 29); [_finishBtn addTarget:self action:@selector(onAdd) forControlEvents:UIControlEventTouchUpInside]; [self getDataArrayByType]; } -(void)getDataArrayByType{ _letterResultArr = [JXChatChineseString LetterSortArray:_addressBookArr]; [_letterResultArr enumerateObjectsUsingBlock:^(NSArray * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [obj enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull dict, NSUInteger idx, BOOL * _Nonnull stop) { [_indexArray addObject:dict[@"title"]]; }]; }]; _indexArray = [JXChatChineseString IndexArray:_indexArray]; } -(JXImageView*)createButton:(NSString*)title drawTop:(BOOL)drawTop drawBottom:(BOOL)drawBottom icon:(NSString*)icon click:(SEL)click{ JXImageView* btn = [[JXImageView alloc] init]; btn.backgroundColor = [UIColor whiteColor]; btn.userInteractionEnabled = YES; btn.didTouch = click; btn.delegate = self; [self.backView addSubview:btn]; JXLabel* p = [[JXLabel alloc] initWithFrame:CGRectMake(15, 0, JX_SCREEN_WIDTH-100, HEIGHT)]; p.text = title; p.font = g_factory.font16; p.backgroundColor = [UIColor clearColor]; p.textColor = [UIColor blackColor]; p.delegate = self; p.didTouch = click; [btn addSubview:p]; if(icon){ UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(10, (HEIGHT-20)/2, 20, 20)]; iv.image = [UIImage imageNamed:icon]; [btn addSubview:iv]; } if(drawTop){ UIView* line = [[UIView alloc] initWithFrame:CGRectMake(15,0,JX_SCREEN_WIDTH-15,LINE_WH)]; line.backgroundColor = THE_LINE_COLOR; [btn addSubview:line]; } if(drawBottom){ UIView* line = [[UIView alloc] initWithFrame:CGRectMake(15,HEIGHT-LINE_WH,JX_SCREEN_WIDTH-15,LINE_WH)]; line.backgroundColor = THE_LINE_COLOR; [btn addSubview:line]; } if(click){ UIImageView* iv; iv = [[UIImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-15-7, (HEIGHT-13)/2, 7, 13)]; iv.image = [UIImage imageNamed:@"new_icon_>"]; [btn addSubview:iv]; } return btn; } - (void) cancelBtnAction { [self getDataArrayByType]; } #pragma mark ---------tableView协议---------------- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [self.indexArray count]; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [self.indexArray objectAtIndex:section]; } -(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{ UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view; header.tintColor = HEXCOLOR(0xF2F2F2); [header.textLabel setTextColor:HEXCOLOR(0x999999)]; [header.textLabel setFont:SYSFONT(15)]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [(NSArray *)[self.letterResultArr objectAtIndex:section] count]; } -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ return self.indexArray; } - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{ return index; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { JXCell *cell=nil; if (!cell) { cell = [[JXCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellNames"]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; NSDictionary *dict= [[self.letterResultArr objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]; memberData *member=dict[@"model"]; [_table addToPool:cell]; cell.title = member.userNickName; cell.isSmall = YES; [cell headImageViewImageWithUserId:nil roomId:nil]; QCheckBox* btn = [[QCheckBox alloc] initWithDelegate:self]; btn.frame = CGRectMake(JX_SCREEN_WIDTH-45, 18.5, 22, 22); btn.tag = (indexPath.section+1) * 100000 + (indexPath.row+1); BOOL b = NO; NSString* s = [NSString stringWithFormat:@"%ld",member.userId]; b = [_existSet containsObject:s]; btn.selected = b; btn.userInteractionEnabled = !b; [cell addSubview:btn]; [_checkBoxArr addObject:btn]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *dict= [[self.letterResultArr objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]; memberData *user=dict[@"model"]; if (![_existSet containsObject:[NSString stringWithFormat:@"%ld",user.userId]]) { QCheckBox *checkBox = nil; JXCell *cell = [tableView cellForRowAtIndexPath:indexPath]; checkBox = [cell viewWithTag:(indexPath.section+1) * 100000 + (indexPath.row+1)]; checkBox.selected = !checkBox.selected; [self didSelectedCheckBox:checkBox checked:checkBox.selected]; } } -(void)reomveExistsSet{ for(NSInteger i=[_array count]-1;i>=0;i--){ memberData* p = [_array objectAtIndex:i]; if([self.existSet containsObject:[NSString stringWithFormat:@"%ld",p.userId]]>0) [_array removeObjectAtIndex:i]; } } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 59; } - (void)didSelectedCheckBox:(QCheckBox *)checkbox checked:(BOOL)checked{ if (!checkbox.enabled) { return; } if ( checked && self.maxSize > 0 && _userIds.count == self.maxSize) { checkbox.selected = NO; [JXMyTools showTipView:@"群成员已达上限"]; return; } NSDictionary *dict = [[self.letterResultArr objectAtIndex:checkbox.tag / 100000-1] objectAtIndex:checkbox.tag % 100000-1]; memberData *user=dict[@"model"]; NSString *userId; NSString *userNickname; memberData *member = (memberData *)user; userId = [NSString stringWithFormat:@"%ld",member.userId]; userNickname = [NSString stringWithFormat:@"%@",member.userNickName]; if(checked){ // 选定 if (![_userIds containsObject:userId]) { // 所有id包含选择id [_userIds addObject:userId]; [_userNames addObject:userNickname]; } if (![_set containsObject:[NSNumber numberWithInteger:checkbox.tag]]) { [_set addObject:[NSNumber numberWithInteger:checkbox.tag]]; } } else{ // 取消选定 if ([_userIds containsObject:userId]) { NSInteger index = [_userIds indexOfObject:userId]; [_userIds removeObject:userId]; [_userNames removeObjectAtIndex:index]; [_set removeObject:[NSNumber numberWithInteger:checkbox.tag]]; } } } -(void)onAdd { if (!self.addressBookArr || self.addressBookArr.count <= 0) { if (self.isForRoom) { if (![_userIds containsObject:self.forRoomUser.userId]) { [_userIds addObject:self.forRoomUser.userId]; [_userNames addObject:self.forRoomUser.userNickname]; } } } [self actionQuit]; } @end