GroupSquareSearchVC.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // GroupSquareSearchVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/1/17.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "GroupSquareSearchVC.h"
  9. #import "GroupSquareModel.h"
  10. #import "GroupSquareSubModel.h"
  11. #import "GroupSquareCell.h"
  12. #import "GroupSynopsisVC.h"
  13. #import "TDGroupInfoListVC.h"
  14. #import "GroupVerifyVC.h"
  15. @interface GroupSquareSearchVC ()<UITableViewDelegate,UITableViewDataSource>
  16. @property (nonatomic, strong) NSMutableArray *listArray;
  17. @end
  18. @implementation GroupSquareSearchVC
  19. - (NSMutableArray *)listArray
  20. {
  21. if (!_listArray) {
  22. _listArray = [NSMutableArray array];
  23. }
  24. return _listArray;
  25. }
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. self.fd_prefersNavigationBarHidden = YES;
  29. self.view.backgroundColor = RGB(255, 255, 255);
  30. self.tableView.delegate = self;
  31. self.tableView.dataSource = self;
  32. self.historySearchType = HistorySearchType_Square;
  33. [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil];
  34. }
  35. - (void)dealloc
  36. {
  37. [[NSNotificationCenter defaultCenter] removeObserver:self];
  38. }
  39. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  40. {
  41. id obj = [change objectForKey:@"new"];
  42. NSString * text = @"";
  43. if ([obj isKindOfClass:[NSString class]]) {
  44. text = obj;
  45. }else{
  46. text = [obj stringValue];
  47. }
  48. if (text.length > 0) {
  49. [self getData];
  50. }
  51. }
  52. - (void)getData
  53. {
  54. [self.listArray removeAllObjects];
  55. WS(weakSelf);
  56. [[HttpManager sharedHttpManager] GETUrl:Host(API_APP_GROUP_Search) parameters:@{@"keyWord":self.searchText} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  57. if ([responseObject isKindOfClass:[NSArray class]]) {
  58. for (NSDictionary * dict in responseObject) {
  59. GroupSquareSubModel * model = [GroupSquareSubModel modelWithDictionary:dict];
  60. [weakSelf.listArray addObject:model];
  61. }
  62. }
  63. dispatch_async(dispatch_get_main_queue(), ^{
  64. [weakSelf.tableView reloadData];
  65. });
  66. } failure:^(NSError * _Nonnull error) {
  67. }];
  68. }
  69. #pragma mark - UITableViewDelegate
  70. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  71. {
  72. return self.listArray.count;
  73. }
  74. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  75. {
  76. return [GroupSquareCell configCell1Height];
  77. }
  78. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  79. {
  80. GroupSquareSubModel * model = [self.listArray objectAtIndex:indexPath.row];
  81. GroupSquareCell * cell = [GroupSquareCell configCell1:tableView indexPath:indexPath];
  82. [cell setRightDataSubModel:model withSearchText:self.searchText];
  83. WS(weakSelf);
  84. [cell.JoinBtn setAction:^{
  85. [weakSelf JoinGroupIndex:indexPath withModel:model];
  86. }];
  87. return cell;
  88. }
  89. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  90. {
  91. WS(weakSelf);
  92. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  93. GroupSquareSubModel * model = [self.listArray objectAtIndex:indexPath.row];
  94. if (model.IsUser) {
  95. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  96. vc.GroupId = model.Id;
  97. vc.titleStr = model.Name;
  98. [self.navigationController pushViewController:vc animated:YES];
  99. }else{
  100. GroupSynopsisVC * vc = [GroupSynopsisVC initGroupSynopsisVC];
  101. vc.GroupModel = model;
  102. vc.JoinBlock = ^{
  103. model.IsUser = YES;
  104. dispatch_async(dispatch_get_main_queue(), ^{
  105. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  106. });
  107. };
  108. vc.SendBlock = ^{
  109. model.IsApply = YES;
  110. dispatch_async(dispatch_get_main_queue(), ^{
  111. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  112. });
  113. };
  114. [self.navigationController pushViewController:vc animated:YES];
  115. }
  116. }
  117. - (void)JoinGroupIndex:(NSIndexPath *)indexPath withModel:(GroupSquareSubModel *)model
  118. {
  119. WS(weakSelf);
  120. if (model.IsAdmin) {
  121. GroupVerifyVC * vc = [GroupVerifyVC initGroupVerifyVC];
  122. vc.Id = model.Id;
  123. vc.SendBlock = ^{
  124. model.IsApply = YES;
  125. dispatch_async(dispatch_get_main_queue(), ^{
  126. [weakSelf showMessage];
  127. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  128. });
  129. };
  130. [self.navigationController pushViewController:vc animated:YES];
  131. }else{
  132. NSDictionary * paraDict = @{@"GroupId":@(model.Id),
  133. @"UserIds":@[@([AppUserModel sharedAppUserModel].Id)],
  134. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  135. @"SourceType":@(1)///申请
  136. };
  137. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Insert_User) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  138. model.IsUser = YES;
  139. dispatch_async(dispatch_get_main_queue(), ^{
  140. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  141. });
  142. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  143. vc.GroupId = model.Id;
  144. vc.titleStr = model.Name;
  145. [weakSelf.navigationController pushViewController:vc animated:YES];
  146. } failure:^(NSError * _Nonnull error) {
  147. SHOWERROR([ZYCTool handerResultData:error]);
  148. }];
  149. }
  150. }
  151. - (void)showMessage
  152. {
  153. WS(weakSelf);
  154. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"您的申请已提交,请耐心等候!" preferredStyle:UIAlertControllerStyleAlert];
  155. UIAlertAction *noOk = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  156. }];
  157. [noOk setValue:UIColorHex(0x0F7FD9) forKey:@"_titleTextColor"];
  158. [alertVC addAction:noOk];
  159. [weakSelf presentViewController:alertVC animated:YES completion:nil];
  160. }
  161. @end