123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- //
- // 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 ()<UITableViewDelegate,UITableViewDataSource>
- @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 <NSMutableArray<WZContactModel *> *>*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<self.groupArray.count;i ++) {
- for (WZContactModel *model in self.groupArray[i]) {
- if (model.isSelect) {
- flag += 1;
- }
- }
- }
- if (flag == 0) {
- self.rightButton.enabled = NO;
- }else{
- self.rightButton.enabled = YES;
- [self.rightButton setTitle:[NSString stringWithFormat:@"确定(%@)",@(flag).stringValue] forState:UIControlStateNormal];
- }
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 65;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- if (section == 0) {
- return [[UIView alloc] initWithFrame:CGRectZero];
- }else if( section == 1){
- return [[UIView alloc] initWithFrame:CGRectZero];
- }else{
- if (self.isHomePage) {
- UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,kGXScreenWidth,30)];
- UILabel *headTitleLab = [[UILabel alloc]initWithFrame:CGRectMake(16,(30-13)/2,250, 13)];
- [headerView addSubview:headTitleLab];
- headerView.backgroundColor = UIColorHex(F5F6F8);
- headTitleLab.text = @"最近使用";
- headTitleLab.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:14.f];
- headTitleLab.textColor = UIColorHex(999999);
- return headerView;
- }else{
- return nil;
- }
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- if (section == 0) {
- return 0;
- }else if (section == 1) {
- return 0;
- }else{
- return self.isHomePage ? 30 : 0;
- }
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
- return [[UIView alloc] initWithFrame:CGRectZero];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return 0;
- }
- #pragma mark -- setter
- - (NSMutableArray<NSMutableArray<WZContactModel *> *> *)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
|