123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924 |
- //
- // AddLookUpUserSecondVC.m
- // smartRhino
- //
- // Created by tederen on 2019/11/25.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "AddLookUpUserSecondVC.h"
- #import "SendInfoGroupCell.h"
- #import "SendGroupBCell.h"
- #import "MailListSearchVC.h"
- #import "MyTDGroupView.h"
- #import "MailModel.h"
- #import "MailListCell.h"
- @interface AddLookUpUserSecondVC ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) TDTableView *myTableView;
- @property (nonatomic, strong) UIView *listHeaderVIew;
- @property (nonatomic, strong) TDButton *serachButton;
- @property (nonatomic, strong) AddressBookGroupModel *addressBookModel;
- @property (nonatomic,assign) NSInteger indexflag;
- @property (nonatomic, strong) NSMutableArray <SelectModel*>*selectArray;
- @property (nonatomic, strong) NSMutableArray <Department *>*selectDepartArray;
- @property (nonatomic, strong) NSMutableArray <SelectModel*>*usersSourceDataArray;
- @property (nonatomic, strong) NSMutableArray *dataSourceArray;
- @property (nonatomic, strong) UIView *SortView;
- @property (nonatomic, strong) UIButton *allSelectBtn;
- @property (nonatomic, strong) UILabel *selectCountL;
- @end
- @implementation AddLookUpUserSecondVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self getdata];
- [self.view addSubview:self.listHeaderVIew];
- [self.listHeaderVIew mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.myNavigationBar.mas_bottom);
- make.height.mas_offset(44);
- }];
- [self addSortV];
- [self.view addSubview:self.myTableView];
- [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.SortView.mas_bottom);
- make.left.right.mas_equalTo(self.view);
- make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom);
- }];
- WS(weakSelf);
- UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
- MailListSearchVC *vc = [[MailListSearchVC alloc] init];
- vc.notChangeColor = weakSelf.notSearchChangeColor;
- vc.IsAddUser = YES;
- vc.isShow = weakSelf.isShow;
- vc.UserIds = weakSelf.UserIds;
- vc.DepartmentId = weakSelf.indexId;
- vc.SearchType = weakSelf.isMyGroup;
- [weakSelf.navigationController pushViewController:vc animated:YES];
- }];
- [self.listHeaderVIew addGestureRecognizer:tap];
- self.fd_prefersNavigationBarHidden = YES;
- self.view.backgroundColor = UIColorHex(#FFFFFF);
- self.myTableView.backgroundColor = UIColorHex(#F5F6F8);
- [self createnavi];
- }
- #pragma mark - 导航视图
- - (void)createnavi{
- self.myNavigationBar.titleLabel.text = self.titleStr;
- [self.myNavigationBar.rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
- [self.myNavigationBar.rightButton setTitle:@"确定" forState:UIControlStateNormal];
- [[self.myNavigationBar.rightButton titleLabel] setFont:[UIFont systemFontOfSize:15.f]];
- self.myNavigationBar.rightButton.hidden = NO;
- [self.myNavigationBar.rightButton mas_updateConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.myNavigationBar.backButton);
- make.height.mas_offset(@44);
- make.right.mas_equalTo(self.myNavigationBar.mas_right).offset(-15);
- }];
- }
- #pragma mark - 导航事件处理
- -(void)back{
- [self.navigationController popViewControllerAnimated:YES];
-
- }
- -(void)back1{
- for ( NSInteger i = (self.navigationController.viewControllers.count - 1); i > 0 ;i --) {
- NSLog(@"%@",self.navigationController.viewControllers[i]);
- if ([self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyWorkWordVC")]
- || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"ChatNewGroupVC")]
- || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"H5ViewController")]
- || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyTDTopicCreateVC")]
- || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyFavoriteNewFindVC")]
- || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"ChatNewRowVC")]
- || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyTDTopicGroupUserVC")]
- || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"WorkFlowOrderController")]
- || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"CreateInterLeterVC")]
- || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MailListByZuVC")]) {
- [self.navigationController popToViewController:self.navigationController.viewControllers[i] animated:YES];
- return;
- }
- }
- }
- //全选操作
- - (void)selectedAction{
- if (self.isAllSelected) {
- [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
- }else{
- [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
- }
- if (self.IsSubVC) {
- NSInteger count = 0;
- for(NSInteger i = 0 ; i < 2 ; i++){
- if (i == 0) {
- for (Department *depart in self.departSourceDataArray) {
- depart.hadSelected = self.isAllSelected;
- if (depart.hadSelected) {
- count ++;
- }
- }
- }
- if (i == 1) {
- for (SelectModel * model in self.usersSourceDataArray) {
- model.hadSelected = self.isAllSelected;
- if (model.hadSelected) {
- count ++;
- }
- }
- }
- }
- self.selectCountL.text = [NSString stringWithFormat:@"%ld",count];
- }else{
- NSInteger count = 0;
- for (NSArray * array in self.dataSourceArray) {
- for (MailModel * model in array) {
- model.IsSelect = self.isAllSelected;
- if (model.IsSelect) {
- count ++;
- }
- }
- }
- self.selectCountL.text = [NSString stringWithFormat:@"%ld",count];
- }
- [self.myTableView reloadData];
- }
- // 左边按钮 全选 取消全选
- - (void)secondBarButtonItems:(TDButton *)sender{
- [super menuAction:sender];
- }
- - (void)rightButtonAction:(TDButton *)sender{
- [self confirmAction:sender];
- }
- - (BOOL)hidesBottomBarWhenPushed{
- return YES;
- }
- - (void)confirmAction:(UIButton*)btn{
- // if (self.isAllSelected) {
- // //获取所有被选中的分组
- // NSMutableArray *groupIDArray = [NSMutableArray array];
- // for (Department *model in self.departSourceDataArray) {
- // if (model.hadSelected) {
- // [groupIDArray addObject:model];
- // }
- // }
- // for (SelectModel *mode in self.usersSourceDataArray) {
- // if (mode.hadSelected) {
- // mode.SourceType = 0;
- // mode.SourceId = mode.UserId;
- // mode.SourceName = mode.UserName;
- // [self.selectArray addObject:mode];
- // }
- // }
- // if (groupIDArray.count == 0) {
- // NSLog(@"选中%@",self.selectArray);
- // [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":self.selectArray}];
- // [self back1];
- // return;
- // } else {
- // NSMutableArray *selectedUsers = [[NSMutableArray alloc] init];
- // //把部门转换为成员
- // for (Department *model in groupIDArray) {
- // SelectModel *selectModel = [[SelectModel alloc] init];
- // selectModel.UserId = model.Id;
- // selectModel.UserName = model.Name ? model.Name : model.GroupName;
- // selectModel.SourceType = self.SourceType;
- // selectModel.SourceId = model.Id;
- // selectModel.SourceName = model.Name ? model.Name : model.GroupName;
- // [selectedUsers addObject:selectModel];
- // if ([model.Name isEqualToString:@"单位通讯录"]) {
- // selectModel.SourceType = 1;
- // }else if ([model.Name isEqualToString:@"自建通讯录"]) {
- // selectModel.SourceType = 3;
- // }
- // }
- // if (self.selectArray.count > 0) {
- // [selectedUsers addObjectsFromArray:self.selectArray];
- // }
- // [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":selectedUsers}];
- // [self back1];
- // return;
- // }
- // }
- // NSMutableArray *groupIDArray = [NSMutableArray array];
- // for (Department *model in self.departSourceDataArray) {
- // if (model.hadSelected) {
- // [groupIDArray addObject:@(model.Id)];
- // }
- // }
- // for (SelectModel *mode in self.usersSourceDataArray) {
- // if (mode.hadSelected) {
- // [self.selectArray addObject:mode];
- // }
- // }
- // if (self.selectArray.count > 0) {
- // NSLog(@"选中%@",self.selectArray);
- // [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":self.selectArray}];
- // [self back1];
- // return;
- // }else{
- // NSMutableDictionary *dic = @{@"ItemId":groupIDArray}.mutableCopy;
- // [dic setValue:@(self.isMyGroup) forKey:@"TypeId"];
- // if (self.isDefalutPage == 1) {
- // [dic setValue:@[@(0)] forKey:@"ItemId"];
- // if (self.indexflag == 0) {
- // if (self.departSourceDataArray.firstObject.hadSelected) {
- // [dic setValue:@(1) forKey:@"TypeId"];
- // }else{
- // [dic setValue:@(2) forKey:@"TypeId"];
- // }
- // }else if (self.indexflag == 1) {
- // if (self.departSourceDataArray.firstObject.hadSelected) {
- // [dic setValue:@(1) forKey:@"TypeId"];
- // }else{
- // [dic setValue:@(2) forKey:@"TypeId"];
- // }
- // }else if (self.indexflag == 2){
- // [dic setValue:@(1) forKey:@"TypeId"];
- // }
- // }
- // NSLog(@"请求参数1%@",dic);
- SHOWLOADING
- WS(weakSelf);
- // [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddChaoSongRen_Post] parameters:dic responseStyle:JOSN success:^(id _Nonnull responseObject) {
- // REMOVESHOW
- // for (NSDictionary *dict in responseObject) {
- // SelectModel * model = [SelectModel modelWithDictionary:dict];
- // model.UserId = model.Id;
- // model.UserName = model.Name;
- // model.SourceType = weakSelf.SourceType;
- // model.SourceId = model.UserId;
- // model.SourceName = model.UserName;
- // [weakSelf.selectArray addObject:model];
- // }
- // [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":weakSelf.selectArray}];
- // [weakSelf back1];
- // } failure:^(NSError * _Nonnull error) {
- // SHOWERROR([ZYCTool handerResultData:error]);
- // }];
- NSMutableDictionary * paraDict = [NSMutableDictionary dictionary];
- if (self.dataSourceArray.count > 0) {
- NSMutableArray * mArray = [NSMutableArray array];
- for (NSArray * array in self.dataSourceArray) {
- for (MailModel * model in array) {
- [mArray addObject:@{@"SourceType":@(model.TypeId),@"SourceId":@(0)}];
- }
- }
- [paraDict setValue:mArray forKey:@"Item"];
- }
- if (self.departSourceDataArray.count > 0) {
- NSMutableArray * mArray = [NSMutableArray array];
- for (Department *model in self.departSourceDataArray) {
- [mArray addObject:@{@"SourceType":@(1),@"SourceId":@(model.Id)}];
- }
- [paraDict setValue:mArray forKey:@"Item"];
- }
- [self.selectArray removeAllObjects];
- [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_User_Middle) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
- REMOVESHOW
- for (NSDictionary *dict in responseObject) {
- SelectModel * model = [SelectModel modelWithDictionary:dict];
- model.UserId = model.Id;
- model.UserName = model.Name;
- model.SourceType = weakSelf.SourceType;
- model.SourceId = model.UserId;
- model.SourceName = model.UserName;
- [weakSelf.selectArray addObject:model];
- }
- [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":weakSelf.selectArray}];
- [weakSelf back1];
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- // }
- }
- - (void)setRIghtButtonTitle:(NSInteger)indeflag{
- [self.myNavigationBar.rightButton setTitle:[NSString stringWithFormat:@"确定(%ld)",(long)indeflag] forState:UIControlStateNormal];
- // if (self.isDefalutPage == 1){
- // if (indeflag == 2) {
- // [self.myNavigationBar.backButton2 setTitle:@"取消全选" forState:UIControlStateNormal];
- // }else{
- // [self.myNavigationBar.backButton2 setTitle:@"全选" forState:UIControlStateNormal];
- // }
- // }else{
- // [self.myNavigationBar.backButton2 setTitle:@"全选" forState:UIControlStateNormal];
- // }
-
- }
- #pragma mark - setter
- - (TDTableView *)myTableView{
- if (!_myTableView) {
- _myTableView = [[TDTableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- _myTableView.delegate = self;
- _myTableView.dataSource = self;
- [self.myTableView registerNib:[UINib nibWithNibName:@"SendInfoGroupCell" bundle:nil] forCellReuseIdentifier:@"SendInfoGroupCell"];//SendGroupBCell
- [self.myTableView registerNib:[UINib nibWithNibName:@"SendGroupBCell" bundle:nil] forCellReuseIdentifier:@"SendGroupBCell"];
- }
- return _myTableView;
- }
- - (UIView *)listHeaderVIew{
- if (!_listHeaderVIew) {
- _listHeaderVIew = [UIView new];
- _listHeaderVIew.backgroundColor = UIColorHex(#FFFFFF);
- MyTDGroupView * groupView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 4, SCREEN_WIDTH, 36)];
- [_listHeaderVIew addSubview:groupView];
- }
- return _listHeaderVIew;
- }
- - (TDButton *)serachButton{
- if (!_serachButton) {
- _serachButton = [[TDButton alloc]initWithFrame:CGRectMake(20,5, kGXScreenWidth-40,40)];
- [_serachButton setTitle:@"搜索" forState:UIControlStateNormal];
- [[_serachButton titleLabel] setFont:[UIFont systemFontOfSize:14.f]];
- [_serachButton setImage:IMG(@"sendinfo_search") forState:UIControlStateNormal];
- [_serachButton setTitleColor:UIColorHex(B6B7B9) forState:UIControlStateNormal];
- _serachButton.backgroundColor = UIColorHex(F5F6F8);
- [_serachButton addTarget:self action:@selector(searchhander:) forControlEvents:UIControlEventTouchDown];
- [_serachButton layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:2];
- _serachButton.layer.cornerRadius = 20;
- _serachButton.layer.masksToBounds = YES;
- }
- return _serachButton;
- }
- - (NSMutableArray<SelectModel *> *)selectArray{
- if (!_selectArray) {
- _selectArray = [NSMutableArray array];
- }
- return _selectArray;
- }
- #pragma mark -UITableViewDelegate,UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- if (!self.IsSubVC) {
- return self.dataSourceArray.count;
- }else{
- return 2;
- }
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- if (!self.IsSubVC) {
- NSArray * array = self.dataSourceArray[section];
- return [array count];
- }else{
- if (section == 0) {
- return self.departSourceDataArray.count;
- }else{
- return self.usersSourceDataArray.count;
- }
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- WS(weakSelf);
- NSInteger count = [self countOfSelectArray];
- if (count > 0) {
- [self.myNavigationBar.rightButton setTitle:[NSString stringWithFormat:@"确定(%ld)",(long)count] forState:UIControlStateNormal];
- }else{
- [self.myNavigationBar.rightButton setTitle:@"确定" forState:UIControlStateNormal];
- }
- if (!self.IsSubVC) {
- if ([self checkAllSelect:2]) {
- [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
- }else{
- [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
- }
- NSString *cellIdentifier2 = @"SendGroupBCell";
- SendGroupBCell * cell = (SendGroupBCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
- NSArray * array = self.dataSourceArray[indexPath.section];
- if (array.count > 0) {
- MailModel * model = array[indexPath.row];
- [cell setDataModel:model];
- [cell.selectbuton setAction:^{
- model.IsSelect = !model.IsSelect;
- [weakSelf checkSelectCount:2];
- [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
- }];
- }
- return cell;
- }
- if (indexPath.section == 1) {
- if ([self checkAllSelect:0]) {
- [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
- }else{
- [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
- }
- NSString *cellIdentifier = @"SendInfoGroupCell";
- SendInfoGroupCell * detailCommentCell = (SendInfoGroupCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
- SelectModel *model = self.usersSourceDataArray[indexPath.row];
- if (model.IsDisable) {
- [detailCommentCell.selectbuton setEnabled:NO];
- [detailCommentCell.contentView setBackgroundColor:[UIColor grayColor]];
- }
- [detailCommentCell loadDataDepartUserModel:model indexWith:indexPath];
- [detailCommentCell.selectbuton setAction:^{
- model.hadSelected = !model.hadSelected;
- [weakSelf checkSelectCount:0];
- [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
- }];
- detailCommentCell.rightImgeView.hidden = YES;
- return detailCommentCell;
- }else{
- if ([self checkAllSelect:1]) {
- [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
- }else{
- [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
- }
- NSString *cellIdentifier2 = @"SendGroupBCell";
- SendGroupBCell * sendB = (SendGroupBCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
- Department *model = self.departSourceDataArray[indexPath.row];
- [sendB loadDataModelDepartment: model WithIndex:indexPath];
- [sendB.selectbuton setAction:^{
- model.hadSelected = !model.hadSelected;
- [weakSelf checkSelectCount:1];
- [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
- }];
- sendB.rightImgeView.hidden = NO;
- return sendB;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 65.f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- if (!self.IsSubVC && section > 0) {
- return 36.f;
- }else{
- return 0.01f;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return 0.01f;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
- view.backgroundColor = UIColorHex(0xF0EFF4);
- UILabel * titleL = [UILabel new];
- [view addSubview:titleL];
- titleL.textColor = UIColorHex(0x666666);
- titleL.font = Kfont(13);
- titleL.text = @"";
- [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_offset(48);
- make.centerY.mas_equalTo(view);
- }];
- return view;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- if (self.IsSubVC) {
- if (self.isDefalutPage == 1) {
- if (indexPath.row == 0) { //
- AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
- vc.indexId = self.departSourceDataArray[indexPath.row].Id;
- vc.isDefalutPage = 2;
- vc.isMyGroup = 1;
- vc.SourceType = 1;
- vc.IsSubVC = YES;
- vc.isShow = self.isShow;
- vc.UserIds = self.UserIds;
- vc.titleStr = self.titleStr;
- vc.grouperArray = self.grouperArray;
- vc.isAllSelected = self.isAllSelected;
- [self.navigationController pushViewController:vc animated:YES];
- }else{
- AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
- vc.indexId = self.departSourceDataArray[indexPath.row].Id;
- vc.isDefalutPage = 2;
- vc.isMyGroup = 2;
- vc.titleStr = self.titleStr;
- vc.SourceType = 3;
- vc.IsSubVC = YES;
- vc.isShow = self.isShow;
- vc.UserIds = self.UserIds;
- vc.grouperArray = self.grouperArray;
- vc.isAllSelected = self.isAllSelected;
- [self.navigationController pushViewController:vc animated:YES];
- }
- }else{
- if (indexPath.section == 0) {
- AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
- Department *model = self.departSourceDataArray[indexPath.row];
- vc.indexId = model.Id;
- vc.isDefalutPage = 2;
- vc.IsSubVC = YES;
- vc.isShow = self.isShow;
- vc.UserIds = self.UserIds;
- vc.titleStr = self.titleStr;
- vc.isMyGroup = self.isMyGroup;
- vc.SourceType = self.SourceType;
- vc.grouperArray = self.grouperArray;
- vc.isAllSelected = self.isAllSelected;
- [self.navigationController pushViewController:vc animated:YES];
- }else{
- SelectModel *model = self.usersSourceDataArray[indexPath.row];
- if (!model.IsDisable) {
- model.hadSelected = !model.hadSelected;
- [self.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
- }
- }
- }
- }else{
- NSArray * array = [self.dataSourceArray objectAtIndex:indexPath.section];
- MailModel * model = [array objectAtIndex:indexPath.row];
- switch (model.TypeId) {
- case MailListUserType:
- {
-
- }
- break;
- case MailListDesType:
- {
- AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
- vc.indexId = self.departSourceDataArray[indexPath.row].Id;
- vc.isDefalutPage = 2;
- vc.isMyGroup = 1;
- vc.SourceType = 1;
- vc.isShow = self.isShow;
- vc.IsSubVC = YES;
- vc.UserIds = self.UserIds;
- vc.titleStr = self.titleStr;
- vc.grouperArray = self.grouperArray;
- vc.isAllSelected = self.isAllSelected;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case MailListSysType:
- {
-
- }
- break;
- default:
- {
- AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
- vc.indexId = self.departSourceDataArray[indexPath.row].Id;
- vc.isDefalutPage = 2;
- vc.isMyGroup = 2;
- vc.titleStr = self.titleStr;
- vc.SourceType = 3;
- vc.IsSubVC = YES;
- vc.isShow = self.isShow;
- vc.UserIds = self.UserIds;
- vc.grouperArray = self.grouperArray;
- vc.isAllSelected = self.isAllSelected;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- }
- }
- }
- - (NSInteger)countOfSelectArray
- {
- NSInteger count = 0;
- for (SelectModel * model in self.usersSourceDataArray) {
- if (model.hadSelected) {
- count++;
- }
- }
- for (Department * model in self.departSourceDataArray) {
- if (model.hadSelected) {
- count++;
- }
- }
- if (count > 0) {
- [self.myNavigationBar.rightButton setTitleColor:UIColorHex(#3979D3) forState:UIControlStateNormal];
- }else{
- [self.myNavigationBar.rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
- }
- return count;
- }
- - (BOOL)checkAllSelect:(NSInteger)index
- {
- switch (index) {
- case 0:
- {
- for (SelectModel * model in self.usersSourceDataArray) {
- if (!model.hadSelected) {
- [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
- return NO;
- }
- }
- [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
- return YES;
- }
- break;
- case 1:
- {
- for (Department * model in self.departSourceDataArray) {
- if (!model.hadSelected) {
- [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
- return NO;
- }
- }
- [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
- return YES;
- }
- break;
- default:
- {
- for (NSArray * array in self.dataSourceArray) {
- for (MailModel * model in array) {
- if (!model.IsSelect) {
- [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
- return NO;
- }
- }
- }
- [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
- return YES;
- }
- break;
- }
- }
- - (void)checkSelectCount:(NSInteger)index
- {
- NSInteger count = 0;
- switch (index) {
- case 0:
- {
- for (SelectModel * model in self.usersSourceDataArray) {
- if (model.hadSelected) {
- count++;
- }
- }
- }
- break;
- case 1:
- {
- for (Department * model in self.departSourceDataArray) {
- if (model.hadSelected) {
- count++;
- }
- }
- }
- break;
- default:
- {
- for (NSArray * array in self.dataSourceArray) {
- for (MailModel * model in array) {
- if (model.IsSelect) {
- count++;
- }
- }
- }
- }
- break;
- }
- self.selectCountL.text = [NSString stringWithFormat:@"%ld",count];
- if (count > 0) {
- [self.myNavigationBar.rightButton setTitleColor:UIColorHex(#3979D3) forState:UIControlStateNormal];
- }else{
- [self.myNavigationBar.rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
- }
- }
- #pragma mark - 网络数据请求
- - (void)getdata{
- if (!self.IsSubVC) {
- [self getRootData];
- }
- if (self.isDefalutPage == 1) {
- return ;
- }
- if (self.isMyGroup == 1) {
- [self defaltGroupData];
- }
- if (self.isMyGroup == 2) {
- [self myGroupData];
- }
- }
- - (void)getRootData
- {
- SHOWLOADING
- WS(weakSelf);
- [self.dataSourceArray removeAllObjects];
- [[HttpManager sharedHttpManager] GETUrl:Host(API_APP_User_Link) parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
- NSLog(@"%@",responseObject);
- REMOVESHOW
- NSMutableArray * fArray = [NSMutableArray array];
- NSMutableArray * sArray = [NSMutableArray array];
- if ([responseObject[@"Items"] isKindOfClass:[NSArray class]]) {
- NSArray * array = responseObject[@"Items"];
- for (NSDictionary * dict in array) {
- MailModel * model = [MailModel modelWithDictionary:dict];
- [fArray addObject:model];
- }
- MailModel * omodel = [MailModel modelWithDictionary:@{@"Name":@"其他",@"TypeId":@(0)}];
- [fArray addObject:omodel];
- [weakSelf.dataSourceArray addObject:fArray];
- [weakSelf.dataSourceArray addObject:sArray];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.myTableView reloadData];
- });
- }
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- }];
- }
- - (void)defaltGroupData{
- SHOWLOADING
- NSDictionary * paraDict = @{@"DepartmentId":@(self.indexId),@"UserIds":self.UserIds,@"IsShow":@(self.isShow)};
- NSLog(@"%@",paraDict);
- [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddressBookGroup_DepartemntDetail_Post] parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
- REMOVESHOW;
- NSDictionary *dic = responseObject;
- NSArray *departMentArray = dic[@"Departments"];
- NSMutableArray *departMentMutableArray = [NSMutableArray array];
- for (NSDictionary *dic2 in departMentArray) {
- Department *model = [[Department alloc]initWithDictionary:dic2 error:nil];
- [departMentMutableArray addObject:model];
- }
- self.departSourceDataArray = departMentMutableArray;
- NSArray *userArray = dic[@"Users"];
- NSMutableArray *usersMutableArray = [NSMutableArray array];
- for (NSDictionary *dic2 in userArray) {
- SelectModel * model = [[SelectModel alloc] initDict:dic2];
- [usersMutableArray addObject:model];
- }
- for (SelectModel * model in self.grouperArray) {
- for (SelectModel * userModel in usersMutableArray) {
- if (userModel.UserId == model.UserId) {
- userModel.IsDelete = YES;
- }
- }
- }
- NSMutableArray * checkUserArray = [NSMutableArray array];
- for (SelectModel * model in usersMutableArray) {
- if (!model.IsDelete) {
- [checkUserArray addObject:model];
- }
- }
- self.usersSourceDataArray = checkUserArray;
- [self.myTableView reloadData];
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- - (void)myGroupData{
- SHOWLOADING
- NSDictionary * paraDict = @{@"AddressBookGroupId":@(self.indexId),@"UserIds":self.UserIds,@"IsShow":@(self.isShow)};
- NSLog(@"%@",paraDict);
- [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddressBookGroupUser_Get_Post] parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
- REMOVESHOW;
- NSDictionary *dic = responseObject;
- NSArray *departMentArray = dic[@"AddressBookGroups"];
- NSMutableArray *departMentMutableArray = [NSMutableArray array];
- for (NSDictionary *dic2 in departMentArray) {
- Department *model = [[Department alloc]initWithDictionary:dic2 error:nil];
- [departMentMutableArray addObject:model];
- }
- self.departSourceDataArray = departMentMutableArray;
- NSArray *userArray = dic[@"AddressBookGroupUsers"];
- NSMutableArray *usersMutableArray = [NSMutableArray array];
- for (NSDictionary *dic2 in userArray) {
- SelectModel * model = [SelectModel modelWithDictionary:dic2];
- [usersMutableArray addObject:model];
- }
- for (SelectModel * model in self.grouperArray) {
- for (SelectModel * userModel in usersMutableArray) {
- if (userModel.UserId == model.UserId) {
- userModel.IsDelete = YES;
- }
- }
- }
- NSMutableArray * checkUserArray = [NSMutableArray array];
- for (SelectModel * model in usersMutableArray) {
- if (!model.IsDelete) {
- [checkUserArray addObject:model];
- }
- }
- self.usersSourceDataArray = checkUserArray;
- [self.myTableView reloadData];
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- #pragma mark - 搜索事件处理
- - (void)searchhander:(TDButton *)sedner{
-
- }
- -(void)getSearchKeyWord:(NSString *)searchWord{
- NSLog(@"%@",searchWord);
- if(searchWord.length > 0){
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:searchWord forKey:@"Key"];
- WEAKSELF
- [[HttpManager sharedHttpManager] POSTWithUrl:Host(AddressBookGroup_Search_Post) parameters:dict success:^(id _Nonnull responseObject) {
- STRONGSELF
- NSArray *array = responseObject;
- if (array.count == 0) {
- SHOWERROR(@"没有搜到结果");
- }else{
-
- NSArray *userArray = responseObject;
- NSMutableArray *usersMutableArray = [NSMutableArray array];
- for (NSDictionary *dic2 in userArray) {
- SelectModel * model = [[SelectModel alloc] initDict:dic2];
- [usersMutableArray addObject:model];
- }
- [strongSelf.departSourceDataArray removeAllObjects];
- strongSelf.usersSourceDataArray = usersMutableArray;
- [strongSelf.myTableView reloadData];
- [strongSelf.myTableView reloadData];
-
- }
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error])
-
- }];
- }else{
-
- }
- }
- - (void)canCelAllSelect
- {
- for (SelectModel * model in self.usersSourceDataArray) {
- model.hadSelected = NO;
- }
- for (Department * model in self.departSourceDataArray) {
- model.hadSelected = NO;
- }
- }
- - (UIButton *)allSelectBtn
- {
- if (!_allSelectBtn) {
- _allSelectBtn = [UIButton new];
- [_allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
- }
- return _allSelectBtn;
- }
- - (UILabel *)selectCountL
- {
- if (!_selectCountL) {
- _selectCountL = [UILabel new];
- _selectCountL.font = Kfont(13);
- _selectCountL.text = @"0";
- _selectCountL.textColor = UIColorHex(0x0F88EB);
- }
- return _selectCountL;
- }
- - (UIView *)SortView
- {
- if (!_SortView) {
- _SortView = [UIView new];
- _SortView.backgroundColor = UIColorHex(0xF0EFF4);
- }
- return _SortView;
- }
- - (void)addSortV
- {
- [self.view addSubview:self.SortView];
- [self.SortView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.height.mas_offset(38);
- make.top.mas_equalTo(self.listHeaderVIew.mas_bottom);
- }];
- [self.SortView addSubview:self.allSelectBtn];
- [self.SortView addSubview:self.selectCountL];
- [self.allSelectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_offset(5);
- make.centerY.mas_equalTo(self.SortView);
- make.size.mas_offset(CGSizeMake(38, 38));
- }];
- UILabel * leftL = [UILabel new];
- leftL.text = @"已选:";
- leftL.textColor = UIColorHex(0x666666);
- leftL.font = Kfont(13);
- [self.SortView addSubview:leftL];
- [leftL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.allSelectBtn.mas_right).offset(5);
- make.centerY.mas_equalTo(self.SortView);
- }];
- [self.selectCountL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(leftL.mas_right).offset(8);
- make.centerY.mas_equalTo(self.SortView);
- }];
-
- WS(weakSelf);
- [self.allSelectBtn setAction:^{
- weakSelf.isAllSelected = !weakSelf.isAllSelected;
- [weakSelf selectedAction];
- }];
- }
- - (NSMutableArray *)dataSourceArray
- {
- if (!_dataSourceArray) {
- _dataSourceArray = [NSMutableArray array];
- }
- return _dataSourceArray;
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self canCelAllSelect];
- [self.myTableView reloadData];
- }
- @end
|