HomeWeiCousreVC.m 5.9 KB

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