HomeBigshotVC.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // HomeBigshotVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/6/23.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "HomeBigshotVC.h"
  9. #import "HomeSubModel.h"
  10. #import "HomeSubItemModel.h"
  11. #import "HomeBigshotCell.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 HomeBigshotVC ()<UITableViewDelegate,UITableViewDataSource>
  19. @property (nonatomic, strong) UITableView * tableView;
  20. @property (nonatomic, strong) NSMutableArray * dataSource;
  21. @property (nonatomic, strong) NSMutableArray * moreArray;
  22. @property (nonatomic, assign) NSInteger currentPage;
  23. @property (nonatomic, assign) NSInteger Total;
  24. @end
  25. @implementation HomeBigshotVC
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. [self.view addSubview:self.tableView];
  29. self.tableView.delegate = self;
  30. self.tableView.dataSource = self;
  31. WS(weakSelf);
  32. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  33. [weakSelf footerRefresh];
  34. }];
  35. [self headRefresh];
  36. }
  37. - (void)setHeight:(CGFloat)height
  38. {
  39. [self.tableView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, height - 45)];
  40. }
  41. - (UITableView *)tableView
  42. {
  43. if (!_tableView) {
  44. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  45. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  46. _tableView.showsVerticalScrollIndicator = NO;
  47. }
  48. return _tableView;
  49. }
  50. - (NSMutableArray *)dataSource
  51. {
  52. if (!_dataSource) {
  53. _dataSource = [NSMutableArray array];
  54. }
  55. return _dataSource;
  56. }
  57. - (NSMutableArray *)moreArray
  58. {
  59. if (!_moreArray) {
  60. _moreArray = [NSMutableArray array];
  61. }
  62. return _moreArray;
  63. }
  64. - (void)headRefresh{
  65. self.currentPage = 1;
  66. self.Total = 0;
  67. [self.dataSource removeAllObjects];
  68. [self.moreArray removeAllObjects];
  69. [self getData];
  70. }
  71. - (void)footerRefresh{
  72. self.currentPage += 1;
  73. if (self.Total == self.dataSource.count) {
  74. self.currentPage --;
  75. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  76. self.tableView.mj_footer.hidden = YES;
  77. return ;
  78. }
  79. [self getMoreData];
  80. }
  81. - (void)getData
  82. {
  83. WS(weakSelf);
  84. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_CATHEDRA) parameters:@{@"StyleCss":self.style,@"Page":@(self.currentPage),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  85. NSLog(@"%@",responseObject);
  86. if ([responseObject isKindOfClass:[NSArray class]]) {
  87. NSArray * array = responseObject;
  88. for (NSDictionary * dict in array) {
  89. HomeSubModel *model = [HomeSubModel modelWithDictionary:dict];
  90. NSMutableArray * mArray = [NSMutableArray array];
  91. for (NSDictionary * mdict in model.Items) {
  92. HomeSubItemModel *mmodel = [HomeSubItemModel modelWithDictionary:mdict];
  93. [mArray addObject:mmodel];
  94. }
  95. model.Items = mArray.mutableCopy;
  96. model.LabelName = @"今日推荐";
  97. [weakSelf.dataSource addObject:model];
  98. }
  99. [weakSelf getMoreData];
  100. }
  101. } failure:^(NSError * _Nonnull error) {
  102. }];
  103. }
  104. - (void)getMoreData
  105. {
  106. WS(weakSelf);
  107. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_CATHEDRA_Page) parameters:@{@"Page":@(self.currentPage),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  108. NSLog(@"%@",responseObject);
  109. [weakSelf.tableView.mj_footer endRefreshing];
  110. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  111. for (NSDictionary * dict in responseObject[@"Items"]) {
  112. HomeSubItemModel *model = [HomeSubItemModel modelWithDictionary:dict];
  113. [weakSelf.moreArray addObject:model];
  114. }
  115. weakSelf.Total = [responseObject[@"Total"] integerValue];
  116. }
  117. if (weakSelf.Total == weakSelf.moreArray.count) {
  118. [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
  119. weakSelf.tableView.mj_footer.hidden = YES;
  120. }
  121. dispatch_async(dispatch_get_main_queue(), ^{
  122. [weakSelf.tableView reloadData];
  123. });
  124. } failure:^(NSError * _Nonnull error) {
  125. }];
  126. }
  127. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  128. {
  129. return 1;
  130. }
  131. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  132. {
  133. return 2;
  134. }
  135. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  136. {
  137. return UITableViewAutomaticDimension;
  138. }
  139. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  140. {
  141. WS(weakSelf);
  142. if (indexPath.row == 0) {
  143. HomeSubModel *model = self.dataSource.firstObject;
  144. HomeBigshotCell * cell = [HomeBigshotCell configCell0:tableView indexPath:indexPath];
  145. [cell setDatatype:0 model:model];
  146. cell.ClickItemBlock = ^(HomeSubItemModel * _Nonnull pmodel) {
  147. [weakSelf pushVC:pmodel];
  148. };
  149. return cell;
  150. }else{
  151. HomeSubModel *model = [[HomeSubModel alloc] init];
  152. model.LabelName = @"更多精彩";
  153. model.Items = self.moreArray.mutableCopy;
  154. HomeBigshotCell * cell = [HomeBigshotCell configCell1:tableView indexPath:indexPath];
  155. [cell setDatatype:1 model:model];
  156. cell.ClickItemBlock = ^(HomeSubItemModel * _Nonnull pmodel) {
  157. [weakSelf pushVC:pmodel];
  158. };
  159. return cell;
  160. }
  161. }
  162. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  163. {
  164. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  165. }
  166. - (void)pushVC:(HomeSubItemModel *)model
  167. {
  168. switch ((CollectModelType)model.MediaType) {
  169. case CollectModel_StoreBook:
  170. {
  171. BookListDetailVC * vc = [BookListDetailVC initBookListDetailVC];
  172. vc.Id = model.Id;
  173. [self.navigationController pushViewController:vc animated:YES];
  174. }
  175. break;
  176. case CollectModel_StoreVideo:
  177. {
  178. BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
  179. vc.Id = model.Id;
  180. [self.navigationController pushViewController:vc animated:YES];
  181. }
  182. break;
  183. case CollectModel_StoreSound:
  184. {
  185. BookListenVC * vc = [BookListenVC initBookListenVC];
  186. vc.Id = model.Id;
  187. vc.MediaType = MediaMusicType;
  188. [self.navigationController pushViewController:vc animated:YES];
  189. }
  190. break;
  191. case CollectModel_Teacher:
  192. {
  193. BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC];
  194. vc.Id = model.Id;
  195. [self.navigationController pushViewController:vc animated:YES];
  196. }
  197. break;
  198. case CollectModel_Organization:
  199. {
  200. HomeSCDetailVC * vc = [[HomeSCDetailVC alloc] init];
  201. vc.Id = model.Id;
  202. [self.navigationController pushViewController:vc animated:YES];
  203. }
  204. break;
  205. case CollectModel_MediaAritle:
  206. {
  207. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  208. vc.type = CollectModel_MediaAritle;
  209. vc.Id = model.Id;
  210. [self.navigationController pushViewController:vc animated:YES];
  211. }
  212. break;
  213. default:
  214. {
  215. }
  216. break;
  217. }
  218. }
  219. @end