HomeDayGoodBookVC.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 "HomeDayGoodBookVC.h"
  9. #import "HomeSubModel.h"
  10. #import "HomeSubItemModel.h"
  11. #import "HomeGoodBookCell.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 HomeDayGoodBookVC ()<UITableViewDelegate,UITableViewDataSource>
  19. @property (nonatomic, strong) UITableView * tableView;
  20. @property (nonatomic, strong) NSMutableArray * dataSource;
  21. @end
  22. @implementation HomeDayGoodBookVC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self.view addSubview:self.tableView];
  26. self.tableView.delegate = self;
  27. self.tableView.dataSource = self;
  28. [self getData];
  29. }
  30. - (void)setHeight:(CGFloat)height
  31. {
  32. [self.tableView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, height - 45)];
  33. }
  34. - (UITableView *)tableView
  35. {
  36. if (!_tableView) {
  37. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  38. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  39. _tableView.showsVerticalScrollIndicator = NO;
  40. }
  41. return _tableView;
  42. }
  43. - (NSMutableArray *)dataSource
  44. {
  45. if (!_dataSource) {
  46. _dataSource = [NSMutableArray array];
  47. }
  48. return _dataSource;
  49. }
  50. - (void)getData
  51. {
  52. WS(weakSelf);
  53. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_CATHEDRA) parameters:@{@"StyleCss":self.style,@"Page":@(1),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  54. NSLog(@"%@",responseObject);
  55. if ([responseObject isKindOfClass:[NSArray class]]) {
  56. for (NSDictionary * dict in responseObject) {
  57. HomeSubModel *model = [HomeSubModel modelWithDictionary:dict];
  58. [weakSelf.dataSource addObject:model];
  59. }
  60. }
  61. dispatch_async(dispatch_get_main_queue(), ^{
  62. [weakSelf.tableView reloadData];
  63. });
  64. } failure:^(NSError * _Nonnull error) {
  65. }];
  66. }
  67. - (void)refreshData:(HomeSubModel *)model indexPath:(NSIndexPath *)indexPath
  68. {
  69. WS(weakSelf);
  70. NSString * url = [NSString stringWithFormat:@"%@%@%@",BaseUrl,@"/",model.ActionUrl];
  71. [[HttpManager sharedHttpManager] POSTUrl:url parameters:@{@"LableId":@(model.Id)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  72. HomeSubModel * model = [weakSelf.dataSource objectAtIndex:indexPath.row];
  73. model.Items = responseObject;
  74. [weakSelf.dataSource replaceObjectAtIndex:indexPath.row withObject:model];
  75. dispatch_async(dispatch_get_main_queue(), ^{
  76. [weakSelf.tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationAutomatic];
  77. });
  78. } failure:^(NSError * _Nonnull error) {
  79. }];
  80. }
  81. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  82. {
  83. return 1;
  84. }
  85. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  86. {
  87. return self.dataSource.count;
  88. }
  89. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  90. {
  91. return UITableViewAutomaticDimension;
  92. }
  93. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  94. {
  95. WS(weakSelf);
  96. HomeSubModel * model = [self.dataSource objectAtIndex:indexPath.row];
  97. HomeGoodBookCell * cell = [HomeGoodBookCell configCell:tableView indexPath:indexPath];
  98. if (indexPath.row == 0) {
  99. cell.height.constant = 11.f;
  100. }
  101. BOOL isEnd = self.dataSource.count - 1 == indexPath.row;
  102. [cell setDataWithItem:indexPath.row isUnUser:isEnd model:model];
  103. cell.ClickItemBlock = ^(HomeSubItemModel * _Nonnull pmodel) {
  104. [weakSelf pushVC:pmodel];
  105. };
  106. [cell.huanBtn setAction:^{
  107. [weakSelf refreshData:model indexPath:indexPath];
  108. }];
  109. return cell;
  110. }
  111. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  112. {
  113. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  114. }
  115. - (void)pushVC:(HomeSubItemModel *)model
  116. {
  117. switch ((CollectModelType)model.MediaType) {
  118. case CollectModel_StoreBook:
  119. {
  120. BookListDetailVC * vc = [BookListDetailVC initBookListDetailVC];
  121. vc.Id = model.Id;
  122. [self.navigationController pushViewController:vc animated:YES];
  123. }
  124. break;
  125. case CollectModel_StoreVideo:
  126. {
  127. BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
  128. vc.Id = model.Id;
  129. [self.navigationController pushViewController:vc animated:YES];
  130. }
  131. break;
  132. case CollectModel_StoreSound:
  133. {
  134. BookListenVC * vc = [BookListenVC initBookListenVC];
  135. vc.Id = model.Id;
  136. vc.MediaType = MediaMusicType;
  137. [self.navigationController pushViewController:vc animated:YES];
  138. }
  139. break;
  140. case CollectModel_Teacher:
  141. {
  142. BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC];
  143. vc.Id = model.Id;
  144. [self.navigationController pushViewController:vc animated:YES];
  145. }
  146. break;
  147. case CollectModel_Organization:
  148. {
  149. HomeSCDetailVC * vc = [[HomeSCDetailVC alloc] init];
  150. vc.Id = model.Id;
  151. [self.navigationController pushViewController:vc animated:YES];
  152. }
  153. break;
  154. case CollectModel_MediaAritle:
  155. {
  156. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  157. vc.type = CollectModel_MediaAritle;
  158. vc.Id = model.Id;
  159. [self.navigationController pushViewController:vc animated:YES];
  160. }
  161. break;
  162. default:
  163. {
  164. }
  165. break;
  166. }
  167. }
  168. @end