IndexMoreVC.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. //
  2. // IndexMoreVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/9/18.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "IndexMoreVC.h"
  9. #import "HomeWeiCousreCell.h"
  10. #import "BookSubArticeCell.h"
  11. #import "HomeTeacherCell.h"
  12. #import "HomeMusicCell.h"
  13. #import "HomeSchoolCell.h"
  14. #import "IndexGoodBookCell.h"
  15. #import "HomeSubItemModel.h"
  16. #import "BookTeacherDetailVC.h"
  17. #import "BookWCDetailVC.h"
  18. #import "BookListenVC.h"
  19. #import "BookListDetailVC.h"
  20. #import "TDSearchBar.h"
  21. @interface IndexMoreVC ()<UISearchBarDelegate,UIScrollViewDelegate>
  22. @property (weak, nonatomic) IBOutlet UILabel *titleL;
  23. @property (weak, nonatomic) IBOutlet UIButton *shareBtn;
  24. @property (weak, nonatomic) IBOutlet UILabel *countL;
  25. @property (weak, nonatomic) IBOutlet UIButton *cateBtn;
  26. @property (weak, nonatomic) IBOutlet UIView *searchView;
  27. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  28. @property (nonatomic, strong) NSMutableArray * dataArray;
  29. @property (nonatomic, copy) NSString * searchText;
  30. @property (nonatomic, assign) NSInteger currentPage;
  31. @property (nonatomic, assign) NSInteger Total;
  32. @property (nonatomic, strong) TDSearchBar *searchBar;
  33. @end
  34. @implementation IndexMoreVC
  35. +(IndexMoreVC *)initIndexMoreVC{
  36. IndexMoreVC *controller = [StoryboardManager.shared.home instantiateViewControllerWithIdentifier:@"IndexMoreVC"];
  37. return controller;
  38. }
  39. - (NSMutableArray *)dataArray
  40. {
  41. if (!_dataArray) {
  42. _dataArray = [NSMutableArray array];
  43. }
  44. return _dataArray;
  45. }
  46. - (TDSearchBar *)searchBar {
  47. if (!_searchBar) {
  48. _searchBar = [[TDSearchBar alloc] initWithFrame:CGRectZero];
  49. }
  50. return _searchBar;
  51. }
  52. - (void)viewDidLoad {
  53. [super viewDidLoad];
  54. self.fd_prefersNavigationBarHidden = YES;
  55. self.view.backgroundColor = UIColorHex(0xF8F8F8);
  56. self.tableView.backgroundColor = [UIColor clearColor];
  57. self.tableView.layer.cornerRadius = 8.f;
  58. self.tableView.layer.masksToBounds = YES;
  59. self.searchBar.delegate = self;
  60. WS(weakSelf);
  61. self.tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
  62. [weakSelf footerRefresh];
  63. }];
  64. self.titleL.text = self.titleStr;
  65. [self.searchView addSubview:self.searchBar];
  66. [self.searchBar mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.edges.mas_offset(UIEdgeInsetsMake(11, 15, 11, 15));
  68. }];
  69. [self getData];
  70. }
  71. - (void)footerRefresh
  72. {
  73. self.currentPage += 1;
  74. if (self.dataArray.count == self.Total) {
  75. self.tableView.mj_footer.hidden = YES;
  76. [self.tableView.mj_footer resetNoMoreData];
  77. return;
  78. }
  79. [self getDataNetWork];
  80. }
  81. - (void)getDataNetWork
  82. {
  83. WS(weakSelf);
  84. SHOWLOADING
  85. NSDictionary * paraDict = @{@"LableId":@(self.Id),
  86. @"Page":@(self.currentPage),
  87. @"PerPage":@(10),
  88. @"KeyWord":self.searchText
  89. };
  90. [[HttpManager sharedHttpManager] GETUrl:Host(API_APP_Media_Lable_List) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  91. REMOVESHOW
  92. NSLog(@"%@",responseObject);
  93. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  94. for (NSDictionary * dict in responseObject[@"Items"]) {
  95. HomeSubItemModel * model = [HomeSubItemModel modelWithDictionary:dict];
  96. [weakSelf.dataArray addObject:model];
  97. }
  98. }
  99. weakSelf.Total = [responseObject[@"Total"] integerValue];
  100. [weakSelf.tableView.mj_footer endRefreshing];
  101. dispatch_async(dispatch_get_main_queue(), ^{
  102. [weakSelf.tableView reloadData];
  103. weakSelf.countL.text = [NSString stringWithFormat:@"为你找到相关结果为%ld个",weakSelf.Total];
  104. });
  105. } failure:^(NSError * _Nonnull error) {
  106. REMOVESHOW
  107. }];
  108. }
  109. - (void)getData
  110. {
  111. [self.dataArray removeAllObjects];
  112. self.currentPage = 1;
  113. self.Total = 0;
  114. [self getDataNetWork];
  115. }
  116. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  117. {
  118. return self.dataArray.count;
  119. }
  120. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  121. {
  122. HomeSubItemModel * model = [self.dataArray objectAtIndex:indexPath.row];
  123. switch ((CollectModelType)model.MediaType) {
  124. case CollectModel_StoreBook:
  125. {
  126. IndexGoodBookCell * cell = [IndexGoodBookCell configCell0:tableView indexPath:indexPath];
  127. [cell setDataWithModel:model searchText:@""];
  128. if (self.dataArray.count == indexPath.row + 1) {
  129. cell.lineV.hidden = YES;
  130. }
  131. return cell;
  132. }
  133. break;
  134. case CollectModel_StoreVideo:
  135. {
  136. HomeWeiCousreCell * cell = [HomeWeiCousreCell configCell0:tableView indexPath:indexPath];
  137. [cell setDataWithIndexModel:model searchText:@""];
  138. if (self.dataArray.count == indexPath.row + 1) {
  139. cell.lineV.hidden = YES;
  140. }
  141. return cell;
  142. }
  143. break;
  144. case CollectModel_StoreSound:
  145. {
  146. HomeMusicCell * cell = [HomeMusicCell configCell:tableView indexPath:indexPath];
  147. [cell setDataWithModel:model searchText:@""];
  148. if (self.dataArray.count == indexPath.row + 1) {
  149. cell.lineV.hidden = YES;
  150. }
  151. return cell;
  152. }
  153. break;
  154. case CollectModel_Teacher:
  155. {
  156. HomeTeacherCell * cell = [HomeTeacherCell configCell:tableView indexPath:indexPath];
  157. [cell setDataWithModel:model searchText:@""];
  158. if (self.dataArray.count == indexPath.row + 1) {
  159. cell.lineV.hidden = YES;
  160. }
  161. return cell;
  162. }
  163. break;
  164. case CollectModel_Organization:
  165. {
  166. HomeSchoolCell * cell = [HomeSchoolCell configCell1:tableView indexPath:indexPath];
  167. [cell setDataIndexModel:model searchText:@""];
  168. if (self.dataArray.count == indexPath.row + 1) {
  169. cell.lineV.hidden = YES;
  170. }
  171. return cell;
  172. }
  173. break;
  174. default:
  175. {
  176. IndexGoodBookCell * cell = [IndexGoodBookCell configCell1:tableView indexPath:indexPath];
  177. [cell setDataWithModel:model searchText:@""];
  178. if (self.dataArray.count == indexPath.row + 1) {
  179. cell.lineV.hidden = YES;
  180. }
  181. return cell;
  182. }
  183. break;
  184. }
  185. }
  186. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  187. {
  188. HomeSubItemModel * model = [self.dataArray objectAtIndex:indexPath.row];
  189. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  190. switch ((CollectModelType)model.MediaType) {
  191. case CollectModel_StoreBook:
  192. {
  193. BookListDetailVC * vc = [BookListDetailVC initBookListDetailVC];
  194. vc.Id = model.Id;
  195. [self.navigationController pushViewController:vc animated:YES];
  196. }
  197. break;
  198. case CollectModel_StoreVideo:
  199. {
  200. BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
  201. vc.Id = model.Id;
  202. [self.navigationController pushViewController:vc animated:YES];
  203. }
  204. break;
  205. case CollectModel_StoreSound:
  206. {
  207. BookListenVC * vc = [BookListenVC initBookListenVC];
  208. vc.Id = model.Id;
  209. vc.MediaType = MediaMusicType;
  210. [self.navigationController pushViewController:vc animated:YES];
  211. }
  212. break;
  213. case CollectModel_Teacher:
  214. {
  215. BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC];
  216. vc.Id = model.Id;
  217. [self.navigationController pushViewController:vc animated:YES];
  218. }
  219. break;
  220. case CollectModel_Organization:
  221. {
  222. }
  223. break;
  224. default:
  225. {
  226. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  227. vc.type = (CollectModelType)model.MediaType;
  228. vc.Id = model.Id;
  229. [self.navigationController pushViewController:vc animated:YES];
  230. }
  231. break;
  232. }
  233. }
  234. #pragma mark - Delegata
  235. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  236. {
  237. [self setEditing:YES];
  238. }
  239. - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
  240. self.searchText = searchBar.text;
  241. [self getData];
  242. }
  243. @end