GroupSquareVC.m 6.4 KB

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