MyTDTopicUserSearchVC.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // MyTDTopicUserSearchVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/1/1.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "MyTDTopicUserSearchVC.h"
  9. #import "SelectModel.h"
  10. #import "MyTDTopicUserMoveVC.h"
  11. #import "MailListByZuCell.h"
  12. @interface MyTDTopicUserSearchVC ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic, copy) NSString * text;
  14. @property (nonatomic, strong) NSMutableArray * searchArray;
  15. @end
  16. @implementation MyTDTopicUserSearchVC
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.tableView.delegate = self;
  20. self.tableView.dataSource = self;
  21. self.historySearchType = HistorySearchType_MailList;
  22. [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil];
  23. }
  24. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  25. {
  26. id obj = [change objectForKey:@"new"];
  27. NSString * text = @"";
  28. if ([obj isKindOfClass:[NSString class]]) {
  29. text = obj;
  30. }else{
  31. text = [obj stringValue];
  32. }
  33. if (text.length > 0) {
  34. [self forDataArraySearch:text];
  35. }
  36. }
  37. - (void)forDataArraySearch:(NSString *)text
  38. {
  39. [self.searchArray removeAllObjects];
  40. for (SelectModel * model in self.listArray) {
  41. if ([model.UserName containsString:text]) {
  42. [self.searchArray addObject:model];
  43. }
  44. }
  45. if (self.searchArray.count > 0) {
  46. self.collectionView.hidden = YES;
  47. self.noDataView.hidden = YES;
  48. self.tableView.hidden = NO;
  49. [self.tableView reloadData];
  50. }else{
  51. self.noDataView.hidden = NO;
  52. self.collectionView.hidden = YES;
  53. self.tableView.hidden = YES;
  54. self.noDataL.text = @"暂无成员";
  55. }
  56. }
  57. - (NSMutableArray *)searchArray
  58. {
  59. if (!_searchArray) {
  60. _searchArray = [NSMutableArray array];
  61. }
  62. return _searchArray;
  63. }
  64. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  65. return 1;
  66. }
  67. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  68. {
  69. return self.searchArray.count;
  70. }
  71. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  72. return 65.f;
  73. }
  74. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  75. SelectModel * model = [self.searchArray objectAtIndex:indexPath.row];
  76. MailListByZuCell *cell = [MailListByZuCell configCell0:tableView indexPath:indexPath];
  77. cell.cell0TitleLabel.text = model.UserName;
  78. [cell.cell0ImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  79. return cell;
  80. }
  81. #pragma Mark 左滑按钮 iOS8以上
  82. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
  83. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){// delete action
  84. WS(weakSelf);
  85. SelectModel * model = [self.searchArray objectAtIndex:indexPath.row];
  86. UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  87. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  88. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  89. [weakSelf deleteFind:@[@(model.Id)] indexPath:indexPath.row];
  90. }];
  91. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  92. }];
  93. [alert addAction:sureAction];
  94. [alert addAction:cancelAction];
  95. [weakSelf presentViewController:alert animated:YES completion:^{
  96. }];
  97. }];
  98. action1.backgroundColor = UIColorHex(#F64A33);
  99. UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"移动" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  100. [weakSelf launchMoveVC:@[@(model.Id)]];
  101. }];
  102. action2.backgroundColor = RGB(61, 156, 248);
  103. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1,action2]];
  104. actions.performsFirstActionWithFullSwipe = NO;
  105. return actions;
  106. }
  107. #else
  108. - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
  109. WS(weakSelf);
  110. SelectModel * model = [self.searchArray objectAtIndex:indexPath.row];
  111. UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  112. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  113. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  114. [weakSelf deleteFind:@[@(model.Id)] indexPath:indexPath.row];
  115. }];
  116. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  117. }];
  118. [alert addAction:sureAction];
  119. [alert addAction:cancelAction];
  120. [weakSelf presentViewController:alert animated:YES completion:^{
  121. }];
  122. }];
  123. action1.backgroundColor = UIColorHex(#F64A33);
  124. UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"移动" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  125. [weakSelf launchMoveVC:@[@(model.Id)]];
  126. }];
  127. action2.backgroundColor = RGB(61, 156, 248);
  128. return @[action1,action2];
  129. }
  130. #endif
  131. - (void)deleteFind:(NSArray *)array indexPath:(NSInteger)row
  132. {
  133. WS(weakSelf);
  134. [[HttpManager sharedHttpManager] DeleteUrl:Host(APP_Topic_Group_User) parameters:@{@"Ids":array} responseStyle:DATA success:^(id _Nonnull responseObject) {
  135. [weakSelf.searchArray removeObjectAtIndex:row];
  136. dispatch_async(dispatch_get_main_queue(), ^{
  137. [weakSelf.tableView reloadData];
  138. if (weakSelf.upDateBlock) {
  139. weakSelf.upDateBlock();
  140. }
  141. });
  142. } failure:^(NSError * _Nonnull error) {
  143. }];
  144. }
  145. - (void)launchMoveVC:(NSArray *)selectIDArray{
  146. MyTDTopicUserMoveVC * vc = [MyTDTopicUserMoveVC initMyTDTopicUserMoveVC];
  147. vc.selectIdArray = selectIDArray;
  148. if (self.upDateBlock) {
  149. self.upDateBlock();
  150. }
  151. [self.navigationController pushViewController:vc animated:YES];
  152. }
  153. - (void)dealloc
  154. {
  155. [self removeObserver:self forKeyPath:@"searchText" context:nil];
  156. }
  157. @end