123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- //
- // HomeBigshotVC.m
- // smartRhino
- //
- // Created by niuzhen on 2020/6/23.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "HomeBigshotVC.h"
- #import "HomeSubModel.h"
- #import "HomeSubItemModel.h"
- #import "HomeBigshotCell.h"
- #import "BookTeacherDetailVC.h"
- #import "BookWCDetailVC.h"
- #import "BookListenVC.h"
- #import "BookListDetailVC.h"
- #import "IndexMoreVC.h"
- #import "HomeSCDetailVC.h"
- @interface HomeBigshotVC ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) UITableView * tableView;
- @property (nonatomic, strong) NSMutableArray * dataSource;
- @property (nonatomic, strong) NSMutableArray * moreArray;
- @property (nonatomic, assign) NSInteger currentPage;
- @property (nonatomic, assign) NSInteger Total;
- @end
- @implementation HomeBigshotVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self.view addSubview:self.tableView];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- 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;
- }
- - (NSMutableArray *)moreArray
- {
- if (!_moreArray) {
- _moreArray = [NSMutableArray array];
- }
- return _moreArray;
- }
- - (void)headRefresh{
- self.currentPage = 1;
- self.Total = 0;
- [self.dataSource removeAllObjects];
- [self.moreArray 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 getMoreData];
- }
- - (void)getData
- {
- WS(weakSelf);
- [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_CATHEDRA) parameters:@{@"StyleCss":self.style,@"Page":@(self.currentPage),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) {
- NSLog(@"%@",responseObject);
- if ([responseObject isKindOfClass:[NSArray class]]) {
- NSArray * array = responseObject;
- for (NSDictionary * dict in array) {
- HomeSubModel *model = [HomeSubModel modelWithDictionary:dict];
- NSMutableArray * mArray = [NSMutableArray array];
- for (NSDictionary * mdict in model.Items) {
- HomeSubItemModel *mmodel = [HomeSubItemModel modelWithDictionary:mdict];
- [mArray addObject:mmodel];
- }
- model.Items = mArray.mutableCopy;
- model.LabelName = @"今日推荐";
- [weakSelf.dataSource addObject:model];
- }
- [weakSelf getMoreData];
- }
- } failure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)getMoreData
- {
- WS(weakSelf);
- [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_PAGE_CATHEDRA_Page) parameters:@{@"Page":@(self.currentPage),@"PerPage":@20} responseStyle:JOSN success:^(id _Nonnull responseObject) {
- NSLog(@"%@",responseObject);
- [weakSelf.tableView.mj_footer endRefreshing];
- if ([responseObject isKindOfClass:[NSDictionary class]]) {
- for (NSDictionary * dict in responseObject[@"Items"]) {
- HomeSubItemModel *model = [HomeSubItemModel modelWithDictionary:dict];
- [weakSelf.moreArray addObject:model];
- }
- weakSelf.Total = [responseObject[@"Total"] integerValue];
- }
- if (weakSelf.Total == weakSelf.moreArray.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) {
-
- }];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return 2;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return UITableViewAutomaticDimension;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- WS(weakSelf);
- if (indexPath.row == 0) {
- HomeSubModel *model = self.dataSource.firstObject;
- HomeBigshotCell * cell = [HomeBigshotCell configCell0:tableView indexPath:indexPath];
- [cell setDatatype:0 model:model];
- cell.ClickItemBlock = ^(HomeSubItemModel * _Nonnull pmodel) {
- [weakSelf pushVC:pmodel];
- };
- return cell;
- }else{
- HomeSubModel *model = [[HomeSubModel alloc] init];
- model.LabelName = @"更多精彩";
- model.Items = self.moreArray.mutableCopy;
- HomeBigshotCell * cell = [HomeBigshotCell configCell1:tableView indexPath:indexPath];
- [cell setDatatype:1 model:model];
- cell.ClickItemBlock = ^(HomeSubItemModel * _Nonnull pmodel) {
- [weakSelf pushVC:pmodel];
- };
- return cell;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- }
- - (void)pushVC:(HomeSubItemModel *)model
- {
- 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
|