GroupSquareVC.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. @interface GroupSquareVC ()<UITableViewDelegate,UITableViewDataSource>
  17. @property (weak, nonatomic) IBOutlet UITableView *leftTable;
  18. @property (weak, nonatomic) IBOutlet UITableView *rightTable;
  19. @property (weak, nonatomic) IBOutlet UIView *HeadView;
  20. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *height;
  21. @property (strong, nonatomic) MyTDGroupView *SearchView;
  22. @property (copy, nonatomic) NSMutableArray *leftArray;
  23. @property (copy, nonatomic) NSMutableArray *rightArray;
  24. @property (assign, nonatomic) NSInteger leftId;
  25. @end
  26. @implementation GroupSquareVC
  27. +(GroupSquareVC *)initGroupSquareVC{
  28. GroupSquareVC *controller = [StoryboardManager.shared.Source instantiateViewControllerWithIdentifier:@"GroupSquareVC"];
  29. return controller;
  30. }
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. self.fd_prefersNavigationBarHidden = YES;
  34. [self.HeadView addSubview:self.SearchView];
  35. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.top.mas_offset(6);
  37. make.left.right.mas_equalTo(self.HeadView);
  38. make.height.mas_offset(36);
  39. }];
  40. WS(weakSelf);
  41. [self.SearchView.button setAction:^{
  42. GroupSquareSearchVC * vc = [[GroupSquareSearchVC alloc] init];
  43. [weakSelf.navigationController pushViewController:vc animated:YES];
  44. }];
  45. self.leftTable.delegate = self;
  46. self.leftTable.dataSource = self;
  47. self.leftTable.showsHorizontalScrollIndicator = NO;
  48. self.leftTable.showsVerticalScrollIndicator = NO;
  49. self.rightTable.delegate = self;
  50. self.rightTable.dataSource = self;
  51. self.leftTable.estimatedRowHeight = 0;
  52. self.leftTable.estimatedSectionHeaderHeight = 0;
  53. self.leftTable.estimatedSectionFooterHeight = 0;
  54. self.rightTable.estimatedRowHeight = 0;
  55. self.rightTable.estimatedSectionHeaderHeight = 0;
  56. self.rightTable.estimatedSectionFooterHeight = 0;
  57. [self getData];
  58. }
  59. - (void)getData
  60. {
  61. WS(weakSelf);
  62. [self.leftArray removeAllObjects];
  63. NSString * url = [NSString stringWithFormat:@"%@%@",Host(API_APP_GROUP_Group_Category),@"0"];
  64. [[HttpManager sharedHttpManager] GET:url parameters:@{} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  65. NSLog(@"%@",responseObject);
  66. if ([responseObject isKindOfClass:[NSArray class]]) {
  67. NSArray * array = responseObject;
  68. for (NSInteger i = 0; i < array.count; i ++) {
  69. GroupSquareModel * model = [GroupSquareModel modelWithDictionary:array[i]];
  70. model.isSelect = i == 0 ? YES : NO;
  71. [weakSelf.leftArray addObject:model];
  72. }
  73. GroupSquareModel * fmodel = weakSelf.leftArray.firstObject;
  74. weakSelf.leftId = fmodel.Id;
  75. [weakSelf getSubData:fmodel.Id];
  76. }
  77. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  78. }];
  79. }
  80. - (void)getSubData:(NSInteger)listID
  81. {
  82. WS(weakSelf);
  83. [self.rightArray removeAllObjects];
  84. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(API_APP_GROUP_Category_list),listID];
  85. [[HttpManager sharedHttpManager] GETUrl:url parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  86. if ([responseObject isKindOfClass:[NSArray class]]) {
  87. for (NSDictionary * dict in responseObject) {
  88. GroupSquareSubModel * model = [GroupSquareSubModel modelWithDictionary:dict];
  89. [weakSelf.rightArray addObject:model];
  90. }
  91. }
  92. dispatch_async(dispatch_get_main_queue(), ^{
  93. [weakSelf reloadData];
  94. });
  95. } failure:^(NSError * _Nonnull error) {
  96. }];
  97. }
  98. - (void)reloadData
  99. {
  100. [self.leftTable reloadData];
  101. [self.rightTable reloadData];
  102. }
  103. #pragma mark -UITableViewDelegate
  104. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  105. {
  106. if (tableView == self.leftTable) {
  107. return self.leftArray.count;
  108. }else{
  109. return self.rightArray.count;
  110. }
  111. }
  112. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. if (tableView == self.leftTable) {
  115. return [GroupSquareCell configCell0Height];
  116. }else{
  117. return [GroupSquareCell configCell1Height];
  118. }
  119. }
  120. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  121. {
  122. if (tableView == self.leftTable) {
  123. GroupSquareModel * model = [self.leftArray objectAtIndex:indexPath.row];
  124. GroupSquareCell * cell = [GroupSquareCell configCell0:tableView indexPath:indexPath];
  125. [cell setLeftDataModel:model];
  126. return cell;
  127. }else{
  128. GroupSquareSubModel * model = [self.rightArray objectAtIndex:indexPath.row];
  129. GroupSquareCell * cell = [GroupSquareCell configCell1:tableView indexPath:indexPath];
  130. [cell setRightDataSubModel:model];
  131. WS(weakSelf);
  132. [cell.JoinBtn setAction:^{
  133. [weakSelf JoinGroupIndex:indexPath withModel:model];
  134. }];
  135. return cell;
  136. }
  137. }
  138. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  139. {
  140. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  141. if (tableView == self.leftTable) {
  142. GroupSquareModel * model = [self.leftArray objectAtIndex:indexPath.row];
  143. if (!model.isSelect) {
  144. [self.leftArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  145. GroupSquareModel * smodel = (GroupSquareModel *)obj;
  146. smodel.isSelect = NO;
  147. }];
  148. model.isSelect = !model.isSelect;
  149. if (indexPath.row == 0) {
  150. self.height.constant = 0.f;
  151. }else{
  152. self.height.constant = 19.f;
  153. }
  154. self.leftId = model.Id;
  155. [self getSubData:model.Id];
  156. }
  157. }else{
  158. GroupSquareSubModel * model = [self.rightArray objectAtIndex:indexPath.row];
  159. if (model.IsUser) {
  160. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  161. vc.GroupId = model.Id;
  162. vc.titleStr = model.Name;
  163. [self.navigationController pushViewController:vc animated:YES];
  164. }else{
  165. GroupSynopsisVC * vc = [GroupSynopsisVC initGroupSynopsisVC];
  166. vc.GroupId = model.Id;
  167. if (!model.IsUser && !model.IsApply) {
  168. vc.IsJoin = NO;
  169. }else{
  170. vc.IsJoin = YES;
  171. }
  172. [self.navigationController pushViewController:vc animated:YES];
  173. }
  174. }
  175. }
  176. - (void)JoinGroupIndex:(NSIndexPath *)indexPath withModel:(GroupSquareSubModel *)model
  177. {
  178. WS(weakSelf);
  179. NSDictionary * paraDict = @{@"GroupId":@(model.Id),
  180. @"UserIds":@[@([AppUserModel sharedAppUserModel].Id)],
  181. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  182. @"SourceType":@(1)///申请
  183. };
  184. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Group_Insert_User) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  185. SHOWSUCCESS(responseObject[@"Msg"]);
  186. if ([responseObject[@"Code"] integerValue] == 200) {
  187. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  188. vc.GroupId = model.Id;
  189. vc.titleStr = model.Name;
  190. [weakSelf.navigationController pushViewController:vc animated:YES];
  191. }
  192. [weakSelf getSubData:weakSelf.leftId];
  193. } failure:^(NSError * _Nonnull error) {
  194. SHOWERROR([ZYCTool handerResultData:error]);
  195. }];
  196. }
  197. #pragma mark - Load On Demand
  198. - (NSMutableArray *)leftArray
  199. {
  200. if (!_leftArray) {
  201. _leftArray = [NSMutableArray array];
  202. }
  203. return _leftArray;
  204. }
  205. - (NSMutableArray *)rightArray
  206. {
  207. if (!_rightArray) {
  208. _rightArray = [NSMutableArray array];
  209. }
  210. return _rightArray;
  211. }
  212. - (MyTDGroupView *)SearchView
  213. {
  214. if (!_SearchView) {
  215. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  216. }
  217. return _SearchView;
  218. }
  219. @end