MyTDTopicGroupManageVC.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. //
  2. // MyTDTopicGroupManageVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2019/12/18.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "MyTDTopicGroupManageVC.h"
  9. #import "TopicGroupManageCell.h"
  10. #import "TopicGroupManageModel.h"
  11. #import "YCMenuView.h"
  12. #import "ShowNewGroupAlert.h"
  13. #import "MyTDTopicGroupUserVC.h"
  14. #import "MyTDGroupView.h"
  15. #import "MyTDTopicGroupSearchVC.h"
  16. @interface MyTDTopicGroupManageVC ()<UITableViewDelegate,UITableViewDataSource>
  17. @property (weak, nonatomic) IBOutlet UIButton *AddBtn;
  18. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  19. @property (weak, nonatomic) IBOutlet UILabel *titleL;
  20. @property (weak, nonatomic) IBOutlet UIView *cusBarV;
  21. @property (weak, nonatomic) IBOutlet UIButton *menuBtn;
  22. @property (weak, nonatomic) IBOutlet UIView *HeadView;
  23. @property (nonatomic, strong) NSMutableArray *dataArray;
  24. @property (nonatomic, strong) NSMutableArray *selectArray;
  25. @property (nonatomic, copy) NSArray *addListArray;
  26. @property (assign,nonatomic) OperationStateEnum operationStateEnum;
  27. @property (strong,nonatomic) UIView *operationBottomBgView;
  28. @property (weak, nonatomic) IBOutlet UIButton *operationAllSelectButton;
  29. @property (strong, nonatomic) MyTDGroupView *SearchView;
  30. @property (nonatomic, strong) UIButton *leftCloseBtn;
  31. @property (nonatomic, strong) UIButton *rightMoveBtn;
  32. @property (nonatomic, assign) BOOL iSViewEditor;
  33. @property (nonatomic, assign) BOOL isAllSelect;
  34. @end
  35. @implementation MyTDTopicGroupManageVC
  36. +(MyTDTopicGroupManageVC *)initMyTDTopicGroupManageVC;
  37. {
  38. MyTDTopicGroupManageVC *controller = [StoryboardManager.shared.myTDTopic instantiateViewControllerWithIdentifier:@"MyTDTopicGroupManageVC"];
  39. return controller;
  40. }
  41. - (MyTDGroupView *)SearchView
  42. {
  43. if (!_SearchView) {
  44. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  45. }
  46. return _SearchView;
  47. }
  48. - (void)viewWillAppear:(BOOL)animated
  49. {
  50. [super viewWillAppear:animated];
  51. if (self.iSViewEditor) {
  52. self.operationBottomBgView.hidden = NO;
  53. }else{
  54. self.operationBottomBgView.hidden = YES;
  55. }
  56. [self getData];
  57. }
  58. - (void)viewDidLoad {
  59. [super viewDidLoad];
  60. self.addListArray = @[@"新建分组",@"批量编辑"];
  61. self.tableView.delegate = self;
  62. self.tableView.dataSource = self;
  63. self.iSViewEditor = NO;
  64. self.fd_prefersNavigationBarHidden = YES;
  65. [self initBottomBgView];
  66. [self changeToOperation:NO];
  67. WS(weakSelf);
  68. [self.AddBtn setAction:^{
  69. if (weakSelf.iSViewEditor) {
  70. [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"新建分组" placeholder:@"请输入分组名称" confirm:^(NSString * _Nonnull groupName) {
  71. NSLog(@"%@",groupName);
  72. NSDictionary * paraDict = @{@"Name":groupName,
  73. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  74. @"Id":@(0)
  75. };
  76. [[HttpManager sharedHttpManager] PUTUrl:Host(APP_Topic_Add_Group) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  77. NSLog(@"%@",responseObject);
  78. if ([responseObject[@"Code"] integerValue] == 200) {
  79. [weakSelf pushSubVC:responseObject[@"Data"]];
  80. }else{
  81. SHOWERROR(responseObject[@"Msg"]);
  82. }
  83. } failure:^(NSError * _Nonnull error) {
  84. NSLog(@"%@",error);
  85. SHOWERROR([ZYCTool handerResultData:error])
  86. }];
  87. } cancle:^{
  88. }] show];
  89. }else{
  90. NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.addListArray];
  91. YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:106 relyonView:weakSelf.AddBtn];
  92. view.menuColor = RGB(255, 255, 255);
  93. view.separatorColor = RGB(234, 234, 234);
  94. view.textColor = RGB(102, 102, 102);
  95. view.textFont = [UIFont systemFontOfSize:16.0];
  96. view.menuCellHeight = 43.5;
  97. view.maxDisplayCount = 10;
  98. view.offset = -12;
  99. [view show];
  100. }
  101. }];
  102. [self.operationAllSelectButton setAction:^{
  103. for (TopicGroupManageModel *model in weakSelf.dataArray) {
  104. model.isSelect = !weakSelf.isAllSelect;
  105. }
  106. [weakSelf.tableView reloadData];
  107. }];
  108. self.fd_interactivePopDisabled = YES;
  109. [self.HeadView addSubview:self.SearchView];
  110. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  111. make.top.mas_offset(5);
  112. make.left.right.mas_equalTo(self.HeadView);
  113. make.height.mas_offset(36);
  114. }];
  115. [self.SearchView.button setAction:^{
  116. weakSelf.operationBottomBgView.hidden = YES;
  117. MyTDTopicGroupSearchVC * vc = [[MyTDTopicGroupSearchVC alloc] init];
  118. [weakSelf.navigationController pushViewController:vc animated:YES];
  119. }];
  120. [self.tableView setAllowsSelectionDuringEditing:YES];
  121. }
  122. -(NSMutableArray *)getMenuDataSource:(NSArray *)titleArray{
  123. NSMutableArray *menuDataSourceArray = [[NSMutableArray alloc] init];
  124. for(int i=0;i<titleArray.count;i++){
  125. NSString *titleStr = [titleArray objectAtIndex:i];
  126. WS(weakSelf);
  127. YCMenuAction *actionMenu = [YCMenuAction actionWithTitle:titleStr image:nil handler:^(YCMenuAction *action) {
  128. if([@"新建分组" isEqualToString:action.title]){
  129. [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"新建分组" placeholder:@"请输入分组名称" confirm:^(NSString * _Nonnull groupName) {
  130. NSLog(@"%@",groupName);
  131. NSDictionary * paraDict = @{@"Name":groupName,
  132. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  133. @"Id":@(0)
  134. };
  135. [[HttpManager sharedHttpManager] PUTUrl:Host(APP_Topic_Add_Group) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  136. NSLog(@"%@",responseObject);
  137. if ([responseObject[@"Code"] integerValue] == 200) {
  138. [weakSelf pushSubVC:responseObject[@"Data"]];
  139. }else{
  140. SHOWERROR(responseObject[@"Msg"]);
  141. }
  142. } failure:^(NSError * _Nonnull error) {
  143. NSLog(@"%@",error);
  144. SHOWERROR([ZYCTool handerResultData:error])
  145. }];
  146. } cancle:^{
  147. }] show];
  148. }
  149. else if ([@"批量编辑" isEqualToString:action.title]){
  150. weakSelf.titleL.text = @"批量编辑";
  151. [weakSelf.tableView setEditing:YES];
  152. [weakSelf changeToOperation:YES];
  153. }
  154. }];
  155. [menuDataSourceArray addObject:actionMenu];
  156. }
  157. return menuDataSourceArray;
  158. }
  159. -(void)initBottomBgView{
  160. UIView * lineV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
  161. lineV.backgroundColor = LINEBGCOLOR;
  162. [self.operationBottomBgView addSubview:lineV];
  163. self.leftCloseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  164. [self.leftCloseBtn setTitle:@"删除" forState:UIControlStateNormal];
  165. [self.leftCloseBtn setTitleColor:RGB(255, 82, 82) forState:UIControlStateNormal];
  166. self.leftCloseBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  167. [self.operationBottomBgView addSubview:self.leftCloseBtn];
  168. self.leftCloseBtn.frame = CGRectMake(0, 10, SCREEN_WIDTH, self.operationBottomBgView.height);
  169. WS(weakSelf);
  170. [self.leftCloseBtn setAction:^{
  171. NSMutableArray *modelArray = [NSMutableArray array];
  172. for (NSInteger i = 0; i < weakSelf.dataArray.count; i ++) {
  173. TopicGroupManageModel * model = weakSelf.dataArray[i];
  174. if (model.isSelect) {
  175. [weakSelf.selectArray addObject:@(model.Id)];
  176. [modelArray addObject:model];
  177. }
  178. }
  179. if (weakSelf.selectArray.count == 0) {
  180. SHOWERROR(@"请选择要删除的分组");
  181. return ;
  182. }else{
  183. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  184. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  185. [weakSelf deleteFind:weakSelf.selectArray index:modelArray];
  186. }];
  187. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  188. }];
  189. [alert addAction:sureAction];
  190. [alert addAction:cancelAction];
  191. [weakSelf presentViewController:alert animated:YES completion:^{
  192. }];
  193. }
  194. }];
  195. [[UtilsTools getWindow] addSubview:self.operationBottomBgView];
  196. }
  197. #pragma Mark 左滑按钮 iOS8以上
  198. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
  199. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){// delete action
  200. WS(weakSelf);
  201. TopicGroupManageModel * model = [self.dataArray objectAtIndex:indexPath.row];
  202. UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  203. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  204. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  205. [weakSelf deleteFind:@[@(model.Id)]];
  206. }];
  207. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  208. }];
  209. [alert addAction:sureAction];
  210. [alert addAction:cancelAction];
  211. [weakSelf presentViewController:alert animated:YES completion:^{
  212. }];
  213. }];
  214. action1.backgroundColor = UIColorHex(#F64A33);
  215. UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"重命名" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  216. [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"重命名" changeStr:model.Name confirm:^(NSString * _Nonnull groupName) {
  217. NSLog(@"%@",groupName);
  218. [weakSelf reChangeName:model name:groupName];
  219. } cancle:^{
  220. }] show];
  221. }];
  222. action2.backgroundColor = UIColorHex(#FF923A);
  223. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1,action2]];
  224. actions.performsFirstActionWithFullSwipe = NO;
  225. return actions;
  226. }
  227. #else
  228. - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
  229. WS(weakSelf);
  230. TopicGroupManageModel * model = [self.dataArray objectAtIndex:indexPath.row];
  231. UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  232. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  233. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  234. [weakSelf deleteFind:@[@(model.Id)]];
  235. }];
  236. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  237. }];
  238. [alert addAction:sureAction];
  239. [alert addAction:cancelAction];
  240. [weakSelf presentViewController:alert animated:YES completion:^{
  241. }];
  242. }];
  243. action1.backgroundColor = UIColorHex(#F64A33);
  244. UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title: @"重命名" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  245. [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"重命名" changeStr:model.Name confirm:^(NSString * _Nonnull groupName) {
  246. NSLog(@"%@",groupName);
  247. [weakSelf reChangeName:model name:groupName];
  248. } cancle:^{
  249. }] show];
  250. }];
  251. action2.backgroundColor = UIColorHex(#FF923A);
  252. return @[action1, action2];
  253. }
  254. #endif
  255. - (void)deleteFind:(NSArray *)array
  256. {
  257. WS(weakSelf);
  258. [[HttpManager sharedHttpManager] DeleteUrl:Host(APP_Topic_Topic_Delete_Group) parameters:@{@"Ids":array} responseStyle:DATA success:^(id _Nonnull responseObject) {
  259. [weakSelf getData];
  260. } failure:^(NSError * _Nonnull error) {
  261. }];
  262. }
  263. - (void)deleteFind:(NSArray *)array index:(NSArray *)indexArray
  264. {
  265. WS(weakSelf);
  266. [[HttpManager sharedHttpManager] DeleteUrl:Host(APP_Topic_Topic_Delete_Group) parameters:@{@"Ids":array} responseStyle:DATA success:^(id _Nonnull responseObject) {
  267. [weakSelf.dataArray removeObjectsInArray:indexArray];
  268. [weakSelf.selectArray removeAllObjects];
  269. dispatch_async(dispatch_get_main_queue(), ^{
  270. [weakSelf getData];
  271. });
  272. } failure:^(NSError * _Nonnull error) {
  273. }];
  274. }
  275. - (void)reChangeName:(TopicGroupManageModel *)model name:(NSString *)name
  276. {
  277. NSDictionary * paraDict = @{@"Id":@(model.Id),
  278. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  279. @"Name":name
  280. };
  281. WS(weakSelf);
  282. SHOWLOADING
  283. [[HttpManager sharedHttpManager] PUTUrl:Host(APP_Topic_Update_Group) parameters:paraDict success:^(id _Nonnull responseObject) {
  284. REMOVESHOW
  285. [weakSelf getData];
  286. } failure:^(NSError * _Nonnull error) {
  287. REMOVESHOW
  288. }];
  289. }
  290. -(UIView *)operationBottomBgView{
  291. if(!_operationBottomBgView){
  292. _operationBottomBgView = [[UIView alloc] init];
  293. CGFloat bottomBgViewH = self.tabBarController.tabBar.height;
  294. _operationBottomBgView.frame = CGRectMake(0, SCREEN_HEIGHT - bottomBgViewH - 10, SCREEN_WIDTH, bottomBgViewH + 10);
  295. _operationBottomBgView.backgroundColor = RGB(255, 255, 255);
  296. _operationBottomBgView.hidden = YES;
  297. }
  298. return _operationBottomBgView;
  299. }
  300. #pragma mark 批量操作与正常操作界面切换
  301. -(void)changeToOperation:(BOOL)operation{
  302. if(operation){
  303. self.iSViewEditor = YES;
  304. [self.AddBtn setImage:[UIImage imageNamed:@"chatmsg_right_fileadd_icon"] forState:UIControlStateNormal];
  305. //默认操作状态为批量编辑状态
  306. self.menuBtn.hidden = YES;
  307. self.operationStateEnum = OperationStateEnum1;
  308. // self.operationBackButton.hidden = NO;
  309. self.operationAllSelectButton.hidden = NO;
  310. // self.tabBarController.tabBar.hidden = YES;
  311. self.fd_interactivePopDisabled = NO;
  312. self.operationBottomBgView.hidden = NO;
  313. self.view.height -= self.tabBarController.tabBar.height;
  314. self.tableView.height -= self.tabBarController.tabBar.height;
  315. [self.view layoutIfNeeded];
  316. [self.tableView layoutIfNeeded];
  317. self.fd_interactivePopDisabled = YES;
  318. }else{
  319. [self.AddBtn setImage:[UIImage imageNamed:@"chatmsg_right_add_icon"] forState:UIControlStateNormal];
  320. self.iSViewEditor = NO;
  321. self.menuBtn.hidden = NO;
  322. //默认操作状态为无状态
  323. self.operationStateEnum = OperationStateEnum0;
  324. self.operationAllSelectButton.hidden = YES;
  325. // self.tabBarController.tabBar.hidden = YES;
  326. self.fd_interactivePopDisabled = YES;
  327. self.tableView.height += self.tabBarController.tabBar.height;
  328. self.view.height += self.tabBarController.tabBar.height;
  329. [self.view layoutIfNeeded];
  330. [self.tableView layoutIfNeeded];
  331. self.operationBottomBgView.hidden = YES;
  332. self.fd_interactivePopDisabled = NO;
  333. }
  334. [self.tableView reloadData];
  335. }
  336. #pragma mark 移动 isEdit:当前是否为编辑状态
  337. -(void)userDidMove:(BOOL)move isEdit:(BOOL)isEdit{
  338. //移动
  339. if(move){
  340. //默认操作状态为移动状态
  341. self.operationStateEnum = OperationStateEnum2;
  342. self.AddBtn.hidden = NO;
  343. [self resetRightBtnAction:NO];
  344. //隐藏tabBar - 并将TableView至底端
  345. self.tabBarController.tabBar.hidden = YES;
  346. self.view.height += self.tabBarController.tabBar.height;
  347. self.tableView.height += self.tabBarController.tabBar.height;
  348. [self.view layoutIfNeeded];
  349. [self.tableView layoutIfNeeded];
  350. //隐藏operationBottomBgView
  351. self.operationBottomBgView.hidden = YES;
  352. }
  353. else{
  354. //隐藏tabBar - 并将TableView至底端有tabBar.height的高
  355. self.tabBarController.tabBar.hidden = YES;
  356. self.view.height -= self.tabBarController.tabBar.height;
  357. self.tableView.height -= self.tabBarController.tabBar.height;
  358. [self.view layoutIfNeeded];
  359. [self.tableView layoutIfNeeded];
  360. //显示operationBottomBgView
  361. self.operationBottomBgView.hidden = NO;
  362. if(isEdit){
  363. self.operationStateEnum = OperationStateEnum1;
  364. self.AddBtn.hidden = YES;
  365. [self resetRightBtnAction:YES];
  366. }else{
  367. [self changeToOperation:NO];
  368. }
  369. }
  370. [self.tableView reloadData];
  371. }
  372. -(void)resetRightBtnAction:(BOOL)isShowMenu{
  373. WS(weakSelf);
  374. if(isShowMenu){
  375. [self.AddBtn setImage:[UIImage imageNamed:@"chatmsg_right_add_icon"] forState:UIControlStateNormal];
  376. [self.AddBtn setAction:^{
  377. NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.addListArray];
  378. YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:106 relyonView:weakSelf.AddBtn];
  379. view.menuColor = RGB(255, 255, 255);
  380. view.separatorColor = RGB(234, 234, 234);
  381. view.textColor = RGB(102, 102, 102);
  382. view.textFont = [UIFont systemFontOfSize:16.0];
  383. view.menuCellHeight = 43.5;
  384. view.maxDisplayCount = 10;
  385. view.offset = -6;
  386. [view show];
  387. }];
  388. }else{
  389. [self.AddBtn setImage:[UIImage imageNamed:@"chatmsg_right_fileadd_icon"] forState:UIControlStateNormal];
  390. [self.AddBtn setAction:^{
  391. [ShowtipTool showErrorWithStatus:@"未做"];
  392. }];
  393. }
  394. }
  395. - (void)backAction:(id)sender{
  396. if (self.iSViewEditor) {
  397. self.tableView.editing = NO;
  398. [self getData];
  399. self.titleL.text = @"分组管理";
  400. [self changeToOperation:NO];
  401. }else{
  402. [self changeToOperation:NO];
  403. if (self.RefreshListBlock) {
  404. self.RefreshListBlock();
  405. }
  406. [self.navigationController popViewControllerAnimated:true];
  407. }
  408. }
  409. - (void)menuAction:(id)sender{
  410. [super menuAction:sender];
  411. }
  412. - (void)getData
  413. {
  414. [self.dataArray removeAllObjects];
  415. WS(weakSelf);
  416. [[HttpManager sharedHttpManager] GETUrl:Host(APP_Topic_List_Group) parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  417. NSLog(@"%@",responseObject);
  418. NSArray * array = responseObject;
  419. [array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  420. NSDictionary * dict = (NSDictionary *)obj;
  421. TopicGroupManageModel * model = [TopicGroupManageModel modelWithDictionary:dict];
  422. [weakSelf.dataArray addObject:model];
  423. }];
  424. dispatch_async(dispatch_get_main_queue(), ^{
  425. if (weakSelf.dataArray.count == 0) {
  426. [weakSelf changeToOperation:NO];
  427. }
  428. [weakSelf.tableView reloadData];
  429. });
  430. } failure:^(NSError * _Nonnull error) {
  431. }];
  432. }
  433. //- (void)getDataNoRefresh
  434. //{
  435. // [self.dataArray removeAllObjects];
  436. // WS(weakSelf);
  437. // [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Topic_List_Group) parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  438. // NSLog(@"%@",responseObject);
  439. // NSArray * array = responseObject;
  440. // [array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  441. // NSDictionary * dict = (NSDictionary *)obj;
  442. // TopicGroupManageModel * model = [TopicGroupManageModel modelWithDictionary:dict];
  443. // [weakSelf.dataArray addObject:model];
  444. // }];
  445. // } failure:^(NSError * _Nonnull error) {
  446. //
  447. // }];
  448. //}
  449. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  450. {
  451. return 50.f;
  452. }
  453. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  454. {
  455. return self.dataArray.count;
  456. }
  457. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  458. {
  459. TopicGroupManageModel * model = [self.dataArray objectAtIndex:indexPath.row];
  460. switch (self.operationStateEnum) {
  461. case OperationStateEnum0:
  462. {
  463. TopicGroupManageCell * cell = [TopicGroupManageCell configCell0:tableView indexPath:indexPath];
  464. cell.nameL.text = model.Name;
  465. cell.countL.text = [NSString stringWithFormat:@"%ld",(long)model.IncludeCount];
  466. return cell;
  467. }
  468. break;
  469. default:
  470. {
  471. TopicGroupManageCell * cell = [TopicGroupManageCell configCell1:tableView indexPath:indexPath];
  472. cell.cell1NameL.text = model.Name;
  473. cell.cell1SelectBtn.selected = model.isSelect;
  474. self.isAllSelect = [self isCheckAllData];
  475. if (self.isAllSelect) {
  476. [self.operationAllSelectButton setTitle:@"取消全选" forState:UIControlStateNormal];
  477. }else{
  478. [self.operationAllSelectButton setTitle:@"全选" forState:UIControlStateNormal];
  479. }
  480. self.rightMoveBtn.enabled = [self isMoveCheckData];
  481. [cell.cell1SelectBtn setAction:^{
  482. model.isSelect = !model.isSelect;
  483. [tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationAutomatic];
  484. }];
  485. return cell;
  486. }
  487. break;
  488. }
  489. }
  490. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  491. {
  492. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  493. TopicGroupManageModel * model = [self.dataArray objectAtIndex:indexPath.row];
  494. switch (self.operationStateEnum) {
  495. case OperationStateEnum1:{
  496. NSLog(@"编辑状态的cell");
  497. model.isSelect = !model.isSelect;
  498. [tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationAutomatic];
  499. }break;
  500. default:{
  501. NSLog(@"正常状态的cell");
  502. MyTDTopicGroupUserVC * vc = [MyTDTopicGroupUserVC initMyTDTopicGroupUserVC];
  503. vc.GroupId = model.Id;
  504. vc.titleStr = model.Name;
  505. [self.navigationController pushViewController:vc animated:YES];
  506. }break;
  507. }
  508. }
  509. - (void)pushSubVC:(NSDictionary *)dict
  510. {
  511. if ([dict isKindOfClass:[NSDictionary class]]) {
  512. MyTDTopicGroupUserVC * vc = [MyTDTopicGroupUserVC initMyTDTopicGroupUserVC];
  513. vc.GroupId = [dict[@"Id"] integerValue];
  514. vc.IsCreate = YES;
  515. vc.titleStr = dict[@"Name"];
  516. [self.navigationController pushViewController:vc animated:NO];
  517. }
  518. }
  519. -(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
  520. {
  521. TopicGroupManageModel * firstModel = [self.dataArray objectAtIndex:sourceIndexPath.row];
  522. TopicGroupManageModel * secondModel = [self.dataArray objectAtIndex:destinationIndexPath.row];
  523. WS(weakSelf);
  524. [[HttpManager sharedHttpManager] PUTUrl:Host(API_APP_Topic_Sort) parameters:@{@"FirstId": @(firstModel.Id),
  525. @"SecondId": @(secondModel.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) {
  526. [weakSelf.dataArray removeObject:firstModel];
  527. [weakSelf.dataArray insertObject:firstModel atIndex:destinationIndexPath.row];
  528. dispatch_async(dispatch_get_main_queue(), ^{
  529. [weakSelf getData];
  530. });
  531. } failure:^(NSError * _Nonnull error) {
  532. }];
  533. }
  534. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  535. {
  536. if (self.iSViewEditor) {
  537. UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)];
  538. view.backgroundColor = UIColorHex(#F0EFF4);
  539. UILabel * label = [UILabel new];
  540. [view addSubview:label];
  541. label.textAlignment = NSTextAlignmentCenter;
  542. label.font = [UIFont fontWithName:@"PingFang SC" size: 13];
  543. label.text = @"长按右侧三横,拖动可进行排序";
  544. label.textColor = UIColorHex(#666666);
  545. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  546. make.center.mas_equalTo(view);
  547. }];
  548. return view;
  549. }else{
  550. return nil;
  551. }
  552. }
  553. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  554. {
  555. if (self.iSViewEditor) {
  556. return 35.f;
  557. }else{
  558. return 0.01f;
  559. }
  560. }
  561. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  562. {
  563. return YES;
  564. }
  565. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  566. {
  567. return UITableViewCellEditingStyleNone;
  568. }
  569. - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
  570. { return NO;}
  571. - (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
  572. { return NO;}
  573. - (BOOL)isCheckAllData
  574. {
  575. for (TopicGroupManageModel * model in self.dataArray) {
  576. if (!model.isSelect) {
  577. return NO;
  578. }
  579. }
  580. return YES;
  581. }
  582. - (BOOL)isMoveCheckData
  583. {
  584. BOOL isSelect = NO;
  585. for (TopicGroupManageModel * model in self.dataArray) {
  586. if (model.isSelect) {
  587. isSelect = YES;
  588. }
  589. }
  590. if (!isSelect) {
  591. return NO;
  592. }
  593. return YES;
  594. }
  595. - (NSMutableArray *)dataArray
  596. {
  597. if (!_dataArray) {
  598. _dataArray = [NSMutableArray array];
  599. }
  600. return _dataArray;
  601. }
  602. - (NSMutableArray *)selectArray
  603. {
  604. if (!_selectArray) {
  605. _selectArray = [NSMutableArray array];
  606. }
  607. return _selectArray;
  608. }
  609. //- (void)viewWillDisappear:(BOOL)animated
  610. //{
  611. // [super viewWillDisappear:animated];
  612. // [self changeToOperation:NO];
  613. // if (self.RefreshListBlock) {
  614. // self.RefreshListBlock();
  615. // }
  616. //}
  617. @end