GroupSquareVC.m 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. //
  2. // GroupSquareVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/5/6.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "GroupSquareVC.h"
  9. #import "GroupSquareModel.h"
  10. #import "GroupSquareSubModel.h"
  11. #import "GroupSquareCell.h"
  12. #import "MyTDGroupView.h"
  13. #import "GroupSynopsisVC.h"
  14. #import "GroupSquareSearchVC.h"
  15. #import "TDGroupInfoListVC.h"
  16. #import "GroupVerifyVC.h"
  17. @interface GroupSquareVC ()<UITableViewDelegate,UITableViewDataSource>
  18. @property (weak, nonatomic) IBOutlet UITableView *leftTable;
  19. @property (weak, nonatomic) IBOutlet UITableView *rightTable;
  20. @property (weak, nonatomic) IBOutlet UIView *HeadView;
  21. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *height;
  22. @property (strong, nonatomic) MyTDGroupView *SearchView;
  23. @property (copy, nonatomic) NSMutableArray *leftArray;
  24. @property (copy, nonatomic) NSMutableArray *rightArray;
  25. @property (assign, nonatomic) NSInteger leftId;
  26. @end
  27. @implementation GroupSquareVC
  28. +(GroupSquareVC *)initGroupSquareVC{
  29. GroupSquareVC *controller = [StoryboardManager.shared.Source instantiateViewControllerWithIdentifier:@"GroupSquareVC"];
  30. return controller;
  31. }
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. self.fd_prefersNavigationBarHidden = YES;
  35. [self.HeadView addSubview:self.SearchView];
  36. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.mas_offset(6);
  38. make.left.right.mas_equalTo(self.HeadView);
  39. make.height.mas_offset(36);
  40. }];
  41. WS(weakSelf);
  42. [self.SearchView.button setAction:^{
  43. GroupSquareSearchVC * vc = [[GroupSquareSearchVC alloc] init];
  44. [weakSelf.navigationController pushViewController:vc animated:YES];
  45. }];
  46. self.leftTable.delegate = self;
  47. self.leftTable.dataSource = self;
  48. self.leftTable.showsHorizontalScrollIndicator = NO;
  49. self.leftTable.showsVerticalScrollIndicator = NO;
  50. self.rightTable.delegate = self;
  51. self.rightTable.dataSource = self;
  52. self.leftTable.estimatedRowHeight = 0;
  53. self.leftTable.estimatedSectionHeaderHeight = 0;
  54. self.leftTable.estimatedSectionFooterHeight = 0;
  55. self.rightTable.estimatedRowHeight = 0;
  56. self.rightTable.estimatedSectionHeaderHeight = 0;
  57. self.rightTable.estimatedSectionFooterHeight = 0;
  58. [self getData];
  59. }
  60. - (void)getData
  61. {
  62. WS(weakSelf);
  63. [self.leftArray removeAllObjects];
  64. NSString * url = [NSString stringWithFormat:@"%@%@",Host(API_APP_GROUP_Group_Category),@"0"];
  65. [[HttpManager sharedHttpManager] GET:url parameters:@{} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  66. NSLog(@"%@",responseObject);
  67. if ([responseObject isKindOfClass:[NSArray class]]) {
  68. NSArray * array = responseObject;
  69. for (NSInteger i = 0; i < array.count; i ++) {
  70. GroupSquareModel * model = [GroupSquareModel modelWithDictionary:array[i]];
  71. model.isSelect = i == 0 ? YES : NO;
  72. [weakSelf.leftArray addObject:model];
  73. }
  74. GroupSquareModel * fmodel = weakSelf.leftArray.firstObject;
  75. weakSelf.leftId = fmodel.Id;
  76. [weakSelf getSubData:fmodel.Id];
  77. }
  78. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  79. }];
  80. }
  81. - (void)getSubData:(NSInteger)listID
  82. {
  83. WS(weakSelf);
  84. [self.rightArray removeAllObjects];
  85. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(API_APP_GROUP_Category_list),listID];
  86. [[HttpManager sharedHttpManager] GETUrl:url parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  87. if ([responseObject isKindOfClass:[NSArray class]]) {
  88. for (NSDictionary * dict in responseObject) {
  89. GroupSquareSubModel * model = [GroupSquareSubModel modelWithDictionary:dict];
  90. [weakSelf.rightArray addObject:model];
  91. }
  92. }
  93. dispatch_async(dispatch_get_main_queue(), ^{
  94. [weakSelf reloadData];
  95. });
  96. } failure:^(NSError * _Nonnull error) {
  97. }];
  98. }
  99. - (void)reloadData
  100. {
  101. [self.leftTable reloadData];
  102. [self.rightTable reloadData];
  103. }
  104. #pragma mark -UITableViewDelegate
  105. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  106. {
  107. if (tableView == self.leftTable) {
  108. return self.leftArray.count;
  109. }else{
  110. return self.rightArray.count;
  111. }
  112. }
  113. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  114. {
  115. if (tableView == self.leftTable) {
  116. return [GroupSquareCell configCell0Height];
  117. }else{
  118. return [GroupSquareCell configCell1Height];
  119. }
  120. }
  121. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  122. {
  123. if (tableView == self.leftTable) {
  124. GroupSquareModel * model = [self.leftArray objectAtIndex:indexPath.row];
  125. GroupSquareCell * cell = [GroupSquareCell configCell0:tableView indexPath:indexPath];
  126. [cell setLeftDataModel:model];
  127. return cell;
  128. }else{
  129. GroupSquareSubModel * model = [self.rightArray objectAtIndex:indexPath.row];
  130. GroupSquareCell * cell = [GroupSquareCell configCell1:tableView indexPath:indexPath];
  131. [cell setRightDataSubModel:model];
  132. WS(weakSelf);
  133. [cell.JoinBtn setAction:^{
  134. [weakSelf JoinGroupIndex:indexPath withModel:model];
  135. }];
  136. return cell;
  137. }
  138. }
  139. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  140. {
  141. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  142. if (tableView == self.leftTable) {
  143. GroupSquareModel * model = [self.leftArray objectAtIndex:indexPath.row];
  144. if (!model.isSelect) {
  145. [self.leftArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  146. GroupSquareModel * smodel = (GroupSquareModel *)obj;
  147. smodel.isSelect = NO;
  148. }];
  149. model.isSelect = !model.isSelect;
  150. if (indexPath.row == 0) {
  151. self.height.constant = 0.f;
  152. }else{
  153. self.height.constant = 19.f;
  154. }
  155. self.leftId = model.Id;
  156. [self getSubData:model.Id];
  157. }
  158. }else{
  159. WS(weakSelf);
  160. GroupSquareSubModel * model = [self.rightArray objectAtIndex:indexPath.row];
  161. if (model.IsUser) {
  162. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  163. vc.GroupId = model.Id;
  164. vc.titleStr = model.Name;
  165. [self.navigationController pushViewController:vc animated:YES];
  166. }else{
  167. GroupSynopsisVC * vc = [GroupSynopsisVC initGroupSynopsisVC];
  168. vc.GroupModel = model;
  169. vc.JoinBlock = ^{
  170. model.IsUser = YES;
  171. dispatch_async(dispatch_get_main_queue(), ^{
  172. [weakSelf.rightTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  173. });
  174. };
  175. vc.SendBlock = ^{
  176. model.IsApply = YES;
  177. dispatch_async(dispatch_get_main_queue(), ^{
  178. [weakSelf.rightTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  179. });
  180. };
  181. [self.navigationController pushViewController:vc animated:YES];
  182. }
  183. }
  184. }
  185. - (void)JoinGroupIndex:(NSIndexPath *)indexPath withModel:(GroupSquareSubModel *)model
  186. {
  187. WS(weakSelf);
  188. if (model.IsAdmin) {
  189. GroupVerifyVC * vc = [GroupVerifyVC initGroupVerifyVC];
  190. vc.Id = model.Id;
  191. vc.SendBlock = ^{
  192. model.IsApply = YES;
  193. dispatch_async(dispatch_get_main_queue(), ^{
  194. [weakSelf showMessage];
  195. [weakSelf.rightTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  196. });
  197. };
  198. [self.navigationController pushViewController:vc animated:YES];
  199. }else{
  200. NSDictionary * paraDict = @{@"GroupId":@(model.Id),
  201. @"UserIds":@[@([AppUserModel sharedAppUserModel].Id)],
  202. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  203. @"SourceType":@(1)///申请
  204. };
  205. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Insert_User) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  206. model.IsUser = YES;
  207. dispatch_async(dispatch_get_main_queue(), ^{
  208. [weakSelf.rightTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  209. });
  210. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  211. vc.GroupId = model.Id;
  212. vc.titleStr = model.Name;
  213. [weakSelf.navigationController pushViewController:vc animated:YES];
  214. } failure:^(NSError * _Nonnull error) {
  215. SHOWERROR([ZYCTool handerResultData:error]);
  216. }];
  217. }
  218. }
  219. - (void)showMessage
  220. {
  221. WS(weakSelf);
  222. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"您的申请已提交,请耐心等候!" preferredStyle:UIAlertControllerStyleAlert];
  223. UIAlertAction *noOk = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  224. }];
  225. [noOk setValue:UIColorHex(0x0F7FD9) forKey:@"_titleTextColor"];
  226. [alertVC addAction:noOk];
  227. [weakSelf presentViewController:alertVC animated:YES completion:nil];
  228. }
  229. #pragma mark - Load On Demand
  230. - (NSMutableArray *)leftArray
  231. {
  232. if (!_leftArray) {
  233. _leftArray = [NSMutableArray array];
  234. }
  235. return _leftArray;
  236. }
  237. - (NSMutableArray *)rightArray
  238. {
  239. if (!_rightArray) {
  240. _rightArray = [NSMutableArray array];
  241. }
  242. return _rightArray;
  243. }
  244. - (MyTDGroupView *)SearchView
  245. {
  246. if (!_SearchView) {
  247. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  248. }
  249. return _SearchView;
  250. }
  251. @end