MyTDTopicGroupSearchVC.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // MyTDTopicGroupSearchVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2019/12/19.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "MyTDTopicGroupSearchVC.h"
  9. #import "TopicGroupManageModel.h"
  10. #import "TopicGroupManageCell.h"
  11. #import "MyTDTopicGroupUserVC.h"
  12. #import "ShowNewGroupAlert.h"
  13. @interface MyTDTopicGroupSearchVC ()<UITableViewDelegate,UITableViewDataSource>
  14. @property (strong, nonatomic) NSMutableArray * dataArray;
  15. @end
  16. @implementation MyTDTopicGroupSearchVC
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.fd_prefersNavigationBarHidden = YES;
  20. self.view.backgroundColor = RGB(255, 255, 255);
  21. self.tableView.delegate = self;
  22. self.tableView.dataSource = self;
  23. self.historySearchType = HistorySearchType_TopicGroupManager;
  24. [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil];
  25. }
  26. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  27. {
  28. id obj = [change objectForKey:@"new"];
  29. NSString * text = @"";
  30. if ([obj isKindOfClass:[NSString class]]) {
  31. text = obj;
  32. }else{
  33. text = [obj stringValue];
  34. }
  35. if (text.length > 0) {
  36. [self getData:text];
  37. }
  38. }
  39. - (NSMutableArray *)dataArray
  40. {
  41. if (!_dataArray) {
  42. _dataArray = [NSMutableArray array];
  43. }
  44. return _dataArray;
  45. }
  46. - (void)getData:(NSString *)text
  47. {
  48. [self.dataArray removeAllObjects];
  49. WS(weakSelf);
  50. [[HttpManager sharedHttpManager] GETUrl:Host(APP_Topic_List_Group) parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  51. NSLog(@"%@",responseObject);
  52. NSArray * array = responseObject;
  53. [array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  54. NSDictionary * dict = (NSDictionary *)obj;
  55. TopicGroupManageModel * model = [TopicGroupManageModel modelWithDictionary:dict];
  56. if ([model.Name containsString:text]) {
  57. [weakSelf.dataArray addObject:model];
  58. }
  59. }];
  60. dispatch_async(dispatch_get_main_queue(), ^{
  61. if (weakSelf.dataArray.count > 0) {
  62. weakSelf.collectionView.hidden = YES;
  63. weakSelf.noDataView.hidden = YES;
  64. weakSelf.tableView.hidden = NO;
  65. [weakSelf.tableView reloadData];
  66. }else{
  67. weakSelf.noDataView.hidden = NO;
  68. weakSelf.collectionView.hidden = YES;
  69. weakSelf.tableView.hidden = YES;
  70. weakSelf.noDataL.text = @"暂无该分组";
  71. }
  72. [weakSelf.tableView reloadData];
  73. });
  74. } failure:^(NSError * _Nonnull error) {
  75. }];
  76. }
  77. #pragma mark - UITableViewDelegate
  78. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  79. {
  80. return 50.f;
  81. }
  82. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  83. {
  84. return self.dataArray.count;
  85. }
  86. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  87. {
  88. TopicGroupManageModel * model = [self.dataArray objectAtIndex:indexPath.row];
  89. TopicGroupManageCell * cell = [TopicGroupManageCell configCell0:tableView indexPath:indexPath];
  90. cell.nameL.text = model.Name;
  91. cell.countL.text = [NSString stringWithFormat:@"%ld",(long)model.IncludeCount];
  92. return cell;
  93. }
  94. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  95. {
  96. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  97. TopicGroupManageModel * model = [self.dataArray objectAtIndex:indexPath.row];
  98. MyTDTopicGroupUserVC * vc = [MyTDTopicGroupUserVC initMyTDTopicGroupUserVC];
  99. vc.GroupId = model.Id;
  100. vc.titleStr = model.Name;
  101. [self.navigationController pushViewController:vc animated:YES];
  102. }
  103. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){// delete action
  104. WS(weakSelf);
  105. TopicGroupManageModel * model = [self.dataArray objectAtIndex:indexPath.row];
  106. UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  107. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  108. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  109. [weakSelf deleteFind:model.Id index:indexPath.row];
  110. }];
  111. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  112. }];
  113. [alert addAction:sureAction];
  114. [alert addAction:cancelAction];
  115. [weakSelf presentViewController:alert animated:YES completion:^{
  116. }];
  117. }];
  118. action1.backgroundColor = UIColorHex(#F64A33);
  119. UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"重命名" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  120. [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"重命名" changeStr:model.Name confirm:^(NSString * _Nonnull groupName) {
  121. NSLog(@"%@",groupName);
  122. [weakSelf reChangeName:model name:groupName];
  123. } cancle:^{
  124. }] show];
  125. }];
  126. action2.backgroundColor = UIColorHex(#FF923A);
  127. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1,action2]];
  128. actions.performsFirstActionWithFullSwipe = NO;
  129. return actions;
  130. }
  131. - (void)deleteFind:(NSInteger)Id index:(NSInteger)row
  132. {
  133. WS(weakSelf);
  134. [[HttpManager sharedHttpManager] DeleteUrl:Host(APP_Topic_Topic_Delete_Group) parameters:@{@"Ids":@[@(Id)]} responseStyle:DATA success:^(id _Nonnull responseObject) {
  135. [weakSelf.dataArray removeObjectAtIndex:row];
  136. dispatch_async(dispatch_get_main_queue(), ^{
  137. [weakSelf.tableView reloadData];
  138. });
  139. } failure:^(NSError * _Nonnull error) {
  140. }];
  141. }
  142. - (void)reChangeName:(TopicGroupManageModel *)model name:(NSString *)name
  143. {
  144. NSDictionary * paraDict = @{@"Id":@(model.Id),
  145. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  146. @"Name":name
  147. };
  148. WS(weakSelf);
  149. SHOWLOADING
  150. [[HttpManager sharedHttpManager] PUTUrl:Host(APP_Topic_Update_Group) parameters:paraDict success:^(id _Nonnull responseObject) {
  151. REMOVESHOW
  152. [weakSelf getData:weakSelf.searchText];
  153. } failure:^(NSError * _Nonnull error) {
  154. REMOVESHOW
  155. }];
  156. }
  157. @end