HomeUserVC.m 5.3 KB

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