123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674 |
- //
- // MyTDTopicGroupUserVC.m
- // smartRhino
- //
- // Created by niuzhen on 2019/12/18.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "MyTDTopicGroupUserVC.h"
- #import "MyTDGroupView.h"
- #import "YCMenuView.h"
- #import "MailListCell.h"
- #import "MailListByZuCell.h"
- #import "ChineseString.h"
- #import "AddLookUpUserSecondVC.h"
- #import "MyTDTopicUserMoveVC.h"
- #import "MyTDTopicUserSearchVC.h"
- @interface MyTDTopicGroupUserVC ()<UITableViewDelegate,UITableViewDataSource,AddLookUpUserSecondVCDelegate>
- @property (weak, nonatomic) IBOutlet UIButton *addBtn;
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property (weak, nonatomic) IBOutlet UILabel *titleL;
- @property (weak, nonatomic) IBOutlet UIButton *operationAllSelectButton;
- @property (weak, nonatomic) IBOutlet UIButton *menuBtn;
- @property (assign,nonatomic) OperationStateEnum operationStateEnum;
- @property (strong,nonatomic) UIView *operationBottomBgView;
- @property (nonatomic, strong) UIButton *leftCloseBtn;
- @property (nonatomic, strong) UIButton *rightMoveBtn;
- @property (nonatomic, assign) BOOL iSViewEditor;
- @property (nonatomic, assign) BOOL isNeedSelelct;
- @property (strong,nonatomic) NSMutableArray *taskActionArray;
- @property (strong,nonatomic) NSMutableArray *pinyinArray;
- @property (strong,nonatomic) NSMutableArray *nameArray;
- @property (nonatomic, strong) NSMutableArray *dataArray;
- @property (nonatomic, strong) NSMutableArray *dataSortArray;
- @property (nonatomic, strong) NSMutableArray *selectArray;
- @property (nonatomic, strong) NSMutableArray *selectIdArray;
- @property (nonatomic, strong) NSMutableArray *listArray;
- @end
- @implementation MyTDTopicGroupUserVC
- +(MyTDTopicGroupUserVC *)initMyTDTopicGroupUserVC{
- MyTDTopicGroupUserVC *controller = [StoryboardManager.shared.myTDTopic instantiateViewControllerWithIdentifier:@"MyTDTopicGroupUserVC"];
- return controller;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.titleL.text = self.titleStr;
- [self getData];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recviveChaoSongRen:) name:NOTIFI_ChaoSongRen object:nil];
- self.fd_prefersNavigationBarHidden = YES;
- self.view.backgroundColor = RGB(255, 255, 255);
-
- if (@available(iOS 11.0, *)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.backgroundColor = [UIColor clearColor];
- self.iSViewEditor = NO;
- [self initBottomBgView];
- [self changeToOperation:NO];
- WS(weakSelf);
- [self.operationAllSelectButton setAction:^{
- for (NSArray * array in weakSelf.dataSortArray) {
- for (SelectModel * model in array) {
- model.hadSelected = weakSelf.isNeedSelelct;
- }
- }
- [weakSelf.tableView reloadData];
- }];
- self.isNeedSelelct = YES;
- [self.addBtn setAction:^{
- NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.taskActionArray];
- YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:106 relyonView:weakSelf.addBtn];
- view.menuColor = RGB(255, 255, 255);
- view.separatorColor = RGB(234, 234, 234);
- view.textColor = RGB(102, 102, 102);
- view.textFont = [UIFont systemFontOfSize:16.0];
- view.menuCellHeight = 43.5;
- view.maxDisplayCount = 10;
- view.offset = -6;
- [view show];
- }];
- }
- -(void)initBottomBgView{
- self.leftCloseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [self.leftCloseBtn setTitle:@"删除" forState:UIControlStateNormal];
- [self.leftCloseBtn setTitleColor:RGB(255, 82, 82) forState:UIControlStateNormal];
- self.leftCloseBtn.titleLabel.font = [UIFont systemFontOfSize:15];
-
- [self.operationBottomBgView addSubview:self.leftCloseBtn];
- self.leftCloseBtn.frame = CGRectMake(0, 10, SCREEN_WIDTH/2, self.operationBottomBgView.height - 10);
-
- self.self.rightMoveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [self.rightMoveBtn setTitle:@"移动" forState:UIControlStateNormal];
- [self.rightMoveBtn setTitleColor:RGB(57, 121, 211) forState:UIControlStateNormal];
- [self.rightMoveBtn setTitleColor:UIColorHex(#BBBBBB) forState:UIControlStateDisabled];
- self.rightMoveBtn.enabled = NO;
- self.rightMoveBtn.titleLabel.font = [UIFont systemFontOfSize:15];
-
- [self.operationBottomBgView addSubview:self.rightMoveBtn];
- self.rightMoveBtn.frame = CGRectMake(SCREEN_WIDTH/2, 10, SCREEN_WIDTH/2, self.operationBottomBgView.height - 10);
-
- UIView *line = [[UIView alloc] init];
- line.backgroundColor = RGB(240, 239, 244);
- [self.operationBottomBgView addSubview:line];
- line.frame = CGRectMake(SCREEN_WIDTH/2, 0, .5, self.operationBottomBgView.height);
-
-
- UIView *topLine = [[UIView alloc] init];
- topLine.backgroundColor = RGB(240, 239, 244);
- [self.operationBottomBgView addSubview:topLine];
- topLine.frame = CGRectMake(0, 0, SCREEN_WIDTH, 10);
-
- WS(weakSelf);
- [self.leftCloseBtn setAction:^{
- NSMutableArray *selectIDArray = [NSMutableArray array];
- for (NSArray * array in weakSelf.dataSortArray) {
- for (SelectModel * model in array) {
- if (model.hadSelected) {
- [selectIDArray addObject:@(model.Id)];
- }
- }
- }
- if (selectIDArray.count == 0) {
- SHOWERROR(@"请选择要删除的通知");
- return ;
- }else{
- [weakSelf deleteFind:selectIDArray];
- }
- }];
-
- [self.rightMoveBtn setAction:^{
- NSMutableArray *selectIDArray = [NSMutableArray array];
- for (NSArray * array in weakSelf.dataSortArray) {
- for (SelectModel * model in array) {
- if (model.hadSelected) {
- [selectIDArray addObject:@(model.Id)];
- }
- }
- }
- if (selectIDArray.count == 0) {
- SHOWERROR(@"请选择要移动的通知或者文件夹");
- return ;
- }
- [weakSelf launchMoveVC:selectIDArray];
- }];
-
- [[UtilsTools getWindow] addSubview:self.operationBottomBgView];
- }
- #pragma Mark 左滑按钮 iOS8以上
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
- - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){// delete action
- WS(weakSelf);
- SelectModel * model = [[self.dataSortArray objectAtIndex:indexPath.section-1] objectAtIndex:indexPath.row];
- UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
- UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf deleteFind:@[@(model.Id)]];
- }];
- UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alert addAction:sureAction];
- [alert addAction:cancelAction];
- [weakSelf presentViewController:alert animated:YES completion:^{
-
- }];
- }];
- action1.backgroundColor = UIColorHex(#F64A33);
- UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"移动" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
- [weakSelf launchMoveVC:@[@(model.Id)]];
- }];
- action2.backgroundColor = RGB(61, 156, 248);
- UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1,action2]];
- actions.performsFirstActionWithFullSwipe = NO;
- return actions;
- }
- #else
- - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
- WS(weakSelf);
- SelectModel * model = [[self.dataSortArray objectAtIndex:indexPath.section-1] objectAtIndex:indexPath.row];
- UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- [weakSelf deleteFind:@[@(model.Id)]];
- }];
- action1.backgroundColor = UIColorHex(#F64A33);
- UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"移动" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- SelectModel * model = [[weakSelf.dataSortArray objectAtIndex:indexPath.section-1] objectAtIndex:indexPath.row];
- [weakSelf launchMoveVC:@[@(model.Id)]];
- }];
- action2.backgroundColor = RGB(61, 156, 248);
- return @[action1,action2];
- }
- #endif
- - (void)deleteFind:(NSArray *)array
- {
- WS(weakSelf);
- [[HttpManager sharedHttpManager] DeleteUrl:Host(APP_Topic_Group_User) parameters:@{@"Ids":array} responseStyle:DATA success:^(id _Nonnull responseObject) {
- [weakSelf getData];
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error])
- }];
- }
- - (void)launchMoveVC:(NSArray *)selectIDArray{
- MyTDTopicUserMoveVC * vc = [MyTDTopicUserMoveVC initMyTDTopicUserMoveVC];
- vc.selectIdArray = selectIDArray;
- [self.navigationController pushViewController:vc animated:YES];
- [self changeToOperation:NO];
- }
- -(UIView *)operationBottomBgView{
- if(!_operationBottomBgView){
- _operationBottomBgView = [[UIView alloc] init];
- CGFloat bottomBgViewH = self.tabBarController.tabBar.height + 10;
- _operationBottomBgView.frame = CGRectMake(0, SCREEN_HEIGHT - bottomBgViewH, SCREEN_WIDTH, bottomBgViewH);
- _operationBottomBgView.backgroundColor = RGB(255, 255, 255);
- _operationBottomBgView.hidden = YES;
- }
- return _operationBottomBgView;
- }
- #pragma mark 批量操作与正常操作界面切换
- -(void)changeToOperation:(BOOL)operation{
- if(operation){
- self.iSViewEditor = YES;
- //默认操作状态为批量编辑状态
- self.addBtn.hidden = YES;
- self.menuBtn.hidden = YES;
- self.operationStateEnum = OperationStateEnum1;
- self.operationAllSelectButton.hidden = NO;
-
- self.tabBarController.tabBar.hidden = YES;
-
- self.operationBottomBgView.hidden = NO;
- self.view.height -= self.tabBarController.tabBar.height;
- self.tableView.height -= self.tabBarController.tabBar.height;
- [self.view layoutIfNeeded];
- [self.tableView layoutIfNeeded];
- }else{
- self.iSViewEditor = NO;
- self.menuBtn.hidden = NO;
- self.addBtn.hidden = NO;
- //默认操作状态为无状态
- self.operationStateEnum = OperationStateEnum0;
- self.operationAllSelectButton.hidden = YES;
-
- self.tabBarController.tabBar.hidden = YES;
-
- self.tableView.height += self.tabBarController.tabBar.height;
- self.view.height += self.tabBarController.tabBar.height;
- [self.view layoutIfNeeded];
- [self.tableView layoutIfNeeded];
- self.operationBottomBgView.hidden = YES;
- }
- [self.tableView reloadData];
- }
- #pragma mark 移动 isEdit:当前是否为编辑状态
- -(void)userDidMove:(BOOL)move isEdit:(BOOL)isEdit{
- //移动
- if(move){
- //默认操作状态为移动状态
- self.operationStateEnum = OperationStateEnum2;
- self.addBtn.hidden = NO;
- [self resetRightBtnAction:NO];
-
- //隐藏tabBar - 并将TableView至底端
- self.tabBarController.tabBar.hidden = YES;
- self.view.height += self.tabBarController.tabBar.height;
- self.tableView.height += self.tabBarController.tabBar.height;
- [self.view layoutIfNeeded];
- [self.tableView layoutIfNeeded];
- //隐藏operationBottomBgView
- self.operationBottomBgView.hidden = YES;
- }
- else{
- //隐藏tabBar - 并将TableView至底端有tabBar.height的高
- self.tabBarController.tabBar.hidden = YES;
- self.view.height -= self.tabBarController.tabBar.height;
- self.tableView.height -= self.tabBarController.tabBar.height;
- [self.view layoutIfNeeded];
- [self.tableView layoutIfNeeded];
- //显示operationBottomBgView
- self.operationBottomBgView.hidden = NO;
-
- if(isEdit){
- self.operationStateEnum = OperationStateEnum1;
- self.addBtn.hidden = YES;
- [self resetRightBtnAction:YES];
- }else{
- [self changeToOperation:NO];
- }
- }
- [self.tableView reloadData];
- }
- -(void)resetRightBtnAction:(BOOL)isShowMenu{
- WS(weakSelf);
- if(isShowMenu){
- [self.addBtn setAction:^{
- NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.taskActionArray];
- YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:106 relyonView:weakSelf.addBtn];
- view.menuColor = RGB(255, 255, 255);
- view.separatorColor = RGB(234, 234, 234);
- view.textColor = RGB(102, 102, 102);
- view.textFont = [UIFont systemFontOfSize:16.0];
- view.menuCellHeight = 43.5;
- view.maxDisplayCount = 10;
- view.offset = -6;
- [view show];
- }];
- }
- }
- - (void)backAction:(id)sender{
- if (self.iSViewEditor) {
- [self changeToOperation:NO];
- }else{
- [self.navigationController popViewControllerAnimated:true];
- }
- }
- - (void)menuAction:(id)sender{
- [super menuAction:sender];
- }
- -(NSMutableArray *)getMenuDataSource:(NSMutableArray *)titleArray{
- NSMutableArray *menuDataSourceArray = [[NSMutableArray alloc] init];
- for(int i=0;i<titleArray.count;i++){
- NSString *titleStr = [titleArray objectAtIndex:i];
- WS(weakSelf);
- YCMenuAction *actionMenu = [YCMenuAction actionWithTitle:titleStr image:nil handler:^(YCMenuAction *action) {
- if([@"添加人员" isEqualToString:action.title]){
- Department *defaltGroupSetion = [[Department alloc]init];
- defaltGroupSetion.Name = @"单位通讯录";
- defaltGroupSetion.Id = 0;
-
- Department *myGroupSetion = [[Department alloc]init];
- myGroupSetion.Name = @"自建通讯录";
- defaltGroupSetion.Id = 0;
-
- AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
- vc.departSourceDataArray = @[defaltGroupSetion,myGroupSetion].mutableCopy;
- vc.isDefalutPage = 1;
- vc.titleStr = @"添加成员";
- vc.delegate = weakSelf;
- NSMutableArray * array = [NSMutableArray array];
- for (SelectModel * model in weakSelf.dataArray) {
- [array addObject:@(model.UserId)];
- }
- vc.UserIds = array;
- [weakSelf.navigationController pushViewController:vc animated:YES];
- }else if ([@"批量编辑" isEqualToString:action.title]){
- [weakSelf changeToOperation:YES];
- }
- }];
- [menuDataSourceArray addObject:actionMenu];
- }
- return menuDataSourceArray;
- }
- -(NSMutableArray *)taskActionArray{
- if(!_taskActionArray){
- _taskActionArray = [[NSMutableArray alloc] initWithObjects:@"添加人员",@"批量编辑", nil];
- }
- return _taskActionArray;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1 + self.dataSortArray.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- switch (section) {
- case 0:{
- return 0;
- }break;
- default:{
- if (self.dataSortArray.count > 0) {
- NSArray * array = self.dataSortArray[section - 1];
- return array.count;
- }else{
- return 0;
- }
- }break;
- }
- }
- //section右侧index数组
- -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
- return self.pinyinArray;
- }
- //点击右侧索引表项时调用 索引与section的对应关系
- - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
- return index;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- UIView *headerView = [[UIView alloc]init];
- if(section > 0){
- [headerView setBackgroundColor:RGBA(238, 238, 238, 1)];
- NSString *returnStr = [self.pinyinArray objectAtIndex:section - 1];
- UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 30)];
- [headerView addSubview:headerLabel];
- headerLabel.font = [UIFont systemFontOfSize:14.f];
- headerLabel.text = returnStr;
- headerLabel.textColor = RGB(153, 153, 153);
- }else{
- [headerView setBackgroundColor:[UIColor whiteColor]];
- [headerView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
- MyTDGroupView * view = [[MyTDGroupView alloc] init];
- [headerView addSubview:view];
- WS(weakSelf);
- UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
- MyTDTopicUserSearchVC * vc = [[MyTDTopicUserSearchVC alloc] init];
- vc.listArray = [NSMutableArray arrayWithArray:weakSelf.listArray];
- vc.upDateBlock = ^{
- [weakSelf getData];
- };
- [weakSelf.navigationController pushViewController:vc animated:YES];
- }];
- [headerView addGestureRecognizer:tap];
- }
- return headerView;
- }
-
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- if(section > 0){
- return 30;
- }
- return 50.f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return 0.01f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 65.f;
- }
-
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- SelectModel * model = [[self.dataSortArray objectAtIndex:indexPath.section-1] objectAtIndex:indexPath.row];
- switch (self.operationStateEnum) {
- case OperationStateEnum0:
- {
- MailListByZuCell *cell = [MailListByZuCell configCell0:tableView indexPath:indexPath];
- cell.cell0TitleLabel.text = model.UserName;
- [cell.cell0ImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
- return cell;
- }
- break;
- default:
- {
- MailListByZuCell *cell = [MailListByZuCell configCell1:tableView indexPath:indexPath];
- cell.cell0TitleLabel.text = model.UserName;
- [cell.cell0ImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
- cell.selectBtn.selected = model.hadSelected;
- self.rightMoveBtn.enabled = [self isMoveCheckData];
- if ([self isAllSelect]) {
- self.isNeedSelelct = NO;
- [self.operationAllSelectButton setTitle:@"取消全选" forState:UIControlStateNormal];
- }else{
- self.isNeedSelelct = YES;
- [self.operationAllSelectButton setTitle:@"全选" forState:UIControlStateNormal];
- }
- return cell;
- }
- break;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
- {
- NSLog(@"safdasfasdf");
- SelectModel * model = [[self.dataSortArray objectAtIndex:indexPath.section-1] objectAtIndex:indexPath.row];
- switch (self.operationStateEnum) {
- case OperationStateEnum1:{
- model.hadSelected = !model.hadSelected;
- [tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationNone];
- }break;
- default:{
- }break;
- }
- }
- - (BOOL)isAllSelect
- {
- for (NSArray * array in self.dataSortArray) {
- for (SelectModel * model in array) {
- if (!model.hadSelected) {
- return NO;
- }
- }
- }
- return YES;
- }
- - (BOOL)isMoveCheckData
- {
- BOOL isSelect = NO;
- for (NSArray * array in self.dataSortArray) {
- for (SelectModel * model in array) {
- if (model.hadSelected) {
- isSelect = YES;
- }
- }
- }
- if (!isSelect) {
- return NO;
- }
- return YES;
- }
- - (void)sortData
- {
- [self.dataSortArray removeAllObjects];
- self.pinyinArray = [[NSMutableArray alloc] init];
- self.nameArray = [[NSMutableArray alloc] init];
- NSMutableArray *stringsToSort = [[NSMutableArray alloc] init];
- for(int i = 0;i < [self.dataArray count];i++){
- SelectModel *model = [self.dataArray objectAtIndex:i];
- NSString * str = [NSString stringWithFormat:@"%@UserId%ld",model.UserName,(long)model.UserId];
- [stringsToSort addObject:str];
- }
- self.pinyinArray = [ChineseString IndexArray:stringsToSort];
- self.nameArray = [ChineseString LetterSortArray:stringsToSort];
- for (NSArray * array in self.nameArray) {
- NSMutableArray * subAddArray = [NSMutableArray array];
- for (NSString * string in array) {
- NSInteger flag = 0;
- BOOL isAdd = NO;
- for (NSInteger i = 0; i < self.dataArray.count; i ++) {
- SelectModel * model = self.dataArray[i];
- if ([string containsString:[NSString stringWithFormat:@"UserId%ld",(long)model.UserId]]) {
- [subAddArray addObject:model];
- isAdd = YES;
- flag = i;
- }
- }
- if (isAdd) {
- [self.dataArray removeObjectAtIndex:flag];
- }
- }
- if (subAddArray.count > 0) {
- [self.dataSortArray addObject:subAddArray];
- }
- }
- WS(weakSelf);
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- });
- }
- - (void)getData{
- [self.listArray removeAllObjects];
- [self.dataArray removeAllObjects];
- WS(weakSelf);
- SHOWLOADING
- NSString * url = [NSString stringWithFormat:@"%@%ld",Host(APP_Topic_User_Get),(long)self.GroupId];
- [[HttpManager sharedHttpManager] GETUrl:url parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
- NSLog(@"%@",responseObject);
- REMOVESHOW
- for (NSDictionary * dict in responseObject[@"Items"]) {
- SelectModel * model = [SelectModel modelWithDictionary:dict];
- model.UserName = model.Name;
- [weakSelf.dataArray addObject:model];
- [weakSelf.listArray addObject:model];
- }
- [weakSelf sortData];
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error])
- }];
- }
- #pragma mark - Notification
- - (void)recviveChaoSongRen:(NSNotification *)notification{
- NSMutableArray <SelectModel *>* array = notification.userInfo[@"selectPeople"];
-
- NSMutableArray <SelectModel *>* array0 = self.selectArray;
- NSMutableArray <SelectModel *>* array1 = notification.userInfo[@"selectPeople"];
- if (array0.count == 0) {
- [self.selectArray addObjectsFromArray:array];
- }else{
- for (NSInteger x = 0; x < array.count; x++) {
- for (NSInteger y = 0 ; y < array0.count; y++) {
- if (array[x].UserId == array0[y].UserId) {
- [array1 removeObjectAtIndex:x];
- }
- }
- }
- [self.selectArray addObjectsFromArray:array1];
- }
- if (self.selectArray.count > 0) {
- for (NSInteger i = 0; i < self.selectArray.count; i ++) {
- SelectModel * model = self.selectArray[i];
- [self.selectIdArray addObject:@(model.UserId)];
- }
- [self addUser:self.selectIdArray];
- }
- }
- - (void)addUser:(NSArray *)array
- {
- NSLog(@"=============%@",array);
- NSDictionary * paraDict = @{@"UserIds":array,
- @"TopicGroupId":@(self.GroupId)
- };
- WS(weakSelf);
- SHOWLOADING
- [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Topic_Add_Group_User) parameters:paraDict responseStyle:DATA success:^(id _Nonnull responseObject) {
- REMOVESHOW
- NSLog(@"添加人员成功");
- [weakSelf getData];
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error])
- }];
- }
- - (NSMutableArray *)selectArray
- {
- if (!_selectArray) {
- _selectArray = [NSMutableArray array];
- }
- return _selectArray;
- }
- - (NSMutableArray *)selectIdArray
- {
- if (!_selectIdArray) {
- _selectIdArray = [NSMutableArray array];
- }
- return _selectIdArray;
- }
- - (NSMutableArray *)nameArray{
- if(!_nameArray) {
- _nameArray = [NSMutableArray array];
- }
- return _nameArray;
- }
- - (NSMutableArray *)dataArray{
- if(!_dataArray) {
- _dataArray = [NSMutableArray array];
- }
- return _dataArray;
- }
- - (NSMutableArray *)listArray{
- if(!_listArray) {
- _listArray = [NSMutableArray array];
- }
- return _listArray;
- }
- - (NSMutableArray *)dataSortArray{
- if(!_dataSortArray) {
- _dataSortArray = [NSMutableArray array];
- }
- return _dataSortArray;
- }
- - (void)dealloc
- {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self changeToOperation:NO];
- }
- @end
|