HomeWeiCousreVC.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  80. HomeSubModel *model = [HomeSubModel modelWithDictionary:responseObject];
  81. for (NSDictionary * dict in model.Items) {
  82. HomeSubItemModel *smodel = [HomeSubItemModel modelWithDictionary:dict];
  83. [weakSelf.dataSource addObject:smodel];
  84. }
  85. weakSelf.Total = model.Total;
  86. }
  87. [weakSelf.tableView.mj_footer endRefreshing];
  88. dispatch_async(dispatch_get_main_queue(), ^{
  89. [weakSelf.tableView reloadData];
  90. });
  91. } failure:^(NSError * _Nonnull error) {
  92. }];
  93. }
  94. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  95. {
  96. return 1;
  97. }
  98. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  99. {
  100. return self.dataSource.count;
  101. }
  102. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  103. {
  104. return UITableViewAutomaticDimension;
  105. }
  106. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  107. {
  108. HomeSubItemModel *model = self.dataSource[indexPath.row];
  109. HomeWeiCousreCell * cell = [HomeWeiCousreCell configCell0:tableView indexPath:indexPath];
  110. if (indexPath.row == 0) {
  111. cell.height.constant = 11.f;
  112. }else{
  113. cell.height.constant = 0.f;
  114. }
  115. [cell setDataWithModel:model];
  116. return cell;
  117. }
  118. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  119. {
  120. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  121. HomeSubItemModel *model = self.dataSource[indexPath.row];
  122. switch ((CollectModelType)model.MediaType) {
  123. case CollectModel_StoreBook:
  124. {
  125. BookListDetailVC * vc = [BookListDetailVC initBookListDetailVC];
  126. vc.Id = model.Id;
  127. [self.navigationController pushViewController:vc animated:YES];
  128. }
  129. break;
  130. case CollectModel_StoreVideo:
  131. {
  132. BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
  133. vc.Id = model.Id;
  134. [self.navigationController pushViewController:vc animated:YES];
  135. }
  136. break;
  137. case CollectModel_StoreSound:
  138. {
  139. BookListenVC * vc = [BookListenVC initBookListenVC];
  140. vc.Id = model.Id;
  141. vc.MediaType = MediaMusicType;
  142. [self.navigationController pushViewController:vc animated:YES];
  143. }
  144. break;
  145. case CollectModel_Teacher:
  146. {
  147. BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC];
  148. vc.Id = model.Id;
  149. [self.navigationController pushViewController:vc animated:YES];
  150. }
  151. break;
  152. case CollectModel_Organization:
  153. {
  154. HomeSCDetailVC * vc = [[HomeSCDetailVC alloc] init];
  155. vc.Id = model.Id;
  156. [self.navigationController pushViewController:vc animated:YES];
  157. }
  158. break;
  159. case CollectModel_MediaAritle:
  160. {
  161. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  162. vc.type = CollectModel_MediaAritle;
  163. vc.Id = model.Id;
  164. [self.navigationController pushViewController:vc animated:YES];
  165. }
  166. break;
  167. default:
  168. {
  169. }
  170. break;
  171. }
  172. }
  173. @end