123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- //
- // IndexMoreVC.m
- // smartRhino
- //
- // Created by niuzhen on 2020/9/18.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "IndexMoreVC.h"
- #import "HomeWeiCousreCell.h"
- #import "BookSubArticeCell.h"
- #import "HomeTeacherCell.h"
- #import "HomeMusicCell.h"
- #import "HomeSchoolCell.h"
- #import "IndexGoodBookCell.h"
- #import "HomeSubItemModel.h"
- #import "BookTeacherDetailVC.h"
- #import "BookWCDetailVC.h"
- #import "BookListenVC.h"
- #import "BookListDetailVC.h"
- #import "TDSearchBar.h"
- @interface IndexMoreVC ()<UISearchBarDelegate,UIScrollViewDelegate>
- @property (weak, nonatomic) IBOutlet UILabel *titleL;
- @property (weak, nonatomic) IBOutlet UIButton *shareBtn;
- @property (weak, nonatomic) IBOutlet UILabel *countL;
- @property (weak, nonatomic) IBOutlet UIButton *cateBtn;
- @property (weak, nonatomic) IBOutlet UIView *searchView;
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray * dataArray;
- @property (nonatomic, copy) NSString * searchText;
- @property (nonatomic, assign) NSInteger currentPage;
- @property (nonatomic, assign) NSInteger Total;
- @property (nonatomic, strong) TDSearchBar *searchBar;
- @end
- @implementation IndexMoreVC
- +(IndexMoreVC *)initIndexMoreVC{
- IndexMoreVC *controller = [StoryboardManager.shared.home instantiateViewControllerWithIdentifier:@"IndexMoreVC"];
- return controller;
- }
- - (NSMutableArray *)dataArray
- {
- if (!_dataArray) {
- _dataArray = [NSMutableArray array];
- }
- return _dataArray;
- }
- - (TDSearchBar *)searchBar {
- if (!_searchBar) {
- _searchBar = [[TDSearchBar alloc] initWithFrame:CGRectZero];
- }
- return _searchBar;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.fd_prefersNavigationBarHidden = YES;
- self.view.backgroundColor = UIColorHex(0xF8F8F8);
- self.tableView.backgroundColor = [UIColor clearColor];
- self.tableView.layer.cornerRadius = 8.f;
- self.tableView.layer.masksToBounds = YES;
- self.searchBar.delegate = self;
- WS(weakSelf);
- self.tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
- [weakSelf footerRefresh];
- }];
- self.titleL.text = self.titleStr;
- [self.searchView addSubview:self.searchBar];
- [self.searchBar mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_offset(UIEdgeInsetsMake(11, 15, 11, 15));
- }];
- [self getData];
- }
- - (void)footerRefresh
- {
- self.currentPage += 1;
- if (self.dataArray.count == self.Total) {
- self.tableView.mj_footer.hidden = YES;
- [self.tableView.mj_footer resetNoMoreData];
- return;
- }
- [self getDataNetWork];
- }
- - (void)getDataNetWork
- {
- WS(weakSelf);
- SHOWLOADING
- NSDictionary * paraDict = @{@"LableId":@(self.Id),
- @"Page":@(self.currentPage),
- @"PerPage":@(10),
- @"KeyWord":self.searchText
- };
- [[HttpManager sharedHttpManager] GETUrl:Host(API_APP_Media_Lable_List) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
- REMOVESHOW
- NSLog(@"%@",responseObject);
- if ([responseObject isKindOfClass:[NSDictionary class]]) {
- for (NSDictionary * dict in responseObject[@"Items"]) {
- HomeSubItemModel * model = [HomeSubItemModel modelWithDictionary:dict];
- [weakSelf.dataArray addObject:model];
- }
- }
- weakSelf.Total = [responseObject[@"Total"] integerValue];
- [weakSelf.tableView.mj_footer endRefreshing];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- weakSelf.countL.text = [NSString stringWithFormat:@"为你找到相关结果为%ld个",weakSelf.Total];
- });
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- }];
- }
- - (void)getData
- {
- [self.dataArray removeAllObjects];
- self.currentPage = 1;
- self.Total = 0;
- [self getDataNetWork];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.dataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- HomeSubItemModel * model = [self.dataArray objectAtIndex:indexPath.row];
- switch ((CollectModelType)model.MediaType) {
- case CollectModel_StoreBook:
- {
- IndexGoodBookCell * cell = [IndexGoodBookCell configCell0:tableView indexPath:indexPath];
- [cell setDataWithModel:model searchText:@""];
- if (self.dataArray.count == indexPath.row + 1) {
- cell.lineV.hidden = YES;
- }
- return cell;
- }
- break;
- case CollectModel_StoreVideo:
- {
- HomeWeiCousreCell * cell = [HomeWeiCousreCell configCell0:tableView indexPath:indexPath];
- [cell setDataWithIndexModel:model searchText:@""];
- if (self.dataArray.count == indexPath.row + 1) {
- cell.lineV.hidden = YES;
- }
- return cell;
- }
- break;
- case CollectModel_StoreSound:
- {
- HomeMusicCell * cell = [HomeMusicCell configCell:tableView indexPath:indexPath];
- [cell setDataWithModel:model searchText:@""];
- if (self.dataArray.count == indexPath.row + 1) {
- cell.lineV.hidden = YES;
- }
- return cell;
- }
- break;
- case CollectModel_Teacher:
- {
- HomeTeacherCell * cell = [HomeTeacherCell configCell:tableView indexPath:indexPath];
- [cell setDataWithModel:model searchText:@""];
- if (self.dataArray.count == indexPath.row + 1) {
- cell.lineV.hidden = YES;
- }
- return cell;
- }
- break;
- case CollectModel_Organization:
- {
- HomeSchoolCell * cell = [HomeSchoolCell configCell1:tableView indexPath:indexPath];
- [cell setDataIndexModel:model searchText:@""];
- if (self.dataArray.count == indexPath.row + 1) {
- cell.lineV.hidden = YES;
- }
- return cell;
- }
- break;
- default:
- {
- IndexGoodBookCell * cell = [IndexGoodBookCell configCell1:tableView indexPath:indexPath];
- [cell setDataWithModel:model searchText:@""];
- if (self.dataArray.count == indexPath.row + 1) {
- cell.lineV.hidden = YES;
- }
- return cell;
- }
- break;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- HomeSubItemModel * model = [self.dataArray objectAtIndex:indexPath.row];
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- switch ((CollectModelType)model.MediaType) {
- case CollectModel_StoreBook:
- {
- BookListDetailVC * vc = [BookListDetailVC initBookListDetailVC];
- vc.Id = model.Id;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case CollectModel_StoreVideo:
- {
- BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
- vc.Id = model.Id;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case CollectModel_StoreSound:
- {
- BookListenVC * vc = [BookListenVC initBookListenVC];
- vc.Id = model.Id;
- vc.MediaType = MediaMusicType;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case CollectModel_Teacher:
- {
- BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC];
- vc.Id = model.Id;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case CollectModel_Organization:
- {
-
- }
- break;
- default:
- {
- MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
- vc.type = (CollectModelType)model.MediaType;
- vc.Id = model.Id;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- }
- }
- #pragma mark - Delegata
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
- [self setEditing:YES];
- }
- - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
- self.searchText = searchBar.text;
- [self getData];
- }
- @end
|