MyTDTopicGroupManageVC.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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] GETUrl:Host(APP_Topic_List_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_List_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. //}
  382. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  383. {
  384. return 50.f;
  385. }
  386. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  387. {
  388. return self.dataArray.count;
  389. }
  390. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  391. {
  392. TopicGroupManageModel * model = [self.dataArray objectAtIndex:indexPath.row];
  393. switch (self.operationStateEnum) {
  394. case OperationStateEnum0:
  395. {
  396. TopicGroupManageCell * cell = [TopicGroupManageCell configCell0:tableView indexPath:indexPath];
  397. cell.nameL.text = model.Name;
  398. cell.countL.text = [NSString stringWithFormat:@"%ld",(long)model.IncludeCount];
  399. return cell;
  400. }
  401. break;
  402. default:
  403. {
  404. TopicGroupManageCell * cell = [TopicGroupManageCell configCell1:tableView indexPath:indexPath];
  405. cell.cell1NameL.text = model.Name;
  406. cell.cell1SelectBtn.selected = model.isSelect;
  407. self.isAllSelect = [self isCheckAllData];
  408. if (self.isAllSelect) {
  409. [self.operationAllSelectButton setTitle:@"取消全选" forState:UIControlStateNormal];
  410. }else{
  411. [self.operationAllSelectButton setTitle:@"全选" forState:UIControlStateNormal];
  412. }
  413. self.rightMoveBtn.enabled = [self isMoveCheckData];
  414. return cell;
  415. }
  416. break;
  417. }
  418. }
  419. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  420. {
  421. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  422. TopicGroupManageModel * model = [self.dataArray objectAtIndex:indexPath.row];
  423. switch (self.operationStateEnum) {
  424. case OperationStateEnum1:{
  425. NSLog(@"编辑状态的cell");
  426. model.isSelect = !model.isSelect;
  427. [tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationAutomatic];
  428. }break;
  429. default:{
  430. NSLog(@"正常状态的cell");
  431. MyTDTopicGroupUserVC * vc = [MyTDTopicGroupUserVC initMyTDTopicGroupUserVC];
  432. vc.GroupId = model.Id;
  433. vc.titleStr = model.Name;
  434. [self.navigationController pushViewController:vc animated:YES];
  435. }break;
  436. }
  437. }
  438. -(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
  439. {
  440. TopicGroupManageModel * firstModel = [self.dataArray objectAtIndex:sourceIndexPath.row];
  441. TopicGroupManageModel * secondModel = [self.dataArray objectAtIndex:destinationIndexPath.row];
  442. // [self.dataArray exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];
  443. // [self.tableView moveRowAtIndexPath:sourceIndexPath toIndexPath:destinationIndexPath];
  444. WS(weakSelf);
  445. [[HttpManager sharedHttpManager] PUTUrl:Host(API_APP_Topic_Sort) parameters:@{@"FirstId": @(firstModel.Id),
  446. @"SecondId": @(secondModel.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) {
  447. [weakSelf.dataArray removeObject:firstModel];
  448. [weakSelf.dataArray insertObject:firstModel atIndex:destinationIndexPath.row];
  449. dispatch_async(dispatch_get_main_queue(), ^{
  450. [weakSelf.tableView reloadData];
  451. });
  452. } failure:^(NSError * _Nonnull error) {
  453. }];
  454. }
  455. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  456. {
  457. if (self.iSViewEditor) {
  458. UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)];
  459. view.backgroundColor = UIColorHex(#F0EFF4);
  460. UILabel * label = [UILabel new];
  461. [view addSubview:label];
  462. label.textAlignment = NSTextAlignmentCenter;
  463. label.font = [UIFont fontWithName:@"PingFang SC" size: 13];
  464. label.text = @"长按右侧三横,拖动可进行排序";
  465. label.textColor = UIColorHex(#666666);
  466. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  467. make.center.mas_equalTo(view);
  468. }];
  469. return view;
  470. }else{
  471. return nil;
  472. }
  473. }
  474. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  475. {
  476. if (self.iSViewEditor) {
  477. return 35.f;
  478. }else{
  479. return 0.01f;
  480. }
  481. }
  482. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  483. {
  484. return YES;
  485. }
  486. - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  487. {
  488. return UITableViewCellEditingStyleNone;
  489. }
  490. - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
  491. { return NO;}
  492. - (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
  493. { return NO;}
  494. - (BOOL)isCheckAllData
  495. {
  496. for (TopicGroupManageModel * model in self.dataArray) {
  497. if (!model.isSelect) {
  498. return NO;
  499. }
  500. }
  501. return YES;
  502. }
  503. - (BOOL)isMoveCheckData
  504. {
  505. BOOL isSelect = NO;
  506. for (TopicGroupManageModel * model in self.dataArray) {
  507. if (model.isSelect) {
  508. isSelect = YES;
  509. }
  510. }
  511. if (!isSelect) {
  512. return NO;
  513. }
  514. return YES;
  515. }
  516. - (NSMutableArray *)dataArray
  517. {
  518. if (!_dataArray) {
  519. _dataArray = [NSMutableArray array];
  520. }
  521. return _dataArray;
  522. }
  523. - (NSMutableArray *)selectArray
  524. {
  525. if (!_selectArray) {
  526. _selectArray = [NSMutableArray array];
  527. }
  528. return _selectArray;
  529. }
  530. - (void)viewWillDisappear:(BOOL)animated
  531. {
  532. [super viewWillDisappear:animated];
  533. if (self.RefreshListBlock) {
  534. self.RefreshListBlock();
  535. }
  536. }
  537. @end