GroupSquareVC.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. @interface GroupSquareVC ()<UITableViewDelegate,UITableViewDataSource>
  15. @property (weak, nonatomic) IBOutlet UITableView *leftTable;
  16. @property (weak, nonatomic) IBOutlet UITableView *rightTable;
  17. @property (weak, nonatomic) IBOutlet UIView *HeadView;
  18. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *height;
  19. @property (strong, nonatomic) MyTDGroupView *SearchView;
  20. @property (copy, nonatomic) NSMutableArray *leftArray;
  21. @property (copy, nonatomic) NSMutableArray *rightArray;
  22. @end
  23. @implementation GroupSquareVC
  24. +(GroupSquareVC *)initGroupSquareVC{
  25. GroupSquareVC *controller = [StoryboardManager.shared.Source instantiateViewControllerWithIdentifier:@"GroupSquareVC"];
  26. return controller;
  27. }
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. self.fd_prefersNavigationBarHidden = YES;
  31. [self.HeadView addSubview:self.SearchView];
  32. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.top.mas_offset(6);
  34. make.left.right.mas_equalTo(self.HeadView);
  35. make.height.mas_offset(36);
  36. }];
  37. [self.SearchView.button setAction:^{
  38. NSLog(@"SearchView.button");
  39. }];
  40. self.leftTable.delegate = self;
  41. self.leftTable.dataSource = self;
  42. self.leftTable.showsHorizontalScrollIndicator = NO;
  43. self.leftTable.showsVerticalScrollIndicator = NO;
  44. self.rightTable.delegate = self;
  45. self.rightTable.dataSource = self;
  46. self.leftTable.estimatedRowHeight = 0;
  47. self.leftTable.estimatedSectionHeaderHeight = 0;
  48. self.leftTable.estimatedSectionFooterHeight = 0;
  49. self.rightTable.estimatedRowHeight = 0;
  50. self.rightTable.estimatedSectionHeaderHeight = 0;
  51. self.rightTable.estimatedSectionFooterHeight = 0;
  52. [self getData];
  53. }
  54. - (void)getData
  55. {
  56. WS(weakSelf);
  57. [self.leftArray removeAllObjects];
  58. NSString * url = [NSString stringWithFormat:@"%@%@",Host(API_APP_GROUP_Group_Category),@"0"];
  59. [[HttpManager sharedHttpManager] GET:url parameters:@{} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  60. NSLog(@"%@",responseObject);
  61. if ([responseObject isKindOfClass:[NSArray class]]) {
  62. NSArray * array = responseObject;
  63. for (NSInteger i = 0; i < array.count; i ++) {
  64. GroupSquareModel * model = [GroupSquareModel modelWithDictionary:array[i]];
  65. model.isSelect = i == 0 ? YES : NO;
  66. [weakSelf.leftArray addObject:model];
  67. }
  68. GroupSquareModel * fmodel = weakSelf.leftArray.firstObject;
  69. [weakSelf getSubData:fmodel.Id];
  70. }
  71. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  72. }];
  73. }
  74. - (void)getSubData:(NSInteger)listID
  75. {
  76. WS(weakSelf);
  77. [self.rightArray removeAllObjects];
  78. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(API_APP_GROUP_Category_list),listID];
  79. [[HttpManager sharedHttpManager] GET:url parameters:@{} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  80. NSArray * array = responseObject;
  81. NSLog(@"====== %ld",array.count);
  82. for (NSInteger i = 0; i < array.count; i ++) {
  83. GroupSquareSubModel * model = [GroupSquareSubModel modelWithDictionary:array[i]];
  84. [weakSelf.rightArray addObject:model];
  85. }
  86. dispatch_async(dispatch_get_main_queue(), ^{
  87. [weakSelf reloadData];
  88. });
  89. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  90. }];
  91. }
  92. - (void)reloadData
  93. {
  94. [self.leftTable reloadData];
  95. [self.rightTable reloadData];
  96. }
  97. #pragma mark -UITableViewDelegate
  98. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  99. {
  100. if (tableView == self.leftTable) {
  101. return self.leftArray.count;
  102. }else{
  103. return self.rightArray.count;
  104. }
  105. }
  106. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  107. {
  108. if (tableView == self.leftTable) {
  109. return [GroupSquareCell configCell0Height];
  110. }else{
  111. return [GroupSquareCell configCell1Height];
  112. }
  113. }
  114. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  115. {
  116. if (tableView == self.leftTable) {
  117. GroupSquareModel * model = [self.leftArray objectAtIndex:indexPath.row];
  118. GroupSquareCell * cell = [GroupSquareCell configCell0:tableView indexPath:indexPath];
  119. [cell setLeftDataModel:model];
  120. return cell;
  121. }else{
  122. GroupSquareSubModel * model = [self.rightArray objectAtIndex:indexPath.row];
  123. GroupSquareCell * cell = [GroupSquareCell configCell1:tableView indexPath:indexPath];
  124. [cell setRightDataSubModel:model];
  125. return cell;
  126. }
  127. }
  128. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  129. {
  130. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  131. if (tableView == self.leftTable) {
  132. GroupSquareModel * model = [self.leftArray objectAtIndex:indexPath.row];
  133. if (!model.isSelect) {
  134. [self.leftArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  135. GroupSquareModel * smodel = (GroupSquareModel *)obj;
  136. smodel.isSelect = NO;
  137. }];
  138. model.isSelect = !model.isSelect;
  139. if (indexPath.row == 0) {
  140. self.height.constant = 0.f;
  141. }else{
  142. self.height.constant = 19.f;
  143. }
  144. [self getSubData:model.Id];
  145. }
  146. }else{
  147. GroupSquareSubModel * model = [self.rightArray objectAtIndex:indexPath.row];
  148. GroupSynopsisVC * vc = [GroupSynopsisVC initGroupSynopsisVC];
  149. vc.GroupId = model.Id;
  150. [self.navigationController pushViewController:vc animated:YES];
  151. }
  152. }
  153. #pragma mark - Load On Demand
  154. - (NSMutableArray *)leftArray
  155. {
  156. if (!_leftArray) {
  157. _leftArray = [NSMutableArray array];
  158. }
  159. return _leftArray;
  160. }
  161. - (NSMutableArray *)rightArray
  162. {
  163. if (!_rightArray) {
  164. _rightArray = [NSMutableArray array];
  165. }
  166. return _rightArray;
  167. }
  168. - (MyTDGroupView *)SearchView
  169. {
  170. if (!_SearchView) {
  171. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  172. }
  173. return _SearchView;
  174. }
  175. @end