123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- //
- // 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 ()<UITextFieldDelegate, UIAlertViewDelegate,JXRoomObjectDelegate>
- @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
|