MyTDTopicGroupManageVC.m 23 KB

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