MyTDTopicUserMoveVC.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // MyTDTopicUserMoveVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2019/12/20.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "MyTDTopicUserMoveVC.h"
  9. #import "TopicGroupManageModel.h"
  10. #import "TopicGroupManageCell.h"
  11. #import "MyTDGroupView.h"
  12. #import "ShowNewGroupAlert.h"
  13. @interface MyTDTopicUserMoveVC ()<UITableViewDelegate, UITableViewDataSource>
  14. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  15. @property (weak, nonatomic) IBOutlet UILabel *titleL;
  16. @property (weak, nonatomic) IBOutlet UIButton *addBtn;
  17. @property (nonatomic, strong) NSMutableArray *dataArray;
  18. @end
  19. @implementation MyTDTopicUserMoveVC
  20. +(MyTDTopicUserMoveVC *)initMyTDTopicUserMoveVC;
  21. {
  22. MyTDTopicUserMoveVC *controller = [StoryboardManager.shared.myTDTopicExtent instantiateViewControllerWithIdentifier:@"MyTDTopicUserMoveVC"];
  23. return controller;
  24. }
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. self.fd_prefersNavigationBarHidden = YES;
  28. self.titleL.text = @"移动到";
  29. self.tableView.delegate = self;
  30. self.tableView.dataSource = self;
  31. [self getData];
  32. WS(weakSelf);
  33. [self.addBtn setAction:^{
  34. [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"新建分组" placeholder:@"请输入分组名称" confirm:^(NSString * _Nonnull groupName) {
  35. NSLog(@"%@",groupName);
  36. NSDictionary * paraDict = @{@"Name":groupName,
  37. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  38. @"Id":@(0)
  39. };
  40. [[HttpManager sharedHttpManager] PUTUrl:Host(APP_Topic_Add_Group) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  41. NSLog(@"%@",responseObject);
  42. dispatch_async(dispatch_get_main_queue(), ^{
  43. [weakSelf getData];
  44. });
  45. } failure:^(NSError * _Nonnull error) {
  46. NSLog(@"%@",error);
  47. SHOWERROR([ZYCTool handerResultData:error])
  48. }];
  49. } cancle:^{
  50. }] show];
  51. }];
  52. }
  53. - (void)getData
  54. {
  55. [self.dataArray removeAllObjects];
  56. WS(weakSelf);
  57. [[HttpManager sharedHttpManager] GETUrl:Host(APP_Topic_List_Group) parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  58. NSLog(@"%@",responseObject);
  59. NSArray * array = responseObject;
  60. [array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  61. NSDictionary * dict = (NSDictionary *)obj;
  62. TopicGroupManageModel * model = [TopicGroupManageModel modelWithDictionary:dict];
  63. [weakSelf.dataArray addObject:model];
  64. }];
  65. dispatch_async(dispatch_get_main_queue(), ^{
  66. [weakSelf.tableView reloadData];
  67. });
  68. } failure:^(NSError * _Nonnull error) {
  69. }];
  70. }
  71. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  72. {
  73. if (section == 0) {
  74. return 50.f;
  75. }
  76. return 0.01f;
  77. }
  78. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  79. {
  80. if (section == 0) {
  81. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
  82. MyTDGroupView * groupView = [[MyTDGroupView alloc] init];
  83. [view addSubview:groupView];
  84. view.backgroundColor = UIColorHex(FFFFFF);
  85. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushSearchVC)];
  86. [view addGestureRecognizer:tap];
  87. view.userInteractionEnabled = YES;
  88. return view;
  89. }else{
  90. return [UIView new];
  91. }
  92. }
  93. - (void)pushSearchVC
  94. {
  95. }
  96. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  97. {
  98. return 50.f;
  99. }
  100. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  101. {
  102. return self.dataArray.count;
  103. }
  104. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  105. {
  106. TopicGroupManageModel * model = [self.dataArray objectAtIndex:indexPath.row];
  107. TopicGroupManageCell * cell = [TopicGroupManageCell configCell0:tableView indexPath:indexPath];
  108. cell.countL.hidden = YES;
  109. cell.rightImgV.hidden = YES;
  110. cell.nameL.text = model.Name;
  111. return cell;
  112. }
  113. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  114. {
  115. TopicGroupManageModel * model = [self.dataArray objectAtIndex:indexPath.row];
  116. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  117. [self moveToindex:model.Id];
  118. }
  119. - (void)moveToindex:(NSInteger)toId
  120. {
  121. WS(weakSelf);
  122. SHOWLOADING
  123. [[HttpManager sharedHttpManager] PUTUrl:Host(APP_Topic_Move) parameters:@{@"TopicGroupId":@(toId),@"Ids":self.selectIdArray} responseStyle:DATA success:^(id _Nonnull responseObject) {
  124. REMOVESHOW
  125. SHOWSUCCESS(@"操作成功");
  126. for ( int i = 0; i< weakSelf.navigationController.viewControllers.count; i++) {
  127. if ([weakSelf.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyTDTopicGroupManageVC")]) {
  128. [weakSelf.navigationController popToViewController:self.navigationController.viewControllers[i] animated:YES];
  129. }
  130. }
  131. } failure:^(NSError * _Nonnull error) {
  132. REMOVESHOW
  133. SHOWERROR([ZYCTool handerResultData:error])
  134. }];
  135. }
  136. - (NSMutableArray *)dataArray
  137. {
  138. if (!_dataArray) {
  139. _dataArray = [NSMutableArray array];
  140. }
  141. return _dataArray;
  142. }
  143. @end