IndexAllVC.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //
  2. // IndexAllVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/9/17.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "IndexAllVC.h"
  9. #import "IndexAllCell.h"
  10. #import "IndexAllModel.h"
  11. #import "HomeSubItemModel.h"
  12. #import "BookTeacherDetailVC.h"
  13. #import "BookWCDetailVC.h"
  14. #import "BookListenVC.h"
  15. #import "BookListDetailVC.h"
  16. #import "IndexMoreVC.h"
  17. #import "HomeSCDetailVC.h"
  18. @interface IndexAllVC ()<UITableViewDelegate,UITableViewDataSource>
  19. @property (nonatomic, strong) UITableView * tableView;
  20. @property (nonatomic, strong) NSMutableArray * dataArray;
  21. @end
  22. @implementation IndexAllVC
  23. - (NSMutableArray *)dataArray
  24. {
  25. if (!_dataArray) {
  26. _dataArray = [NSMutableArray array];
  27. }
  28. return _dataArray;
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. self.view.backgroundColor = UIColorHex(0xF8F8F8);
  33. [self.view addSubview:self.tableView];
  34. self.tableView.showsVerticalScrollIndicator = NO;
  35. self.tableView.backgroundColor = [UIColor clearColor];
  36. self.tableView.delegate = self;
  37. self.tableView.dataSource = self;
  38. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.edges.mas_offset(UIEdgeInsetsMake(20,15,(IS_IPHONEX ? 40 : 20) + EMVIEWBOTTOMMARGIN + 50,15));
  40. }];
  41. }
  42. - (void)getData
  43. {
  44. WS(weakSelf);
  45. [self.dataArray removeAllObjects];
  46. SHOWLOADING
  47. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_Page_Search) parameters:@{@"keyword":self.searchText} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  48. REMOVESHOW
  49. NSLog(@"%@",responseObject);
  50. if ([responseObject isKindOfClass:[NSArray class]]) {
  51. for (NSDictionary * dict in responseObject) {
  52. IndexAllModel * model = [IndexAllModel modelWithDictionary:dict];
  53. NSMutableArray * array = [NSMutableArray array];
  54. for (NSDictionary * subDict in model.Items) {
  55. HomeSubItemModel * subModel = [HomeSubItemModel modelWithDictionary:subDict];
  56. [array addObject:subModel];
  57. }
  58. model.Items = array.mutableCopy;
  59. [weakSelf.dataArray addObject:model];
  60. }
  61. }
  62. dispatch_async(dispatch_get_main_queue(), ^{
  63. [weakSelf.tableView reloadData];
  64. });
  65. } failure:^(NSError * _Nonnull error) {
  66. REMOVESHOW
  67. }];
  68. }
  69. - (UITableView *)tableView
  70. {
  71. if (!_tableView) {
  72. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  73. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  74. }
  75. return _tableView;
  76. }
  77. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  78. {
  79. return 14.f;
  80. }
  81. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  82. {
  83. return 0.01f;
  84. }
  85. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  86. {
  87. UIView * view = [UIView new];
  88. return view;
  89. }
  90. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  91. {
  92. UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 14)];
  93. view.backgroundColor = UIColorHex(0xF8F8F8);
  94. return view;
  95. }
  96. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  97. {
  98. return self.dataArray.count;
  99. }
  100. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  101. {
  102. return 1;
  103. }
  104. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  105. {
  106. WS(weakSelf);
  107. IndexAllModel * model = [self.dataArray objectAtIndex:indexPath.section];
  108. IndexAllCell * cell = [IndexAllCell configCell0:tableView indexPath:indexPath];
  109. [cell setDataWithModel:model searchText:self.searchText];
  110. [cell.topBtn setAction:^{
  111. [weakSelf top:model.LableId];
  112. }];
  113. [cell.moreBtn setAction:^{
  114. [weakSelf moreWithName:model.LableName Id:model.LableId ];
  115. }];
  116. cell.ClickRowBlock = ^(CollectModelType type, NSInteger Id) {
  117. [weakSelf pushVC:type Id:Id];
  118. };
  119. return cell;
  120. }
  121. - (void)top:(NSInteger)Id
  122. {
  123. WS(weakSelf);
  124. [[HttpManager sharedHttpManager] PUTUrl:Host(API_APP_Page_System_Lable_User) parameters:@{@"SystemLableId":@(Id)} responseStyle:DATA success:^(id _Nonnull responseObject) {
  125. [weakSelf getData];
  126. } failure:^(NSError * _Nonnull error) {
  127. }];
  128. }
  129. - (void)moreWithName:(NSString *)name Id:(NSInteger)Id
  130. {
  131. IndexMoreVC * vc = [IndexMoreVC initIndexMoreVC];
  132. vc.Id = Id;
  133. vc.titleStr = name;
  134. [self.navigationController pushViewController:vc animated:YES];
  135. }
  136. - (void)pushVC:(CollectModelType)type Id:(NSInteger)Id
  137. {
  138. switch (type) {
  139. case CollectModel_StoreBook:
  140. {
  141. BookListDetailVC * vc = [BookListDetailVC initBookListDetailVC];
  142. vc.Id = Id;
  143. [self.navigationController pushViewController:vc animated:YES];
  144. }
  145. break;
  146. case CollectModel_StoreVideo:
  147. {
  148. BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
  149. vc.Id = Id;
  150. [self.navigationController pushViewController:vc animated:YES];
  151. }
  152. break;
  153. case CollectModel_StoreSound:
  154. {
  155. BookListenVC * vc = [BookListenVC initBookListenVC];
  156. vc.Id = Id;
  157. vc.MediaType = MediaMusicType;
  158. [self.navigationController pushViewController:vc animated:YES];
  159. }
  160. break;
  161. case CollectModel_Teacher:
  162. {
  163. BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC];
  164. vc.Id = Id;
  165. [self.navigationController pushViewController:vc animated:YES];
  166. }
  167. break;
  168. case CollectModel_Organization:
  169. {
  170. HomeSCDetailVC * vc = [[HomeSCDetailVC alloc] init];
  171. vc.Id = Id;
  172. [self.navigationController pushViewController:vc animated:YES];
  173. }
  174. break;
  175. default:
  176. {
  177. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  178. vc.type = type;
  179. vc.Id = Id;
  180. [self.navigationController pushViewController:vc animated:YES];
  181. }
  182. break;
  183. }
  184. }
  185. @end