123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914 |
- //
- // 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"
- @interface MyTDGroupViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) TDTableView *tableView;
- @property (nonatomic, strong) UIView *CusNavBar;
- @property (nonatomic, strong) UILabel *titleL;
- @property (nonatomic, strong) UIButton *addBtn;
- @property (nonatomic, strong) NSMutableArray <NoticeModel*>*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 isFresh;
- @property (nonatomic, assign) BOOL isAllSelect;
- @property (nonatomic, assign) Boolean iSViewEditor;
- @end
- @implementation MyTDGroupViewController
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.fd_prefersNavigationBarHidden = YES;
- [self addNavbarView];
- [self initBottomBgView];
- [self changeToOperation:NO];
- self.iSViewEditor = NO;
- if (self.isPush) {
- [self pushListVC];
- }
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self setTableViewRefresh];
- [self headRefresh];
- }
- - (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];
- [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);
- }];
- [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:^{
- 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.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.CusNavBar.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);
- }
- }];
- if (@available(iOS 11.0, *)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- }
- -(NSMutableArray *)getMenuDataSource:(NSArray *)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]){
- ChatNewRowVC * vc = [ChatNewRowVC initChatNewRowVC];
- vc.GroupFolderId = self.ParentId;
- vc.upDateBlock = ^{
- [weakSelf getData];
- };
- [weakSelf.navigationController pushViewController:vc animated:YES];
- }else if ([@"建文件夹" isEqualToString:action.title]){
- [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"建文件夹" placeholder:@"请输入文件夹名称" confirm:^(NSString * _Nonnull groupName) {
- NSLog(@"%@",groupName);
- NSDictionary * paraDict = @{@"FolderName":groupName,
- @"UserId":@([AppUserModel sharedAppUserModel].Id),
- @"ParentId":@(weakSelf.ParentId),
- @"TypeId":@(CreateGroupType)
- };
- [[HttpManager sharedHttpManager] PUTUrl:Host(APP_Middle_Add_Folder) parameters:paraDict success:^(id _Nonnull responseObject) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf headRefresh];
- });
- } failure:^(NSError * _Nonnull error) {
- NSLog(@"%@",error);
- SHOWERROR([ZYCTool handerResultData:error])
- }];
- } cancle:^{
- }] show];
- }
- else if ([@"批量编辑" isEqualToString:action.title]){
- [weakSelf changeToOperation:YES];
- }
-
- }];
- [menuDataSourceArray addObject:actionMenu];
- }
- return menuDataSourceArray;
- }
- - (UIView *)CusNavBar
- {
- if (!_CusNavBar) {
- _CusNavBar = [UIView new];
- _CusNavBar.backgroundColor = [UIColor whiteColor];
- }
- return _CusNavBar;
- }
- - (UILabel *)titleL
- {
- if (!_titleL) {
- _titleL = [UILabel new];
- _titleL.textAlignment = NSTextAlignmentCenter;
- }
- return _titleL;
- }
- - (NSAttributedString *)stringToAttribuedString:(NSString *)title;
- {
- NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 18],NSForegroundColorAttributeName: [UIColor colorWithRed:10/255.0 green:10/255.0 blue:10/255.0 alpha:1.0]}];
- return string;
- }
- - (void)getData{
- WS(weakSelf);
- NSDictionary * paraDict = @{@"GroupFolderId":@(self.ParentId),
- @"UserId":@([AppUserModel sharedAppUserModel].Id),
- @"Key":@"",
- @"Page":@(self.currentPage),
- @"PerPage":@(20),
- @"Sort":@""
- };
- [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Find) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
- NSLog(@"%@",responseObject);
- NoticeListModel *listModel = [[NoticeListModel alloc] initWithDictionary:responseObject error:nil];
- weakSelf.totalRecord = listModel.Total;
- [weakSelf.dataArray addObjectsFromArray:listModel.Items];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- });
- [weakSelf.tableView.mj_header endRefreshing];
- [weakSelf.tableView.mj_footer endRefreshing];
- } failure:^(NSError * _Nonnull error) {
- [weakSelf.tableView.mj_header endRefreshing];
- [weakSelf.tableView.mj_footer endRefreshing];
- }];
- }
- #pragma mark - UItableView刷新
- - (void)setTableViewRefresh{
- WeakSelf(self)
- self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [weakself headRefresh];
- }];
- self.tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
- [weakself footerRefresh];
- }];
- }
- - (void)headRefresh{
- self.isFresh = YES;
- self.currentPage = 1;
- self.totalPage = 1;
- [self.dataArray removeAllObjects];
- [self getData];
- }
- - (void)footerRefresh{
- self.isFresh = NO;
- self.currentPage += 1;
- if (self.totalRecord == self.dataArray.count) {
- self.currentPage --;
- [self.tableView.mj_footer resetNoMoreData];
- return ;
- }
- [self getData];
- }
- #pragma mark - 批量编辑
- /// 创建文件夹
- - (void)addFind:(NSString *)groupname{
- SHOWLOADING
- WEAKSELF
- [[HttpManager sharedHttpManager] PUTUrl:Host(API_NOTICE_ADDFind) parameters:@{@"FolderName":groupname,@"ParentId":@(self.ParentId)} success:^(id _Nonnull responseObject) {
- STRONGSELF
- REMOVESHOW
- [strongSelf getData];
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- /// 修改文件夹名称
- - (void)reNameFind:(NoticeModel*)findModel withReNameString:(NSString *)renameString{
-
- SHOWLOADING
- WEAKSELF
- [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_ReName) parameters:@{@"FolderName":renameString,@"Id":@(findModel.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) {
- STRONGSELF
- REMOVESHOW
- [strongSelf getData];
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- /// 文件夹 置顶 和 取消置顶
- - (void)topFind:(NoticeModel*)findModel{
- NSLog(@"文件夹---%@%@",findModel.IsTop ? @"置顶":@"取消置顶",findModel.FolderName);
- SHOWLOADING
- WEAKSELF
- [[HttpManager sharedHttpManager] PUTUrl:[NSString stringWithFormat:@"%@%@%ld",BaseUrl,API_Find_Top,(long)findModel.Id] parameters:@{} success:^(id _Nonnull responseObject) {
- REMOVESHOW
- [weakSelf reCreateTable];
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }
- - (void)reCreateTable
- {
- self.currentPage = 1;
- self.totalPage = 1;
- [self.dataArray removeAllObjects];
- WS(weakSelf);
- NSDictionary * paraDict = @{@"GroupFolderId":@(self.ParentId),
- @"UserId":@([AppUserModel sharedAppUserModel].Id),
- @"Key":@"",
- @"Page":@(self.currentPage),
- @"PerPage":@(20),
- @"Sort":@""
- };
- [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Find) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
- NSLog(@"%@",responseObject);
- NoticeListModel *listModel = [[NoticeListModel alloc] initWithDictionary:responseObject error:nil];
- weakSelf.totalRecord = listModel.Total;
- [weakSelf.dataArray addObjectsFromArray:listModel.Items];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView removeFromSuperview];
- weakSelf.tableView = nil;
- weakSelf.tableView.delegate = weakSelf;
- weakSelf.tableView.dataSource = weakSelf;
- [weakSelf.view addSubview:self.tableView];
- [weakSelf.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(weakSelf.CusNavBar.mas_bottom);
- make.left.right.mas_equalTo(weakSelf.view);
- if (@available(iOS 11.0, *)) {
- make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom);
- } else {
- make.bottom.equalTo(weakSelf.view.mas_bottom);
- }
- }];
- [weakSelf.tableView.mj_header endRefreshing];
- [weakSelf.tableView.mj_footer endRefreshing];
- [weakSelf.tableView reloadData];
- });
- } failure:^(NSError * _Nonnull error) {
- [weakSelf.tableView.mj_header endRefreshing];
- [weakSelf.tableView.mj_footer endRefreshing];
- }];
- }
- /// 删除文件夹
- - (void)deleteFind:(NSMutableArray<NoticeModel *>*)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<NoticeModel *>*)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: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 (NoticeModel * model in weakSelf.dataArray) {
- if (model.IsSelect) {
- [selectIDArray addObject:model];
- }
- }
- if (selectIDArray.count == 0) {
- SHOWERROR(@"请选择要删除的通知");
- return ;
- }else{
- [weakSelf deleteFind:selectIDArray];
- }
- }];
- [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<NSNumber*>*)selectIDArray{
- MoveViewController * vc = [MoveViewController initMoveViewController];
- vc.TypeId = CreateGroupType;
- 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.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];
- }else{
- 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.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];
- }
- }
- - (BOOL)checkChatListArray
- {
- for (NoticeModel * model in self.dataArray) {
- if (!model.IsSelect) {
- return NO;
- }
- }
- return YES;
- }
- - (void)menuAction:(id)sender{
- switch (self.operationStateEnum) {
- case OperationStateEnum1:
- for (NoticeModel *model in self.dataArray) {
- model.IsSelect = !self.isAllSelect;
- }
- [self.tableView reloadData];
- break;
- default:
- [super menuAction:sender];
- break;
- }
- }
- #pragma mark - setter
- - (TDTableView *)tableView{
- if (!_tableView) {
- _tableView = [[TDTableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- }
- return _tableView;
- }
- - (NSMutableArray<NoticeModel *> *)dataArray{
- if (!_dataArray) {
- _dataArray = [NSMutableArray new];
- }
- return _dataArray;
- }
- #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];
- if (indexPath.section > 0) {
- 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{
- UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[]];
- actions.performsFirstActionWithFullSwipe = NO;
- return actions;
- }
- }
- #else
- - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
- NoticeModel *model = [self.dataArray objectAtIndex:indexPath.row];
- WEAKSELF
- if (indexPath.section > 0) {
- 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;
- }
- }else{
- return @[];
- }
- }
- #endif
- #pragma mark - UITableViewDelegate,UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 2;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- if (section == 0) {
- return 1;
- }else{
- return self.dataArray.count;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- if (indexPath.section == 0) {
- return [ChatNewRowCell configCell0Height];
- }else{
- return [ChatNewRowCell configCell2Height];
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- WS(weakSelf);
- if (indexPath.section == 0) {
- ChatNewRowCell *cell = [ChatNewRowCell configCell0:tableView indexPath:indexPath];
- WS(weakSelf);
- [cell.cell0SearchBtn setAction:^{
- TDGroupSearchResultVC *vc = [[TDGroupSearchResultVC alloc] init];
- vc.ParentId = weakSelf.ParentId;
- [weakSelf.navigationController pushViewController:vc animated:YES];
- }];
- return cell;
- }
- else{
- 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];
- if (self.isAllSelect) {
- [self.operationAllSelectButton setTitle:@"取消全选" forState:UIControlStateNormal];
- }else{
- [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.cell1SelectButton setAction:^{
- model.IsSelect = !model.IsSelect;
- [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 = @"用户名";
- 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.cell2SelectButton setAction:^{
- model.IsSelect = !model.IsSelect;
- [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
- }];
- return cell;
- }break;
- }
- }break;
- }
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
- {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- switch (self.operationStateEnum) {
- case OperationStateEnum1:{
- NSLog(@"编辑状态的cell");
- self.dataArray[indexPath.row].IsSelect = !self.dataArray[indexPath.row].IsSelect;
- [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
- self.rightMoveBtn.enabled = [self isMoveCheckData];
- }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;
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- default:{
- if (self.isReturn) {
- MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
- vc.Id = model.GroupId;
- vc.type = self.type == 0 ? CollectModel_Group : self.type;
- vc.isReturn = self.isReturn;
- vc.sendModel = self.sendModel;
- [self.navigationController pushViewController:vc animated:YES];
- }else{
- TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
- vc.titleStr = model.GroupName;
- vc.GroupId = model.GroupId;
- vc.type = self.type;
- vc.sendModel = self.sendModel;
- [self.navigationController pushViewController:vc animated:YES];
- }
- }break;
- }
- }
- }break;
- }
- }
- - (void)pushListVC
- {
- TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
- vc.titleStr = self.pushDict[@"Name"];
- vc.GroupId = [self.pushDict[@"Id"] integerValue];
- [self.navigationController pushViewController:vc animated:NO];
- }
- - (BOOL)isMoveCheckData
- {
- BOOL isSelect = NO;
- for (NoticeModel * model in self.dataArray) {
- if (model.AttributeValue == 2 && model.IsSelect) {
- return NO;
- }
- if (model.IsSelect) {
- isSelect = YES;
- }
- }
- if (!isSelect) {
- return NO;
- }
- return YES;
- }
- @end
|