// // MyTDGroupViewController.m // smartRhino // // Created by tederen on 2019/10/31. // Copyright © 2019 tederen. All rights reserved. // #import "MyTDGroupViewController.h" #import "YCMenuView.h" #import "ShowNewGroupAlert.h" #import "NoticeListModel.h" #import "ChatNewRowVC.h" #import "ChatNewRowCell.h" #import "MoveViewController.h" #import "TDGroupSearchResultVC.h" #import "TDGroupInfoListVC.h" #import "MyTDGroupView.h" @interface MyTDGroupViewController () @property (nonatomic, strong) TDTableView *tableView; @property (nonatomic, strong) UIView *CusNavBar; @property (nonatomic, strong) UIView *HeadView; @property (nonatomic, strong) UIView *SortView; @property (nonatomic, strong) UIButton *allSelectBtn; @property (nonatomic, strong) UILabel *selectCountL; @property (strong, nonatomic) MyTDGroupView *SearchView; @property (nonatomic, strong) UILabel *titleL; @property (nonatomic, strong) UIButton *addBtn; @property (nonatomic, strong) NSMutableArray *dataArray; @property (nonatomic, copy) NSArray *addListArray; @property (assign,nonatomic) OperationStateEnum operationStateEnum; @property (strong,nonatomic) UIView *operationBottomBgView; @property (strong, nonatomic) UIButton *operationAllSelectButton; @property (nonatomic, strong) UIButton *leftCloseBtn; @property (nonatomic, strong) UIButton *rightMoveBtn; @property (nonatomic, assign) NSUInteger currentPage; @property (nonatomic, assign) NSUInteger totalPage; @property (nonatomic, assign) NSUInteger totalRecord; @property (nonatomic, assign) BOOL isAllSelect; @property (nonatomic, assign) Boolean iSViewEditor; @end @implementation MyTDGroupViewController - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; [self changeToOperation:NO]; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; [self addNavbarView]; // [self setTableViewRefresh]; [self initBottomBgView]; [self changeToOperation:NO]; self.iSViewEditor = NO; if (self.isPush) { [self pushListVC]; } } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self getData]; } - (void)addNavbarView { if (self.isSubVC) { self.addListArray = @[@"新建小组",@"批量编辑"]; }else{ self.addListArray = @[@"新建小组",@"建文件夹",@"批量编辑"]; } [self.view addSubview:self.CusNavBar]; [self.CusNavBar mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.mas_equalTo(self.view); make.height.mas_offset(kNavigationHeight); }]; // UILabel * lineL = [UILabel new]; // lineL.backgroundColor = LINEBGCOLOR; // [self.CusNavBar addSubview:lineL]; // [lineL mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.bottom.right.mas_equalTo(self.CusNavBar); // make.height.offset(0.5); // }]; UIButton * backBtn = [UIButton new]; [backBtn setImage:[UIImage imageNamed:@"back_black_icon"] forState:UIControlStateNormal]; [self.CusNavBar addSubview:backBtn]; self.operationAllSelectButton = [UIButton new]; [self.operationAllSelectButton setImage:[UIImage imageNamed:@"menu_black_icon"] forState:UIControlStateNormal]; [self.CusNavBar addSubview:self.operationAllSelectButton]; self.addBtn = [UIButton new]; if (self.isSelect) { [self.addBtn setImage:[UIImage imageNamed:@"add_find"] forState:UIControlStateNormal]; }else{ [self.addBtn setImage:[UIImage imageNamed:@"chatmsg_right_add_icon"] forState:UIControlStateNormal]; } [self.CusNavBar addSubview:self.addBtn]; [backBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.CusNavBar); make.bottom.mas_equalTo(self.CusNavBar); make.width.offset(50); make.height.offset(44); }]; [self.operationAllSelectButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(backBtn.mas_right); make.width.mas_greaterThanOrEqualTo(@35); make.height.offset(44); make.bottom.mas_equalTo(self.CusNavBar); }]; if (self.isSelect) { [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.CusNavBar).offset(-15); make.centerY.mas_equalTo(backBtn); }]; }else{ [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.CusNavBar); make.bottom.mas_equalTo(self.CusNavBar); make.width.offset(50); make.height.offset(44); }]; } [backBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside]; [self.operationAllSelectButton addTarget:self action:@selector(menuAction:) forControlEvents:UIControlEventTouchUpInside]; WS(weakSelf); [self.addBtn setAction:^{ if (weakSelf.isSelect) { ChatNewRowVC * vc = [ChatNewRowVC initChatNewRowVC]; vc.GroupFolderId = weakSelf.ParentId; vc.upDateBlock = ^{ [weakSelf getData]; }; [weakSelf.navigationController pushViewController:vc animated:YES]; }else{ NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.addListArray]; 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]; } }]; [self.CusNavBar addSubview:self.titleL]; [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.CusNavBar); make.centerY.mas_equalTo(backBtn); make.height.offset(44); make.width.mas_greaterThanOrEqualTo(10); }]; if (self.titleStr.length == 0) { self.titleL.attributedText = [self stringToAttribuedString:@"小组"]; }else{ self.titleL.attributedText = [self stringToAttribuedString:self.titleStr]; } [self.view addSubview:self.HeadView]; [self.HeadView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.view); make.height.mas_offset(46); make.top.mas_equalTo(self.CusNavBar.mas_bottom); }]; [self.HeadView addSubview:self.SearchView]; [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_offset(6); make.left.right.mas_equalTo(self.HeadView); make.height.mas_offset(36); }]; [self.SearchView.button setAction:^{ TDGroupSearchResultVC *vc = [[TDGroupSearchResultVC alloc] init]; vc.ParentId = weakSelf.ParentId; vc.isReturn = weakSelf.isReturn; vc.isSelect = weakSelf.isSelect; vc.sendModel = weakSelf.sendModel; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; [self.view addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.HeadView.mas_bottom); make.left.right.mas_equalTo(self.view); if (@available(iOS 11.0, *)) { make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom); } else { make.bottom.equalTo(self.view.mas_bottom); } }]; self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; [self addSortV]; } -(NSMutableArray *)getMenuDataSource:(NSArray *)titleArray{ NSMutableArray *menuDataSourceArray = [[NSMutableArray alloc] init]; for(int i=0;i*)findModelArray{ NSMutableArray *MiddleIds = [NSMutableArray array]; for (NoticeModel *model in findModelArray) { [MiddleIds addObject:@(model.Id)]; } NSMutableDictionary *dic = [[NSMutableDictionary alloc]init]; [dic setValue:MiddleIds forKey:@"MiddleIds"]; [dic setValue:@(CreateGroupType) forKey:@"FolderType"]; SHOWLOADING WEAKSELF [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_DeleteRecord) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) { STRONGSELF REMOVESHOW [strongSelf headRefresh]; } failure:^(NSError * _Nonnull error) { SHOWERROR([ZYCTool handerResultData:error]); }]; } /// 移动文件夹 - (void)moveFind:(NSMutableArray*)findModelArray withSuperModel:(NoticeModel *)supermodel{ NSMutableArray *MiddleIds = [NSMutableArray array]; for (NoticeModel *model in findModelArray) { [MiddleIds addObject:@(model.Id)]; } NSMutableDictionary *dic = [[NSMutableDictionary alloc]init]; [dic setValue:MiddleIds forKey:@"Ids"]; [dic setValue:@(self.ParentId) forKey:@"ParentId"]; SHOWLOADING WEAKSELF [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_Move) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) { STRONGSELF REMOVESHOW [strongSelf headRefresh]; } failure:^(NSError * _Nonnull error) { SHOWERROR([ZYCTool handerResultData:error]); }]; } -(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:UIControlStateNormal]; self.rightMoveBtn.enabled = NO; self.rightMoveBtn.titleLabel.font = [UIFont systemFontOfSize:15]; [self.operationBottomBgView addSubview:self.rightMoveBtn]; self.rightMoveBtn.frame = CGRectMake(0, 10, SCREEN_WIDTH, 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 (NoticeModel * model in weakSelf.dataArray) { if (model.IsSelect) { [selectIDArray addObject:model]; } } if (selectIDArray.count == 0) { SHOWERROR(@"请选择要删除的通知"); return ; }else{ [weakSelf deleteFind:selectIDArray]; } }]; self.leftCloseBtn.hidden = YES; [self.rightMoveBtn setAction:^{ NSMutableArray *selectIDArray = [NSMutableArray array]; for (NoticeModel * model in weakSelf.dataArray) { if (model.IsSelect) { [selectIDArray addObject:@(model.Id)]; } } if (selectIDArray.count == 0) { SHOWERROR(@"请选择要移动的通知或者文件夹"); return ; } [weakSelf launchMoveVC:selectIDArray]; }]; [[UtilsTools getWindow] addSubview:self.operationBottomBgView]; } - (void)launchMoveVC:(NSMutableArray*)selectIDArray{ MoveViewController * vc = [MoveViewController initMoveViewController]; vc.TypeId = CreateGroupType; vc.CollectionType = CollectModel_Group; vc.collectType = CollectHanderType_Move; vc.ParentId = 0; vc.titleStr = self.titleL.text; vc.FolderIds = 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.titleL.attributedText = [self stringToAttribuedString:@"批量编辑"]; self.iSViewEditor = YES; [self.HeadView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_offset(36); }]; self.SortView.hidden = NO; self.SearchView.hidden = YES; self.addBtn.hidden = YES; //默认操作状态为批量编辑状态 self.operationStateEnum = OperationStateEnum1; // self.operationBackButton.hidden = NO; // self.operationAllSelectButton.hidden = NO; // [self.operationAllSelectButton setTitle:@"全选" forState:UIControlStateNormal]; // [self.operationAllSelectButton setTitleColor:UIColorHex(#0F88EB) forState:UIControlStateNormal]; // [self.operationAllSelectButton setImage:nil forState:UIControlStateNormal]; 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]; [self.tableView setEditing:YES]; self.tableView.allowsSelectionDuringEditing = YES; }else{ [self.tableView setEditing:NO]; if (self.titleStr.length == 0) { self.titleL.attributedText = [self stringToAttribuedString:@"我的小组"]; }else{ self.titleL.attributedText = [self stringToAttribuedString:self.titleStr]; } self.addBtn.hidden = NO; self.iSViewEditor = NO; [self.HeadView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_offset(46); }]; self.SortView.hidden = YES; self.SearchView.hidden = NO; //默认操作状态为无状态 self.operationStateEnum = OperationStateEnum0; // self.operationAllSelectButton.hidden = NO; // [self.operationAllSelectButton setImage:IMG(@"menu_black_icon") forState:UIControlStateNormal]; // [self.operationAllSelectButton setTitleColor:[UIColor clearColor] forState:UIControlStateNormal]; 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 setImage:[UIImage imageNamed:@"chatmsg_right_add_icon"] forState:UIControlStateNormal]; [self.addBtn setAction:^{ NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.addListArray]; 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]; }]; }else{ [self.addBtn setImage:[UIImage imageNamed:@"chatmsg_right_fileadd_icon"] forState:UIControlStateNormal]; [self.addBtn setAction:^{ [ShowtipTool showErrorWithStatus:@"未做"]; }]; } } - (void)backAction:(id)sender{ if (self.iSViewEditor) { [self changeToOperation:NO]; }else{ [self.navigationController popViewControllerAnimated:true]; } } - (void)back1 { if (self.isSelect) { for (NSInteger i = (self.navigationController.viewControllers.count - 1); i >= 0; i --) { UIViewController *vc = self.navigationController.viewControllers[i]; if ([vc isKindOfClass:NSClassFromString(@"MyTDTopicCreateVC")]) { [self.navigationController popToViewController:vc animated:YES]; return; } } }else{ [self.navigationController popViewControllerAnimated:YES]; } } - (BOOL)checkChatListArray { for (NoticeModel * model in self.dataArray) { if (!model.IsSelect) { return NO; } } return YES; } - (NSInteger)CountSelectArray { NSInteger count = 0; for (NoticeModel * model in self.dataArray) { if (model.IsSelect) { count ++; } } return count; } - (void)menuAction:(id)sender{ [super menuAction:sender]; [self changeToOperation:NO]; } #pragma mark - setter - (TDTableView *)tableView{ if (!_tableView) { _tableView = [[TDTableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; _tableView.delegate = self; _tableView.dataSource = self; } return _tableView; } - (NSMutableArray *)dataArray{ if (!_dataArray) { _dataArray = [NSMutableArray new]; } return _dataArray; } - (MyTDGroupView *)SearchView { if (!_SearchView) { _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)]; } return _SearchView; } #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); NoticeModel *model = [self.dataArray objectAtIndex:indexPath.row]; switch (model.AttributeValue) { case 2:{ 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].mutableCopy]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; action1.backgroundColor = RGB(255, 59, 47); UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"重命名" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) { [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"修改文件夹名称" changeStr:model.FolderName confirm:^(NSString * _Nonnull groupName) { NSLog(@"%@",groupName); [weakSelf reNameFind:model withReNameString:groupName]; } cancle:^{ }] show]; }]; action2.backgroundColor = RGB(255, 149, 3); UIContextualAction *action3 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:model.IsTop?@"取消置顶" :@"置顶" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) { [weakSelf topFind:model]; }]; action3.backgroundColor = RGB(197, 201, 204); UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1, action2, action3]]; actions.performsFirstActionWithFullSwipe = NO; return actions; }break; default:{ UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"退出" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) { [weakSelf deleteFind:@[model].mutableCopy]; }]; action1.backgroundColor = RGB(255, 59, 47); UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"移动" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) { [weakSelf launchMoveVC:@[@(model.Id)].mutableCopy]; }]; action2.backgroundColor = UIColorHex(#589AF1); UIContextualAction *action3 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:model.IsTop ?@"取消置顶" :@"置顶" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) { [weakSelf topFind:model]; }]; action3.backgroundColor = RGB(197, 201, 204); UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1, action2, action3]]; actions.performsFirstActionWithFullSwipe = NO; return actions; } break; } } #else - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { NoticeModel *model = [self.dataArray objectAtIndex:indexPath.row]; WEAKSELF switch (model.AttributeValue) { case 2:{ UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) { [weakSelf deleteFind:@[model].mutableCopy]; }]; action1.backgroundColor = RGB(255, 59, 47); UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"重命名" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) { [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"修改文件夹名称" changeStr:model.FolderName confirm:^(NSString * _Nonnull groupName) { NSLog(@"%@",groupName); [weakSelf reNameFind:model withReNameString:groupName]; } cancle:^{ }] show]; }]; action2.backgroundColor = RGB(255, 149, 3); // NSLog(@"") UITableViewRowAction *action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title: model.IsTop?@"取消置顶" :@"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) { [weakSelf topFind:model]; }]; action3.backgroundColor = RGB(197, 201, 204); return @[action1, action2, action3]; }break; default:{ UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"退出" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) { [weakSelf deleteFind:@[model].mutableCopy]; }]; action1.backgroundColor = RGB(255, 59, 47); UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"移动" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) { [weakSelf launchMoveVC:@[@(model.Id)].mutableCopy]; }]; action2.backgroundColor = UIColorHex(#589AF1); UITableViewRowAction *action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:model.IsTop ?@"取消置顶" :@"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) { [weakSelf topFind:model]; }]; action3.backgroundColor = RGB(197, 201, 204); return @[action1, action2, action3]; } break; } } #endif #pragma mark - UITableViewDelegate,UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataArray.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return [ChatNewRowCell configCell2Height]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ WS(weakSelf); switch (self.operationStateEnum) { case OperationStateEnum0:{ NoticeModel *model = [self.dataArray objectAtIndex:indexPath.row]; switch (model.AttributeValue) { case 2:{ ChatNewRowCell *cell = [ChatNewRowCell configCell1:tableView indexPath:indexPath]; cell.cell1TitleLabel.text = model.FolderName; cell.IsTopImgV.hidden = !model.IsTop; cell.cell1TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.FileCount]; cell.cell1TimeLabel.hidden = model.FileCount == 0 ? YES : NO; return cell; }break; default:{ ChatNewRowCell *cell = [ChatNewRowCell configCell2:tableView indexPath:indexPath]; [cell.cell2UserImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage]; cell.cell2TitleLabel.text = model.GroupName; cell.IsTopImgV.hidden = !model.IsTop; cell.cell2IntroLabel.text = [NSString stringWithFormat:@"共享给%ld人",(long)model.TopicSharingCount]; cell.cell2TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.TopicAllCount]; cell.cell2TimeLabel.hidden = model.TopicAllCount == 0 ? YES : NO; cell.cell2RedNumLabel.text = model.UReadTopicCount > 0 ? [NSString stringWithFormat:@"[%ld条新话题]",(long)model.UReadTopicCount] : @""; return cell; }break; } }break; default:{ NoticeModel *model = [self.dataArray objectAtIndex:indexPath.row]; self.isAllSelect = [self checkChatListArray]; [self isMoveCheckData]; self.selectCountL.text = [NSString stringWithFormat:@"%ld",[self CountSelectArray]]; if (self.isAllSelect) { [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal]; // [self.operationAllSelectButton setTitle:@"取消全选" forState:UIControlStateNormal]; }else{ [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal]; // [self.operationAllSelectButton setTitle:@"全选" forState:UIControlStateNormal]; } switch (model.AttributeValue) { case 2:{///文件 ChatNewRowCell *cell = [ChatNewRowCell configCell10:tableView indexPath:indexPath]; cell.cell1TitleLabel.text = model.FolderName; cell.cell1TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.FileCount]; cell.cell1TimeLabel.hidden = model.FileCount == 0 ? YES : NO; cell.cell1SelectButton.selected = model.IsSelect; cell.IsTopImgV.hidden = !model.IsTop; cell.rightImageView.hidden = YES; cell.isSort = model.IsTop; [cell.cell1SelectButton setAction:^{ model.IsSelect = !model.IsSelect; if (model.IsSelect) { SHOWERROR(@"文件夹不能移动"); } [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; }]; return cell; }break; default:{///小组 ChatNewRowCell *cell = [ChatNewRowCell configCell20:tableView indexPath:indexPath]; [cell.cell2UserImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage]; cell.cell2TitleLabel.text = model.GroupName; cell.cell2IntroLabel.text = [NSString stringWithFormat:@"共享给%ld人",(long)model.TopicSharingCount]; cell.cell2TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.TopicAllCount]; cell.cell2TimeLabel.hidden = model.TopicAllCount == 0 ? YES : NO; cell.cell2RedNumLabel.text = model.UReadTopicCount > 0 ? [NSString stringWithFormat:@"[%ld条新话题]",(long)model.UReadTopicCount] : @""; cell.cell2SelectButton.selected = model.IsSelect; cell.IsTopImgV.hidden = !model.IsTop; [cell.cell2SelectButton setAction:^{ model.IsSelect = !model.IsSelect; [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; }]; cell.isSort = model.IsTop; return cell; }break; } }break; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; switch (self.operationStateEnum) { case OperationStateEnum1:{ NSLog(@"编辑状态的cell"); NoticeModel *model = [self.dataArray objectAtIndex:indexPath.row]; model.IsSelect = !model.IsSelect; if (model.AttributeValue == 2 && model.IsSelect) { SHOWERROR(@"文件夹不能移动"); } [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; }break; default:{ NSLog(@"正常状态的cell"); NoticeModel *model = [self.dataArray objectAtIndex:indexPath.row]; if(model && model != nil) { switch (model.AttributeValue) { case 2:{ MyTDGroupViewController *vc = [[MyTDGroupViewController alloc] init]; vc.ParentId = model.Id; vc.isSubVC = YES; vc.titleStr = model.FolderName; vc.isReturn = self.isReturn; vc.isSelect = self.isSelect; vc.sendImage = self.sendImage; vc.sendModel = self.sendModel; [self.navigationController pushViewController:vc animated:YES]; }break; default:{ if (self.isReturn) { MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC]; vc.FolderId = model.GroupId; vc.type = CollectModel_Toipc; vc.isReturn = self.isReturn; vc.sendImage = self.sendImage; vc.sendModel = self.sendModel; [self.navigationController pushViewController:vc animated:YES]; }else{ if (self.isSelect) { [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_SELECTCREATENOTEFOLDER object:nil userInfo:@{@"FolderId":@(model.GroupId),@"FolderName":model.GroupName}]; [self back1]; }else{ TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC]; vc.titleStr = model.GroupName; vc.GroupId = model.GroupId; vc.type = self.type; vc.isReturn = self.isReturn; vc.sendImage = self.sendImage; vc.sendModel = self.sendModel; [self.navigationController pushViewController:vc animated:YES]; } } }break; } } }break; } } - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { return tableView.editing; } - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { NoticeModel *model = [self.dataArray objectAtIndex:sourceIndexPath.row]; NoticeModel *toModel = [self.dataArray objectAtIndex:destinationIndexPath.row]; WS(weakSelf); if (model.IsTop && toModel.IsTop ) { [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_Sort) parameters:@{@"MiddleIdFirst":@(model.Id),@"MiddleIdSecond":@(toModel.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) { [weakSelf.dataArray removeObject:model]; [weakSelf.dataArray insertObject:model atIndex:destinationIndexPath.row]; dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); } failure:^(NSError * _Nonnull error) { }]; }else{ [weakSelf.dataArray removeObject:model]; [weakSelf.dataArray insertObject:model atIndex:sourceIndexPath.row]; dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); } } - (void)pushListVC { TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC]; vc.titleStr = self.pushDict[@"Name"]; vc.GroupId = [self.pushDict[@"Id"] integerValue]; [self.navigationController pushViewController:vc animated:NO]; } - (void)isMoveCheckData { BOOL flag = NO; BOOL use = NO; for (NoticeModel * model in self.dataArray) { if (model.IsSelect) { if (model.AttributeValue == 2) { flag = YES; }else{ use = YES; } } } if (flag) { [self.rightMoveBtn setTitleColor:UIColorHex(0xBBBBBB) forState:UIControlStateNormal]; self.rightMoveBtn.enabled = NO; }else{ if (!use) { [self.rightMoveBtn setTitleColor:UIColorHex(0xBBBBBB) forState:UIControlStateNormal]; self.rightMoveBtn.enabled = NO; }else{ [self.rightMoveBtn setTitleColor:RGB(57, 121, 211) forState:UIControlStateNormal]; self.rightMoveBtn.enabled = YES; } } } - (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); _SortView.hidden = YES; } return _SortView; } - (void)addSortV { [self.HeadView addSubview:self.SortView]; [self.SortView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_offset(UIEdgeInsetsZero); }]; [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(36, 36)); }]; 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); }]; UILabel * rightL = [UILabel new]; rightL.text = @"长按右侧三横,拖动可进行排序"; rightL.textColor = UIColorHex(0x666666); rightL.font = Kfont(13); [self.SortView addSubview:rightL]; [rightL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.selectCountL.mas_right).offset(12); make.centerY.mas_equalTo(self.SortView); }]; WS(weakSelf); [self.allSelectBtn setAction:^{ for (NoticeModel *model in weakSelf.dataArray) { model.IsSelect = !weakSelf.isAllSelect; if (model.IsSelect && model.AttributeValue == 2) { SHOWERROR(@"文件夹不能移动"); } } dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); }]; } @end