// // HomeWeiCousreVC.m // smartRhino // // Created by niuzhen on 2020/6/23. // Copyright © 2020 tederen. All rights reserved. // #import "HomeWeiCousreVC.h" #import "HomeSubModel.h" #import "HomeSubItemModel.h" #import "HomeWeiCousreCell.h" #import "BookTeacherDetailVC.h" #import "BookWCDetailVC.h" #import "BookListenVC.h" #import "BookListDetailVC.h" #import "IndexMoreVC.h" #import "HomeSCDetailVC.h" @interface HomeWeiCousreVC () @property (nonatomic, strong) UITableView * tableView; @property (nonatomic, strong) NSMutableArray * dataSource; @property (nonatomic, assign) NSInteger currentPage; @property (nonatomic, assign) NSInteger Total; @end @implementation HomeWeiCousreVC - (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:self.tableView]; self.tableView.delegate = self; self.tableView.dataSource = self; self.currentPage = 1; self.Total = 0; WS(weakSelf); self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ [weakSelf footerRefresh]; }]; [self headRefresh]; } - (void)setHeight:(CGFloat)height { [self.tableView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, height - 45)]; } - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.showsVerticalScrollIndicator = NO; } return _tableView; } - (NSMutableArray *)dataSource { if (!_dataSource) { _dataSource = [NSMutableArray array]; } return _dataSource; } - (void)headRefresh{ self.currentPage = 1; self.Total = 1; [self.dataSource removeAllObjects]; [self getData]; } - (void)footerRefresh{ self.currentPage += 1; if (self.Total == self.dataSource.count) { self.currentPage --; [self.tableView.mj_footer endRefreshingWithNoMoreData]; self.tableView.mj_footer.hidden = YES; return ; } [self getData]; } - (void)getData { WS(weakSelf); [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_WE_BOOK) parameters:@{@"StyleCss":self.style,@"Page":@(self.currentPage),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) { NSLog(@"%@",responseObject); [weakSelf.tableView.mj_footer endRefreshing]; if ([responseObject isKindOfClass:[NSDictionary class]]) { HomeSubModel *model = [HomeSubModel modelWithDictionary:responseObject]; for (NSDictionary * dict in model.Items) { HomeSubItemModel *smodel = [HomeSubItemModel modelWithDictionary:dict]; [weakSelf.dataSource addObject:smodel]; } weakSelf.Total = model.Total; if (weakSelf.Total == weakSelf.dataSource.count) { [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData]; weakSelf.tableView.mj_footer.hidden = YES; } } dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); } failure:^(NSError * _Nonnull error) { [weakSelf.tableView.mj_footer endRefreshing]; }]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataSource.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { HomeSubItemModel *model = self.dataSource[indexPath.row]; HomeWeiCousreCell * cell = [HomeWeiCousreCell configCell0:tableView indexPath:indexPath]; if (indexPath.row == 0) { cell.height.constant = 11.f; }else{ cell.height.constant = 0.f; } [cell setDataWithModel:model]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; HomeSubItemModel *model = self.dataSource[indexPath.row]; 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: { HomeSCDetailVC * vc = [[HomeSCDetailVC alloc] init]; vc.Id = model.Id; [self.navigationController pushViewController:vc animated:YES]; } break; case CollectModel_MediaAritle: { MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC]; vc.type = CollectModel_MediaAritle; vc.Id = model.Id; [self.navigationController pushViewController:vc animated:YES]; } break; default: { } break; } } @end