// // SendInfoGroupVC.m // smartRhino // // Created by tederen on 2019/11/4. // Copyright © 2019 tederen. All rights reserved. // #import "SendInfoGroupVC.h" #import "SendInfoGroupModel.h" #import "SendInfoGroupSubModel.h" #import "SendInfoGroupSubTwoModel.h" #import "SendInfoGroupCell.h" #import "SendGroupBCell.h" #import "AddressBookGroupModel.h" #import "SearchBarDisplayCenter.h" #import "WZSendInfoCell.h" @interface SendInfoGroupVC () @property (nonatomic, strong) IBOutlet UIButton *allSelectButton; @property (weak, nonatomic) IBOutlet UILabel *pageTitleLabel; @property (nonatomic, strong) IBOutlet UIButton *rightButton; @property (nonatomic, strong) IBOutlet UITableView *myTableView; @property (nonatomic, strong) NSMutableArray *>*groupArray; @property (nonatomic, strong) TDButton *serachButton; @property (nonatomic, strong) AddressBookGroupModel *addressBookModel; @property (nonatomic, strong) NSMutableSet *userIdsSet; @property (nonatomic, strong) NSMutableSet *departmentIdsSet; @property (nonatomic, strong) NSMutableSet *addressBookGroupIdsSet; @property (strong,nonatomic) SearchBarDisplayCenter *searchBar; @property (nonatomic, strong) NSMutableArray *userIdsArr; @property (nonatomic, strong) NSMutableArray *departmentIdsArr; @property (nonatomic, strong) NSMutableArray *addressBookGroupIdsArr; @property (nonatomic,assign) BOOL isShowEditor; @end @implementation SendInfoGroupVC +(SendInfoGroupVC *)initSendInfoGroupVC{ SendInfoGroupVC *controller = [StoryboardManager.shared.mailList instantiateViewControllerWithIdentifier:@"SendInfoGroupVC"]; return controller; } -(void)getSearchKeyWord:(NSString *)searchWord{ NSLog(@"%@",searchWord); WS(weakSelf); if(searchWord.length > 0){ NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:searchWord forKey:@"Key"]; [[HttpManager sharedHttpManager] POSTWithUrl:AddressBookGroup_Search_Post parameters:dict success:^(id _Nonnull responseObject) { NSArray *array = responseObject; NSLog(@"%@",responseObject); if (array.count == 0) { SHOWERROR(@"没有搜到结果"); }else{ NSMutableArray *arr = [NSMutableArray array]; for (NSDictionary *dic in array) { AddressBookGroupsModel *model = [[AddressBookGroupsModel alloc]initWithDictionary:dic error:nil]; NSLog(@"%@",model); [arr addObject:model]; } [weakSelf.addressBookModel.AddressBookGroups removeAllObjects]; [weakSelf.addressBookModel.AddressBookGroups addObjectsFromArray:arr]; [weakSelf.myTableView reloadData]; } } failure:^(NSError * _Nonnull error) { SHOWERROR([ZYCTool handerResultData:error]) }]; }else{ } } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.pageTitleLabel.text = self.titleStr; [self getData]; self.isShowEditor = YES; [self setMenu:self.isShowEditor]; [self.rightButton addTarget:self action:@selector(confirmAction:) forControlEvents:UIControlEventTouchDown]; } - (void)setMenu:(BOOL)isShowEditor{ if (isShowEditor) { [self.allSelectButton setTitle:@"全选" forState:UIControlStateNormal]; [self.allSelectButton setImage:nil forState:UIControlStateNormal]; }else{ } } - (void)menuAction:(id)sender{ if (self.isShowEditor) { UIButton *button = sender; if ([[button titleLabel].text isEqualToString:@"全选"]) { [self.allSelectButton setTitle:@"取消全选" forState:UIControlStateNormal]; [self isSelectAllHander:YES]; }else{ [self.allSelectButton setTitle:@"全选" forState:UIControlStateNormal]; [self isSelectAllHander:NO]; } [self.myTableView reloadData]; }else{ [super menuAction:sender]; } } - (void)isSelectAllHander:(BOOL)isAllSelect{ for (NSInteger i = 0; i < self.groupArray.count;i++) { for (WZContactModel *mode in self.groupArray[i]) { mode.isSelect = isAllSelect; } } [self countSelectNumber]; } - (void)confirmAction:(UIButton*)btn{ NSMutableArray *departGroupArray = [NSMutableArray array]; NSMutableArray *cusGroupArray = [NSMutableArray array]; NSMutableArray *departUserArray = [NSMutableArray array]; NSMutableArray *cusUserArray = [NSMutableArray array]; for (NSInteger i = 0 ;i < self.groupArray.count; i++) { for (WZContactModel *model in self.groupArray[i]) { if (model.isSelect) { switch (model.modelDataType) { case MailListByZu_SysGroup: [departGroupArray addObject:model]; break; case MailListByZu_CusGroup: [cusGroupArray addObject:model]; break; case MailListByZu_SysUser: [departUserArray addObject:model]; break; case MailListByZu_CusUser: [cusUserArray addObject:model]; break; } } } } [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_SelectPeopleAndDepartMent object:nil userInfo:@{@"selectDepartAndPeople":@[departGroupArray,cusGroupArray,departUserArray,cusUserArray]}]; [self back]; } #pragma mark - 选中之后返回原控制器 - (void)back{ for ( int i = 0 ;i< self.navigationController.viewControllers.count;i++) { NSLog(@"%@",self.navigationController.viewControllers[i]); if ([self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MailListByZuVC")]) { [self.navigationController popToViewController:self.navigationController.viewControllers[i] animated:YES]; return; } } } //从服务器拉取数据 - (void)getData{ if (self.isHomePage) { WS(weakSelf); [[HttpManager sharedHttpManager] POSTUrl:Host(AddressBookGroup_ListGroup_Post) parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) { REMOVESHOW NSLog(@"通讯录首页%@",responseObject); NSDictionary *dic = responseObject; NSMutableArray *departmentsArray = dic[@"Departments"]; NSMutableArray *addressBookGroups = dic[@"AddressBookGroups"]; [weakSelf dictionaryToModelWithGroup:departmentsArray WidthDataType: MailListByZu_SysGroup withUser:addressBookGroups withDataType:MailListByZu_CusGroup]; [weakSelf.myTableView reloadData]; } failure:^(NSError * _Nonnull error) { REMOVESHOW SHOWERROR([ZYCTool handerResultData:error]); }]; }else{ WS(weakSelf); switch (self.pageType) { case MailListByZuPageType_Sys:{ [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddressBookGroup_DepartemntDetail_Post] parameters:@{@"departmentId":@(self.indexId)} responseStyle:JOSN success:^(id _Nonnull responseObject) { REMOVESHOW NSLog(@"=============/n 通讯录子页 系统分组 /n=================/n%@",responseObject); NSDictionary *dic = responseObject; NSArray *departments = dic[@"Departments"]; NSArray *users = dic[@"Users"]; [weakSelf dictionaryToModelWithGroup:departments.mutableCopy WidthDataType: MailListByZu_SysGroup withUser:users.mutableCopy withDataType:MailListByZu_SysUser]; [weakSelf.myTableView reloadData]; } failure:^(NSError * _Nonnull error) { REMOVESHOW SHOWERROR([ZYCTool handerResultData:error]); }]; }break; case MailListByZuPageType_custom:{ [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddressBookGroupUser_Get_Post] parameters:@{@"addressBookGroupId":@(self.indexId)} responseStyle:JOSN success:^(id _Nonnull responseObject) { REMOVESHOW NSLog(@"=============/n通讯录子页 自建分组 /n=================/n%@",responseObject); NSArray *usersArrray = responseObject[@"AddressBookGroupUsers"]; NSArray *groupsArrray = responseObject[@"AddressBookGroups"]; [weakSelf dictionaryToModelWithGroup:groupsArrray.mutableCopy WidthDataType: MailListByZu_CusGroup withUser:usersArrray.mutableCopy withDataType:MailListByZu_CusUser]; [weakSelf.myTableView reloadData]; } failure:^(NSError * _Nonnull error) { REMOVESHOW SHOWERROR([ZYCTool handerResultData:error]); }]; } break; } } } - (void)dictionaryToModelWithGroup:(NSMutableArray *)departmentsArray WidthDataType:(MailListDataModelType)departType withUser:(NSMutableArray *)addressBookGroups withDataType:(MailListDataModelType)userType{ NSMutableArray *departmentsArray2 = [NSMutableArray array]; NSMutableArray *addressBookGroups2 = [NSMutableArray array]; for (NSDictionary *dic in departmentsArray) { WZContactModel *model = [[WZContactModel alloc]initWithDictionary:dic error:nil]; model.modelDataType = departType; [departmentsArray2 addObject:model]; } for (NSDictionary *dic in addressBookGroups) { WZContactModel *model = [[WZContactModel alloc]initWithDictionary:dic error:nil]; model.modelDataType = userType; [addressBookGroups2 addObject:model]; } [self.groupArray addObject:departmentsArray2]; [self.groupArray addObject:addressBookGroups2]; [self.groupArray addObject:@[].mutableCopy]; } #pragma mark - 搜索事件处理 - (void)searchhander:(TDButton *)sedner{ } #pragma mark -UITableViewDelegate,UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return self.groupArray.count; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.groupArray[section].count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ WZContactModel *model = self.groupArray[indexPath.section][indexPath.row]; WS(weakSelf); [self countSelectNumber]; switch (self.pageType) { case MailListByZuPageType_Sys: { if (indexPath.section == 0) { WZSendInfoCell *cell = [WZSendInfoCell configCell0:tableView indexPath:indexPath]; cell.iconImageView.hidden = YES; cell.nameLeftSpace.constant = 0; cell.iconWidthSpace.constant = 0; cell.nameLab.text = model.Name; model.wzDataType = MailListByZuPageType_Sys; cell.selectbuton.selected = model.isSelect; [cell.selectbuton setAction:^{ model.isSelect = !model.isSelect; [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone]; }]; return cell; }else{ if (self.isHomePage) { WZSendInfoCell *cell = [WZSendInfoCell configCell0:tableView indexPath:indexPath]; cell.iconImageView.hidden = YES; cell.nameLeftSpace.constant = 0; cell.iconWidthSpace.constant = 0; cell.nameLab.text = model.GroupName; cell.selectbuton.selected = model.isSelect; model.wzDataType = MailListByZuPageType_custom; [cell.selectbuton setAction:^{ model.isSelect = !model.isSelect; [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone]; }]; return cell; }else{ WZSendInfoCell *cell = [WZSendInfoCell configCell0:tableView indexPath:indexPath]; cell.iconWidthSpace.constant = 40; cell.nameLeftSpace.constant = 10; cell.iconImageView.hidden = NO; [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:IMG(@"imagePlaceholder")]; cell.nameLab.text = model.Name; cell.selectbuton.selected = model.isSelect; [cell.selectbuton setAction:^{ model.isSelect = !model.isSelect; [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone]; }]; cell.rightImgeView.hidden = YES; return cell; } } }break; default:{ if (indexPath.section == 0) { WZSendInfoCell *cell = [WZSendInfoCell configCell0:tableView indexPath:indexPath]; cell.iconImageView.hidden = YES; cell.rightImgeView.hidden = NO; cell.nameLeftSpace.constant = 0; cell.nameLeftSpace.constant = 0; cell.nameLab.text = model.Name; cell.selectbuton.selected = model.isSelect; model.wzDataType = MailListByZuPageType_custom; [cell.selectbuton setAction:^{ model.isSelect = !model.isSelect; [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone]; }]; return cell; }else{ WZSendInfoCell *cell = [WZSendInfoCell configCell0:tableView indexPath:indexPath]; cell.iconImageView.hidden = YES; cell.iconWidthSpace.constant = 40; cell.nameLeftSpace.constant = 10; [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:IMG(@"imagePlaceholder")]; cell.nameLab.text = model.Name; cell.selectbuton.selected = model.isSelect; cell.rightImgeView.hidden = YES; [cell.selectbuton setAction:^{ model.isSelect = !model.isSelect; [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone]; }]; return cell; } } } } - (void)gotoNextPage:(NSIndexPath *)indexPath{ WZContactModel *model = self.groupArray[indexPath.section][indexPath.row]; SendInfoGroupVC *vc = [SendInfoGroupVC initSendInfoGroupVC]; vc.isHomePage = NO; vc.pageType = model.wzDataType; vc.indexId = model.Id; vc.titleStr = ISEmptyString(model.Name) ? model.GroupName:model.Name; [self.navigationController pushViewController:vc animated:YES]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ WZContactModel *model = self.groupArray[indexPath.section][indexPath.row]; switch (self.pageType) { case MailListByZuPageType_Sys: { if (indexPath.section == 0) { [self gotoNextPage:indexPath]; }else{ if (self.isHomePage) { [self gotoNextPage:indexPath]; }else{ model.isSelect = !model.isSelect; [self.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone]; } } }break; default:{ if (indexPath.section == 0) { [self gotoNextPage:indexPath]; }else{ model.isSelect = !model.isSelect; [self.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone]; } } } } - (void)countSelectNumber{ NSInteger flag = 0; for (NSInteger i = 0; i *> *)groupArray{ if (!_groupArray) { _groupArray = [NSMutableArray array]; } return _groupArray; } - (NSMutableSet *)departmentIdsSet{ if (!_departmentIdsSet) { _departmentIdsSet = [[NSMutableSet alloc]init]; } return _departmentIdsSet; } - (NSMutableSet *)addressBookGroupIdsSet{ if (!_addressBookGroupIdsSet) { _addressBookGroupIdsSet = [[NSMutableSet alloc]init]; } return _addressBookGroupIdsSet; } @end