MyTDGroupViewController.m 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. //
  2. // MyTDGroupViewController.m
  3. // smartRhino
  4. //
  5. // Created by tederen on 2019/10/31.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "MyTDGroupViewController.h"
  9. #import "YCMenuView.h"
  10. #import "ShowNewGroupAlert.h"
  11. #import "NoticeListModel.h"
  12. #import "ChatNewRowVC.h"
  13. #import "ChatNewRowCell.h"
  14. #import "MoveViewController.h"
  15. #import "TDGroupSearchResultVC.h"
  16. #import "TDGroupInfoListVC.h"
  17. @interface MyTDGroupViewController ()<UITableViewDelegate,UITableViewDataSource>
  18. @property (nonatomic, strong) TDTableView *tableView;
  19. @property (nonatomic, strong) UIView *CusNavBar;
  20. @property (nonatomic, strong) UILabel *titleL;
  21. @property (nonatomic, strong) UIButton *addBtn;
  22. @property (nonatomic, strong) NSMutableArray <NoticeModel*>*dataArray;
  23. @property (nonatomic, copy) NSArray *addListArray;
  24. @property (assign,nonatomic) OperationStateEnum operationStateEnum;
  25. @property (strong,nonatomic) UIView *operationBottomBgView;
  26. @property (strong, nonatomic) UIButton *operationAllSelectButton;
  27. @property (nonatomic, strong) UIButton *leftCloseBtn;
  28. @property (nonatomic, strong) UIButton *rightMoveBtn;
  29. @property (nonatomic, assign) NSUInteger currentPage;
  30. @property (nonatomic, assign) NSUInteger totalPage;
  31. @property (nonatomic, assign) NSUInteger totalRecord;
  32. @property (nonatomic, assign) BOOL isFresh;
  33. @property (nonatomic, assign) BOOL isAllSelect;
  34. @property (nonatomic, assign) Boolean iSViewEditor;
  35. @end
  36. @implementation MyTDGroupViewController
  37. - (void)viewWillDisappear:(BOOL)animated
  38. {
  39. [super viewWillDisappear:animated];
  40. }
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. self.fd_prefersNavigationBarHidden = YES;
  44. [self addNavbarView];
  45. [self initBottomBgView];
  46. [self changeToOperation:NO];
  47. self.iSViewEditor = NO;
  48. if (self.isPush) {
  49. [self pushListVC];
  50. }
  51. }
  52. - (void)viewWillAppear:(BOOL)animated{
  53. [super viewWillAppear:animated];
  54. [self setTableViewRefresh];
  55. [self headRefresh];
  56. }
  57. - (void)addNavbarView
  58. {
  59. if (self.isSubVC) {
  60. self.addListArray = @[@"新建小组",@"批量编辑"];
  61. }else{
  62. self.addListArray = @[@"新建小组",@"建文件夹",@"批量编辑"];
  63. }
  64. [self.view addSubview:self.CusNavBar];
  65. [self.CusNavBar mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.top.left.right.mas_equalTo(self.view);
  67. make.height.mas_offset(kNavigationHeight);
  68. }];
  69. UILabel * lineL = [UILabel new];
  70. lineL.backgroundColor = LINEBGCOLOR;
  71. [self.CusNavBar addSubview:lineL];
  72. [lineL mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.bottom.right.mas_equalTo(self.CusNavBar);
  74. make.height.offset(0.5);
  75. }];
  76. UIButton * backBtn = [UIButton new];
  77. [backBtn setImage:[UIImage imageNamed:@"back_black_icon"] forState:UIControlStateNormal];
  78. [self.CusNavBar addSubview:backBtn];
  79. self.operationAllSelectButton = [UIButton new];
  80. [self.operationAllSelectButton setImage:[UIImage imageNamed:@"menu_black_icon"] forState:UIControlStateNormal];
  81. [self.CusNavBar addSubview:self.operationAllSelectButton];
  82. self.addBtn = [UIButton new];
  83. [self.addBtn setImage:[UIImage imageNamed:@"chatmsg_right_add_icon"] forState:UIControlStateNormal];
  84. [self.CusNavBar addSubview:self.addBtn];
  85. [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.left.mas_equalTo(self.CusNavBar);
  87. make.bottom.mas_equalTo(self.CusNavBar);
  88. make.width.offset(50);
  89. make.height.offset(44);
  90. }];
  91. [self.operationAllSelectButton mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.left.mas_equalTo(backBtn.mas_right);
  93. make.width.mas_greaterThanOrEqualTo(@35);
  94. make.height.offset(44);
  95. make.bottom.mas_equalTo(self.CusNavBar);
  96. }];
  97. [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.right.mas_equalTo(self.CusNavBar);
  99. make.bottom.mas_equalTo(self.CusNavBar);
  100. make.width.offset(50);
  101. make.height.offset(44);
  102. }];
  103. [backBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
  104. [self.operationAllSelectButton addTarget:self action:@selector(menuAction:) forControlEvents:UIControlEventTouchUpInside];
  105. WS(weakSelf);
  106. [self.addBtn setAction:^{
  107. NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.addListArray];
  108. YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:106 relyonView:weakSelf.addBtn];
  109. view.menuColor = RGB(255, 255, 255);
  110. view.separatorColor = RGB(234, 234, 234);
  111. view.textColor = RGB(102, 102, 102);
  112. view.textFont = [UIFont systemFontOfSize:16.0];
  113. view.menuCellHeight = 43.5;
  114. view.maxDisplayCount = 10;
  115. view.offset = -6;
  116. [view show];
  117. }];
  118. [self.CusNavBar addSubview:self.titleL];
  119. [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  120. make.centerX.mas_equalTo(self.CusNavBar);
  121. make.centerY.mas_equalTo(backBtn);
  122. make.height.offset(44);
  123. make.width.mas_greaterThanOrEqualTo(10);
  124. }];
  125. if (self.titleStr.length == 0) {
  126. self.titleL.attributedText = [self stringToAttribuedString:@"小组"];
  127. }else{
  128. self.titleL.attributedText = [self stringToAttribuedString:self.titleStr];
  129. }
  130. [self.view addSubview:self.tableView];
  131. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.top.mas_equalTo(self.CusNavBar.mas_bottom);
  133. make.left.right.mas_equalTo(self.view);
  134. if (@available(iOS 11.0, *)) {
  135. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  136. } else {
  137. make.bottom.equalTo(self.view.mas_bottom);
  138. }
  139. }];
  140. if (@available(iOS 11.0, *)) {
  141. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  142. } else {
  143. self.automaticallyAdjustsScrollViewInsets = NO;
  144. }
  145. }
  146. -(NSMutableArray *)getMenuDataSource:(NSArray *)titleArray{
  147. NSMutableArray *menuDataSourceArray = [[NSMutableArray alloc] init];
  148. for(int i=0;i<titleArray.count;i++){
  149. NSString *titleStr = [titleArray objectAtIndex:i];
  150. WS(weakSelf);
  151. YCMenuAction *actionMenu = [YCMenuAction actionWithTitle:titleStr image:nil handler:^(YCMenuAction *action) {
  152. if([@"新建小组" isEqualToString:action.title]){
  153. ChatNewRowVC * vc = [ChatNewRowVC initChatNewRowVC];
  154. vc.GroupFolderId = self.ParentId;
  155. vc.upDateBlock = ^{
  156. [weakSelf getData];
  157. };
  158. [weakSelf.navigationController pushViewController:vc animated:YES];
  159. }else if ([@"建文件夹" isEqualToString:action.title]){
  160. [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"建文件夹" placeholder:@"请输入文件夹名称" confirm:^(NSString * _Nonnull groupName) {
  161. NSLog(@"%@",groupName);
  162. NSDictionary * paraDict = @{@"FolderName":groupName,
  163. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  164. @"ParentId":@(weakSelf.ParentId),
  165. @"TypeId":@(CreateGroupType)
  166. };
  167. [[HttpManager sharedHttpManager] PUTUrl:Host(APP_Middle_Add_Folder) parameters:paraDict success:^(id _Nonnull responseObject) {
  168. dispatch_async(dispatch_get_main_queue(), ^{
  169. [weakSelf headRefresh];
  170. });
  171. } failure:^(NSError * _Nonnull error) {
  172. NSLog(@"%@",error);
  173. SHOWERROR([ZYCTool handerResultData:error])
  174. }];
  175. } cancle:^{
  176. }] show];
  177. }
  178. else if ([@"批量编辑" isEqualToString:action.title]){
  179. [weakSelf changeToOperation:YES];
  180. }
  181. }];
  182. [menuDataSourceArray addObject:actionMenu];
  183. }
  184. return menuDataSourceArray;
  185. }
  186. - (UIView *)CusNavBar
  187. {
  188. if (!_CusNavBar) {
  189. _CusNavBar = [UIView new];
  190. _CusNavBar.backgroundColor = [UIColor whiteColor];
  191. }
  192. return _CusNavBar;
  193. }
  194. - (UILabel *)titleL
  195. {
  196. if (!_titleL) {
  197. _titleL = [UILabel new];
  198. _titleL.textAlignment = NSTextAlignmentCenter;
  199. }
  200. return _titleL;
  201. }
  202. - (NSAttributedString *)stringToAttribuedString:(NSString *)title;
  203. {
  204. 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]}];
  205. return string;
  206. }
  207. - (void)getData{
  208. WS(weakSelf);
  209. NSDictionary * paraDict = @{@"GroupFolderId":@(self.ParentId),
  210. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  211. @"Key":@"",
  212. @"Page":@(self.currentPage),
  213. @"PerPage":@(20),
  214. @"Sort":@""
  215. };
  216. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Find) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  217. NSLog(@"%@",responseObject);
  218. NoticeListModel *listModel = [[NoticeListModel alloc] initWithDictionary:responseObject error:nil];
  219. weakSelf.totalRecord = listModel.Total;
  220. [weakSelf.dataArray addObjectsFromArray:listModel.Items];
  221. dispatch_async(dispatch_get_main_queue(), ^{
  222. [weakSelf.tableView reloadData];
  223. });
  224. [weakSelf.tableView.mj_header endRefreshing];
  225. [weakSelf.tableView.mj_footer endRefreshing];
  226. } failure:^(NSError * _Nonnull error) {
  227. [weakSelf.tableView.mj_header endRefreshing];
  228. [weakSelf.tableView.mj_footer endRefreshing];
  229. }];
  230. }
  231. #pragma mark - UItableView刷新
  232. - (void)setTableViewRefresh{
  233. WeakSelf(self)
  234. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  235. [weakself headRefresh];
  236. }];
  237. self.tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
  238. [weakself footerRefresh];
  239. }];
  240. }
  241. - (void)headRefresh{
  242. self.isFresh = YES;
  243. self.currentPage = 1;
  244. self.totalPage = 1;
  245. [self.dataArray removeAllObjects];
  246. [self getData];
  247. }
  248. - (void)footerRefresh{
  249. self.isFresh = NO;
  250. self.currentPage += 1;
  251. if (self.totalRecord == self.dataArray.count) {
  252. self.currentPage --;
  253. [self.tableView.mj_footer resetNoMoreData];
  254. return ;
  255. }
  256. [self getData];
  257. }
  258. #pragma mark - 批量编辑
  259. /// 创建文件夹
  260. - (void)addFind:(NSString *)groupname{
  261. SHOWLOADING
  262. WEAKSELF
  263. [[HttpManager sharedHttpManager] PUTUrl:Host(API_NOTICE_ADDFind) parameters:@{@"FolderName":groupname,@"ParentId":@(self.ParentId)} success:^(id _Nonnull responseObject) {
  264. STRONGSELF
  265. REMOVESHOW
  266. [strongSelf getData];
  267. } failure:^(NSError * _Nonnull error) {
  268. SHOWERROR([ZYCTool handerResultData:error]);
  269. }];
  270. }
  271. /// 修改文件夹名称
  272. - (void)reNameFind:(NoticeModel*)findModel withReNameString:(NSString *)renameString{
  273. SHOWLOADING
  274. WEAKSELF
  275. [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_ReName) parameters:@{@"FolderName":renameString,@"Id":@(findModel.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) {
  276. STRONGSELF
  277. REMOVESHOW
  278. [strongSelf getData];
  279. } failure:^(NSError * _Nonnull error) {
  280. SHOWERROR([ZYCTool handerResultData:error]);
  281. }];
  282. }
  283. /// 文件夹 置顶 和 取消置顶
  284. - (void)topFind:(NoticeModel*)findModel{
  285. NSLog(@"文件夹---%@%@",findModel.IsTop ? @"置顶":@"取消置顶",findModel.FolderName);
  286. SHOWLOADING
  287. WEAKSELF
  288. [[HttpManager sharedHttpManager] PUTUrl:[NSString stringWithFormat:@"%@%@%ld",BaseUrl,API_Find_Top,(long)findModel.Id] parameters:@{} success:^(id _Nonnull responseObject) {
  289. REMOVESHOW
  290. [weakSelf reCreateTable];
  291. } failure:^(NSError * _Nonnull error) {
  292. SHOWERROR([ZYCTool handerResultData:error]);
  293. }];
  294. }
  295. - (void)reCreateTable
  296. {
  297. self.currentPage = 1;
  298. self.totalPage = 1;
  299. [self.dataArray removeAllObjects];
  300. WS(weakSelf);
  301. NSDictionary * paraDict = @{@"GroupFolderId":@(self.ParentId),
  302. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  303. @"Key":@"",
  304. @"Page":@(self.currentPage),
  305. @"PerPage":@(20),
  306. @"Sort":@""
  307. };
  308. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Find) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  309. NSLog(@"%@",responseObject);
  310. NoticeListModel *listModel = [[NoticeListModel alloc] initWithDictionary:responseObject error:nil];
  311. weakSelf.totalRecord = listModel.Total;
  312. [weakSelf.dataArray addObjectsFromArray:listModel.Items];
  313. dispatch_async(dispatch_get_main_queue(), ^{
  314. [weakSelf.tableView removeFromSuperview];
  315. weakSelf.tableView = nil;
  316. weakSelf.tableView.delegate = weakSelf;
  317. weakSelf.tableView.dataSource = weakSelf;
  318. [weakSelf.view addSubview:self.tableView];
  319. [weakSelf.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  320. make.top.mas_equalTo(weakSelf.CusNavBar.mas_bottom);
  321. make.left.right.mas_equalTo(weakSelf.view);
  322. if (@available(iOS 11.0, *)) {
  323. make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom);
  324. } else {
  325. make.bottom.equalTo(weakSelf.view.mas_bottom);
  326. }
  327. }];
  328. [weakSelf.tableView.mj_header endRefreshing];
  329. [weakSelf.tableView.mj_footer endRefreshing];
  330. [weakSelf.tableView reloadData];
  331. });
  332. } failure:^(NSError * _Nonnull error) {
  333. [weakSelf.tableView.mj_header endRefreshing];
  334. [weakSelf.tableView.mj_footer endRefreshing];
  335. }];
  336. }
  337. /// 删除文件夹
  338. - (void)deleteFind:(NSMutableArray<NoticeModel *>*)findModelArray{
  339. NSMutableArray *MiddleIds = [NSMutableArray array];
  340. for (NoticeModel *model in findModelArray) {
  341. [MiddleIds addObject:@(model.Id)];
  342. }
  343. NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
  344. [dic setValue:MiddleIds forKey:@"MiddleIds"];
  345. [dic setValue:@(CreateGroupType) forKey:@"FolderType"];
  346. SHOWLOADING
  347. WEAKSELF
  348. [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_DeleteRecord) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) {
  349. STRONGSELF
  350. REMOVESHOW
  351. [strongSelf headRefresh];
  352. } failure:^(NSError * _Nonnull error) {
  353. SHOWERROR([ZYCTool handerResultData:error]);
  354. }];
  355. }
  356. /// 移动文件夹
  357. - (void)moveFind:(NSMutableArray<NoticeModel *>*)findModelArray withSuperModel:(NoticeModel *)supermodel{
  358. NSMutableArray *MiddleIds = [NSMutableArray array];
  359. for (NoticeModel *model in findModelArray) {
  360. [MiddleIds addObject:@(model.Id)];
  361. }
  362. NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
  363. [dic setValue:MiddleIds forKey:@"Ids"];
  364. [dic setValue:@(self.ParentId) forKey:@"ParentId"];
  365. SHOWLOADING
  366. WEAKSELF
  367. [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_Move) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) {
  368. STRONGSELF
  369. REMOVESHOW
  370. [strongSelf headRefresh];
  371. } failure:^(NSError * _Nonnull error) {
  372. SHOWERROR([ZYCTool handerResultData:error]);
  373. }];
  374. }
  375. -(void)initBottomBgView{
  376. self.leftCloseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  377. [self.leftCloseBtn setTitle:@"删除" forState:UIControlStateNormal];
  378. [self.leftCloseBtn setTitleColor:RGB(255, 82, 82) forState:UIControlStateNormal];
  379. self.leftCloseBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  380. [self.operationBottomBgView addSubview:self.leftCloseBtn];
  381. self.leftCloseBtn.frame = CGRectMake(0, 10, SCREEN_WIDTH/2, self.operationBottomBgView.height - 10);
  382. self.self.rightMoveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  383. [self.rightMoveBtn setTitle:@"移动" forState:UIControlStateNormal];
  384. [self.rightMoveBtn setTitleColor:RGB(57, 121, 211) forState:UIControlStateNormal];
  385. [self.rightMoveBtn setTitleColor:UIColorHex(#BBBBBB) forState:UIControlStateDisabled];
  386. self.rightMoveBtn.enabled = NO;
  387. self.rightMoveBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  388. [self.operationBottomBgView addSubview:self.rightMoveBtn];
  389. self.rightMoveBtn.frame = CGRectMake(SCREEN_WIDTH/2, 10, SCREEN_WIDTH/2, self.operationBottomBgView.height - 10);
  390. UIView *line = [[UIView alloc] init];
  391. line.backgroundColor = RGB(240, 239, 244);
  392. [self.operationBottomBgView addSubview:line];
  393. line.frame = CGRectMake(SCREEN_WIDTH/2, 0, .5, self.operationBottomBgView.height);
  394. UIView *topLine = [[UIView alloc] init];
  395. topLine.backgroundColor = RGB(240, 239, 244);
  396. [self.operationBottomBgView addSubview:topLine];
  397. topLine.frame = CGRectMake(0, 0, SCREEN_WIDTH, 10);
  398. WS(weakSelf);
  399. [self.leftCloseBtn setAction:^{
  400. NSMutableArray *selectIDArray = [NSMutableArray array];
  401. for (NoticeModel * model in weakSelf.dataArray) {
  402. if (model.IsSelect) {
  403. [selectIDArray addObject:model];
  404. }
  405. }
  406. if (selectIDArray.count == 0) {
  407. SHOWERROR(@"请选择要删除的通知");
  408. return ;
  409. }else{
  410. [weakSelf deleteFind:selectIDArray];
  411. }
  412. }];
  413. [self.rightMoveBtn setAction:^{
  414. NSMutableArray *selectIDArray = [NSMutableArray array];
  415. for (NoticeModel * model in weakSelf.dataArray) {
  416. if (model.IsSelect) {
  417. [selectIDArray addObject:@(model.Id)];
  418. }
  419. }
  420. if (selectIDArray.count == 0) {
  421. SHOWERROR(@"请选择要移动的通知或者文件夹");
  422. return ;
  423. }
  424. [weakSelf launchMoveVC:selectIDArray];
  425. }];
  426. [[UtilsTools getWindow] addSubview:self.operationBottomBgView];
  427. }
  428. - (void)launchMoveVC:(NSMutableArray<NSNumber*>*)selectIDArray{
  429. MoveViewController * vc = [MoveViewController initMoveViewController];
  430. vc.TypeId = CreateGroupType;
  431. vc.collectType = CollectHanderType_Move;
  432. vc.ParentId = 0;
  433. vc.titleStr = self.titleL.text;
  434. vc.FolderIds = selectIDArray;
  435. [self.navigationController pushViewController:vc animated:YES];
  436. [self changeToOperation:NO];
  437. }
  438. -(UIView *)operationBottomBgView{
  439. if(!_operationBottomBgView){
  440. _operationBottomBgView = [[UIView alloc] init];
  441. CGFloat bottomBgViewH = self.tabBarController.tabBar.height + 10;
  442. _operationBottomBgView.frame = CGRectMake(0, SCREEN_HEIGHT - bottomBgViewH, SCREEN_WIDTH, bottomBgViewH);
  443. _operationBottomBgView.backgroundColor = RGB(255, 255, 255);
  444. _operationBottomBgView.hidden = YES;
  445. }
  446. return _operationBottomBgView;
  447. }
  448. #pragma mark 批量操作与正常操作界面切换
  449. -(void)changeToOperation:(BOOL)operation{
  450. if(operation){
  451. self.titleL.attributedText = [self stringToAttribuedString:@"批量操作"];
  452. self.iSViewEditor = YES;
  453. self.addBtn.hidden = YES;
  454. //默认操作状态为批量编辑状态
  455. self.operationStateEnum = OperationStateEnum1;
  456. // self.operationBackButton.hidden = NO;
  457. self.operationAllSelectButton.hidden = NO;
  458. [self.operationAllSelectButton setTitle:@"全选" forState:UIControlStateNormal];
  459. [self.operationAllSelectButton setTitleColor:UIColorHex(#0F88EB) forState:UIControlStateNormal];
  460. [self.operationAllSelectButton setImage:nil forState:UIControlStateNormal];
  461. self.tabBarController.tabBar.hidden = YES;
  462. self.operationBottomBgView.hidden = NO;
  463. self.view.height -= self.tabBarController.tabBar.height;
  464. self.tableView.height -= self.tabBarController.tabBar.height;
  465. [self.view layoutIfNeeded];
  466. [self.tableView layoutIfNeeded];
  467. }else{
  468. if (self.titleStr.length == 0) {
  469. self.titleL.attributedText = [self stringToAttribuedString:@"小组"];
  470. }else{
  471. self.titleL.attributedText = [self stringToAttribuedString:self.titleStr];
  472. }
  473. self.addBtn.hidden = NO;
  474. self.iSViewEditor = NO;
  475. //默认操作状态为无状态
  476. self.operationStateEnum = OperationStateEnum0;
  477. self.operationAllSelectButton.hidden = NO;
  478. [self.operationAllSelectButton setImage:IMG(@"menu_black_icon") forState:UIControlStateNormal];
  479. [self.operationAllSelectButton setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
  480. self.tabBarController.tabBar.hidden = YES;
  481. self.tableView.height += self.tabBarController.tabBar.height;
  482. self.view.height += self.tabBarController.tabBar.height;
  483. [self.view layoutIfNeeded];
  484. [self.tableView layoutIfNeeded];
  485. self.operationBottomBgView.hidden = YES;
  486. }
  487. [self.tableView reloadData];
  488. }
  489. #pragma mark 移动 isEdit:当前是否为编辑状态
  490. -(void)userDidMove:(BOOL)move isEdit:(BOOL)isEdit{
  491. //移动
  492. if(move){
  493. //默认操作状态为移动状态
  494. self.operationStateEnum = OperationStateEnum2;
  495. self.addBtn.hidden = NO;
  496. [self resetRightBtnAction:NO];
  497. //隐藏tabBar - 并将TableView至底端
  498. self.tabBarController.tabBar.hidden = YES;
  499. self.view.height += self.tabBarController.tabBar.height;
  500. self.tableView.height += self.tabBarController.tabBar.height;
  501. [self.view layoutIfNeeded];
  502. [self.tableView layoutIfNeeded];
  503. //隐藏operationBottomBgView
  504. self.operationBottomBgView.hidden = YES;
  505. }
  506. else{
  507. //隐藏tabBar - 并将TableView至底端有tabBar.height的高
  508. self.tabBarController.tabBar.hidden = YES;
  509. self.view.height -= self.tabBarController.tabBar.height;
  510. self.tableView.height -= self.tabBarController.tabBar.height;
  511. [self.view layoutIfNeeded];
  512. [self.tableView layoutIfNeeded];
  513. //显示operationBottomBgView
  514. self.operationBottomBgView.hidden = NO;
  515. if(isEdit){
  516. self.operationStateEnum = OperationStateEnum1;
  517. self.addBtn.hidden = YES;
  518. [self resetRightBtnAction:YES];
  519. }else{
  520. [self changeToOperation:NO];
  521. }
  522. }
  523. [self.tableView reloadData];
  524. }
  525. -(void)resetRightBtnAction:(BOOL)isShowMenu{
  526. WS(weakSelf);
  527. if(isShowMenu){
  528. [self.addBtn setImage:[UIImage imageNamed:@"chatmsg_right_add_icon"] forState:UIControlStateNormal];
  529. [self.addBtn setAction:^{
  530. NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.addListArray];
  531. YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:106 relyonView:weakSelf.addBtn];
  532. view.menuColor = RGB(255, 255, 255);
  533. view.separatorColor = RGB(234, 234, 234);
  534. view.textColor = RGB(102, 102, 102);
  535. view.textFont = [UIFont systemFontOfSize:16.0];
  536. view.menuCellHeight = 43.5;
  537. view.maxDisplayCount = 10;
  538. view.offset = -6;
  539. [view show];
  540. }];
  541. }else{
  542. [self.addBtn setImage:[UIImage imageNamed:@"chatmsg_right_fileadd_icon"] forState:UIControlStateNormal];
  543. [self.addBtn setAction:^{
  544. [ShowtipTool showErrorWithStatus:@"未做"];
  545. }];
  546. }
  547. }
  548. - (void)backAction:(id)sender{
  549. if (self.iSViewEditor) {
  550. [self changeToOperation:NO];
  551. }else{
  552. [self.navigationController popViewControllerAnimated:true];
  553. }
  554. }
  555. - (BOOL)checkChatListArray
  556. {
  557. for (NoticeModel * model in self.dataArray) {
  558. if (!model.IsSelect) {
  559. return NO;
  560. }
  561. }
  562. return YES;
  563. }
  564. - (void)menuAction:(id)sender{
  565. switch (self.operationStateEnum) {
  566. case OperationStateEnum1:
  567. for (NoticeModel *model in self.dataArray) {
  568. model.IsSelect = !self.isAllSelect;
  569. }
  570. [self.tableView reloadData];
  571. break;
  572. default:
  573. [super menuAction:sender];
  574. break;
  575. }
  576. }
  577. #pragma mark - setter
  578. - (TDTableView *)tableView{
  579. if (!_tableView) {
  580. _tableView = [[TDTableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  581. _tableView.delegate = self;
  582. _tableView.dataSource = self;
  583. }
  584. return _tableView;
  585. }
  586. - (NSMutableArray<NoticeModel *> *)dataArray{
  587. if (!_dataArray) {
  588. _dataArray = [NSMutableArray new];
  589. }
  590. return _dataArray;
  591. }
  592. #pragma Mark 左滑按钮 iOS8以上
  593. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
  594. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){// delete action
  595. WS(weakSelf);
  596. NoticeModel *model = [self.dataArray objectAtIndex:indexPath.row];
  597. if (indexPath.section > 0) {
  598. switch (model.AttributeValue) {
  599. case 2:{
  600. UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  601. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  602. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  603. [weakSelf deleteFind:@[model].mutableCopy];
  604. }];
  605. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  606. }];
  607. [alert addAction:sureAction];
  608. [alert addAction:cancelAction];
  609. [weakSelf presentViewController:alert animated:YES completion:^{
  610. }];
  611. }];
  612. action1.backgroundColor = RGB(255, 59, 47);
  613. UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"重命名" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  614. [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"修改文件夹名称" changeStr:model.FolderName confirm:^(NSString * _Nonnull groupName) {
  615. NSLog(@"%@",groupName);
  616. [weakSelf reNameFind:model withReNameString:groupName];
  617. } cancle:^{
  618. }] show];
  619. }];
  620. action2.backgroundColor = RGB(255, 149, 3);
  621. UIContextualAction *action3 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:model.IsTop?@"取消置顶" :@"置顶" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  622. [weakSelf topFind:model];
  623. }];
  624. action3.backgroundColor = RGB(197, 201, 204);
  625. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1, action2, action3]];
  626. actions.performsFirstActionWithFullSwipe = NO;
  627. return actions;
  628. }break;
  629. default:{
  630. UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"退出" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  631. [weakSelf deleteFind:@[model].mutableCopy];
  632. }];
  633. action1.backgroundColor = RGB(255, 59, 47);
  634. UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"移动" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  635. [weakSelf launchMoveVC:@[@(model.Id)].mutableCopy];
  636. }];
  637. action2.backgroundColor = UIColorHex(#589AF1);
  638. UIContextualAction *action3 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:model.IsTop ?@"取消置顶" :@"置顶" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  639. [weakSelf topFind:model];
  640. }];
  641. action3.backgroundColor = RGB(197, 201, 204);
  642. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1, action2, action3]];
  643. actions.performsFirstActionWithFullSwipe = NO;
  644. return actions;
  645. }
  646. break;
  647. }
  648. }else{
  649. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[]];
  650. actions.performsFirstActionWithFullSwipe = NO;
  651. return actions;
  652. }
  653. }
  654. #else
  655. - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
  656. NoticeModel *model = [self.dataArray objectAtIndex:indexPath.row];
  657. WEAKSELF
  658. if (indexPath.section > 0) {
  659. switch (model.AttributeValue) {
  660. case 2:{
  661. UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  662. [weakSelf deleteFind:@[model].mutableCopy];
  663. }];
  664. action1.backgroundColor = RGB(255, 59, 47);
  665. UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"重命名" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  666. [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"修改文件夹名称" changeStr:model.FolderName confirm:^(NSString * _Nonnull groupName) {
  667. NSLog(@"%@",groupName);
  668. [weakSelf reNameFind:model withReNameString:groupName];
  669. } cancle:^{
  670. }] show];
  671. }];
  672. action2.backgroundColor = RGB(255, 149, 3);
  673. // NSLog(@"")
  674. UITableViewRowAction *action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title: model.IsTop?@"取消置顶" :@"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  675. [weakSelf topFind:model];
  676. }];
  677. action3.backgroundColor = RGB(197, 201, 204);
  678. return @[action1, action2, action3];
  679. }break;
  680. default:{
  681. UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"退出" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  682. [weakSelf deleteFind:@[model].mutableCopy];
  683. }];
  684. action1.backgroundColor = RGB(255, 59, 47);
  685. UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"移动" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  686. [weakSelf launchMoveVC:@[@(model.Id)].mutableCopy];
  687. }];
  688. action2.backgroundColor = UIColorHex(#589AF1);
  689. UITableViewRowAction *action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:model.IsTop ?@"取消置顶" :@"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  690. [weakSelf topFind:model];
  691. }];
  692. action3.backgroundColor = RGB(197, 201, 204);
  693. return @[action1, action2, action3];
  694. }
  695. break;
  696. }
  697. }else{
  698. return @[];
  699. }
  700. }
  701. #endif
  702. #pragma mark - UITableViewDelegate,UITableViewDataSource
  703. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  704. return 2;
  705. }
  706. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  707. if (section == 0) {
  708. return 1;
  709. }else{
  710. return self.dataArray.count;
  711. }
  712. }
  713. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  714. if (indexPath.section == 0) {
  715. return [ChatNewRowCell configCell0Height];
  716. }else{
  717. return [ChatNewRowCell configCell2Height];
  718. }
  719. }
  720. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  721. WS(weakSelf);
  722. if (indexPath.section == 0) {
  723. ChatNewRowCell *cell = [ChatNewRowCell configCell0:tableView indexPath:indexPath];
  724. WS(weakSelf);
  725. [cell.cell0SearchBtn setAction:^{
  726. TDGroupSearchResultVC *vc = [[TDGroupSearchResultVC alloc] init];
  727. vc.ParentId = weakSelf.ParentId;
  728. [weakSelf.navigationController pushViewController:vc animated:YES];
  729. }];
  730. return cell;
  731. }
  732. else{
  733. switch (self.operationStateEnum) {
  734. case OperationStateEnum0:{
  735. NoticeModel *model = [self.dataArray objectAtIndex:indexPath.row];
  736. switch (model.AttributeValue) {
  737. case 2:{
  738. ChatNewRowCell *cell = [ChatNewRowCell configCell1:tableView indexPath:indexPath];
  739. cell.cell1TitleLabel.text = model.FolderName;
  740. cell.IsTopImgV.hidden = !model.IsTop;
  741. cell.cell1TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.FileCount];
  742. cell.cell1TimeLabel.hidden = model.FileCount == 0 ? YES : NO;
  743. return cell;
  744. }break;
  745. default:{
  746. ChatNewRowCell *cell = [ChatNewRowCell configCell2:tableView indexPath:indexPath];
  747. [cell.cell2UserImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  748. cell.cell2TitleLabel.text = model.GroupName;
  749. cell.IsTopImgV.hidden = !model.IsTop;
  750. cell.cell2IntroLabel.text = [NSString stringWithFormat:@"共享给%ld人",(long)model.TopicSharingCount];
  751. cell.cell2TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.TopicAllCount];
  752. cell.cell2TimeLabel.hidden = model.TopicAllCount == 0 ? YES : NO;
  753. cell.cell2RedNumLabel.text = model.UReadTopicCount > 0 ? [NSString stringWithFormat:@"[%ld条新话题]",(long)model.UReadTopicCount] : @"";
  754. return cell;
  755. }break;
  756. }
  757. }break;
  758. default:{
  759. NoticeModel *model = [self.dataArray objectAtIndex:indexPath.row];
  760. self.isAllSelect = [self checkChatListArray];
  761. if (self.isAllSelect) {
  762. [self.operationAllSelectButton setTitle:@"取消全选" forState:UIControlStateNormal];
  763. }else{
  764. [self.operationAllSelectButton setTitle:@"全选" forState:UIControlStateNormal];
  765. }
  766. switch (model.AttributeValue) {
  767. case 2:{///文件
  768. ChatNewRowCell *cell = [ChatNewRowCell configCell10:tableView indexPath:indexPath];
  769. cell.cell1TitleLabel.text = model.FolderName;
  770. cell.cell1TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.FileCount];
  771. cell.cell1TimeLabel.hidden = model.FileCount == 0 ? YES : NO;
  772. cell.cell1SelectButton.selected = model.IsSelect;
  773. [cell.cell1SelectButton setAction:^{
  774. model.IsSelect = !model.IsSelect;
  775. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  776. }];
  777. return cell;
  778. }break;
  779. default:{///小组
  780. ChatNewRowCell *cell = [ChatNewRowCell configCell20:tableView indexPath:indexPath];
  781. [cell.cell2UserImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  782. cell.cell2TitleLabel.text = model.GroupName;
  783. cell.cell2IntroLabel.text = @"用户名";
  784. cell.cell2TimeLabel.text = [NSString stringWithFormat:@"%ld",(long)model.TopicAllCount];
  785. cell.cell2TimeLabel.hidden = model.TopicAllCount == 0 ? YES : NO;
  786. cell.cell2RedNumLabel.text = model.UReadTopicCount > 0 ? [NSString stringWithFormat:@"[%ld条新话题]",(long)model.UReadTopicCount] : @"";
  787. cell.cell2SelectButton.selected = model.IsSelect;
  788. [cell.cell2SelectButton setAction:^{
  789. model.IsSelect = !model.IsSelect;
  790. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  791. }];
  792. return cell;
  793. }break;
  794. }
  795. }break;
  796. }
  797. }
  798. }
  799. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  800. {
  801. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  802. switch (self.operationStateEnum) {
  803. case OperationStateEnum1:{
  804. NSLog(@"编辑状态的cell");
  805. self.dataArray[indexPath.row].IsSelect = !self.dataArray[indexPath.row].IsSelect;
  806. [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  807. self.rightMoveBtn.enabled = [self isMoveCheckData];
  808. }break;
  809. default:{
  810. NSLog(@"正常状态的cell");
  811. NoticeModel *model = [self.dataArray objectAtIndex:indexPath.row];
  812. if(model && model != nil)
  813. {
  814. switch (model.AttributeValue) {
  815. case 2:{
  816. MyTDGroupViewController *vc = [[MyTDGroupViewController alloc] init];
  817. vc.ParentId = model.Id;
  818. vc.isSubVC = YES;
  819. vc.titleStr = model.FolderName;
  820. [self.navigationController pushViewController:vc animated:YES];
  821. }break;
  822. default:{
  823. if (self.isReturn) {
  824. MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
  825. vc.Id = model.GroupId;
  826. vc.type = self.type == 0 ? CollectModel_Group : self.type;
  827. vc.isReturn = self.isReturn;
  828. vc.sendModel = self.sendModel;
  829. [self.navigationController pushViewController:vc animated:YES];
  830. }else{
  831. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  832. vc.titleStr = model.GroupName;
  833. vc.GroupId = model.GroupId;
  834. vc.type = self.type;
  835. vc.sendModel = self.sendModel;
  836. [self.navigationController pushViewController:vc animated:YES];
  837. }
  838. }break;
  839. }
  840. }
  841. }break;
  842. }
  843. }
  844. - (void)pushListVC
  845. {
  846. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  847. vc.titleStr = self.pushDict[@"Name"];
  848. vc.GroupId = [self.pushDict[@"Id"] integerValue];
  849. [self.navigationController pushViewController:vc animated:NO];
  850. }
  851. - (BOOL)isMoveCheckData
  852. {
  853. BOOL isSelect = NO;
  854. for (NoticeModel * model in self.dataArray) {
  855. if (model.AttributeValue == 2 && model.IsSelect) {
  856. return NO;
  857. }
  858. if (model.IsSelect) {
  859. isSelect = YES;
  860. }
  861. }
  862. if (!isSelect) {
  863. return NO;
  864. }
  865. return YES;
  866. }
  867. @end