MyTDTopicUserSearchVC.m 7.6 KB

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