// // TFMemberViewController.m // WXReader // // Created by 谢腾飞 on 2020/12/2. // Copyright © 2020 xtfei_2011@126.com. All rights reserved. // #import "TFMemberViewController.h" #import "TFSortViewController.h" #import "TFUpgradeMemberController.h" #import "TFMemberHeaderView.h" #import "TFBookStoreNovelStyleOneCell.h" #import "TFBookStoreNovelStyleTwoCell.h" #import "TFBookStoreNovelStyleThreeCell.h" #import "TFBookStoreNovelStyleFourCell.h" #import "TFBookStoreComicMaxStyleCell.h" #import "TFBookStoreComicMiddleStyleCell.h" #import "TFBookStoreComicNormalStyleCell.h" #import "TFPublicAdvertisementViewCell.h" #import "TFMemberModel.h" #import "TFBannerActionManager.h" @interface TFMemberViewController () @property (nonatomic ,strong) TFMemberHeaderView *headerView; @property (nonatomic ,strong) TFMemberModel *monthlyModel; @property (nonatomic ,assign) BOOL needRefresh; @end @implementation TFMemberViewController - (void)viewDidLoad { [super viewDidLoad]; [self initialize]; [self createSubviews]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self setStatusBarDefaultStyle]; [self netRequest]; } - (void)initialize { self.needRefresh = YES; [self setNavigationBarTitle:TFLocalizedString(@"会员中心")]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Recharge_Success object:nil]; } - (void)createSubviews { self.mainTableViewGroup.delegate = self; self.mainTableViewGroup.dataSource = self; [self.view addSubview:self.mainTableViewGroup]; [self.mainTableViewGroup mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.mas_equalTo(PUB_NAVBAR_HEIGHT); make.width.mas_equalTo(self.view.mas_width); make.height.mas_equalTo(SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT); }]; WS(weakSelf) self.headerView = [[TFMemberHeaderView alloc] init]; self.headerView.functionButtonClickBlock = ^(TFPrivilegeModel *privilegeModel) { if ([privilegeModel.action isEqualToString:@"library"]) { TFSortViewController *vc = [[TFSortViewController alloc] init]; vc.productionType = weakSelf.productionType; vc.isMemberStore = YES; [weakSelf.navigationController pushViewController:vc animated:YES]; } else { if (!TFUserInfoManager.isLogin) { [TFLoginOptionsViewController presentLoginView:nil]; return; } [weakSelf.navigationController pushViewController:[[TFUpgradeMemberController alloc] init] animated:YES]; } }; self.headerView.bannerrImageClickBlock = ^(TFBannerModel *bannerModel) { if ([TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:weakSelf.productionType]) { [weakSelf.navigationController pushViewController:[TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:weakSelf.productionType] animated:YES]; } }; [self.mainTableViewGroup setTableHeaderView:self.headerView]; [self setEmptyOnView:self.mainTableViewGroup title:TFLocalizedString(@"暂无数据") tapBlock:^{ }]; self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{ [weakSelf netRequest]; }]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.monthlyModel.label.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { TFBookStoreLabelModel *labelModel = [self.monthlyModel.label objectOrNilAtIndex:indexPath.section]; if (labelModel.ad_type == 0) { if (self.productionType == TFProductionTypeComic) { switch (labelModel.style) { case 1: return [self createMiddleStyleComicCellWithTableView:tableView indexPath:indexPath labelModel:labelModel]; break; case 2: return [self createNormalStyleComicCellWithTableView:tableView indexPath:indexPath labelModel:labelModel]; break; case 3: return [self createMaxStyleComicCellWithTableView:tableView indexPath:indexPath labelModel:labelModel]; break; default: return [self createNormalStyleComicCellWithTableView:tableView indexPath:indexPath labelModel:labelModel]; break; } } else { for (TFProductionModel *t_model in labelModel.list) { t_model.productionType = self.productionType; } switch (labelModel.style) { case 1: return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleOneCell.class indexPath:indexPath labelModel:labelModel]; break; case 2: return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleTwoCell.class indexPath:indexPath labelModel:labelModel]; break; case 3: return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleThreeCell.class indexPath:indexPath labelModel:labelModel]; break; case 4: return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleFourCell.class indexPath:indexPath labelModel:labelModel]; break; default: return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleOneCell.class indexPath:indexPath labelModel:labelModel]; break; } } } else { return [self createAdStyleCellWithTableView:tableView indexPath:indexPath adModel:labelModel]; } } - (UITableViewCell *)createCellWithTabelView:(UITableView *)tableView cellClass:(Class)cellClass indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel { WS(weakSelf) TFBookStoreNovelBasicViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(cellClass)]; if (!cell) { cell = [[cellClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(cellClass)]; } cell.labelModel = labelModel; cell.cellSelectMoreBlock = ^(TFBookStoreLabelModel * _Nonnull labelModel) { TFBookStoreMoreViewController *vc = [[TFBookStoreMoreViewController alloc] init]; vc.productionType = weakSelf.productionType; vc.recommend_id = [TFUtilsHelper formatStringWithInteger:labelModel.recommend_id]; [weakSelf.navigationController pushViewController:vc animated:YES]; }; cell.cellDidSelectItemBlock = ^(NSInteger production_id) { [weakSelf pushToMallDetail:production_id]; }; cell.showTopMoreBtn = labelModel.can_more; return cell; } - (UITableViewCell *)createMaxStyleComicCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel { WS(weakSelf) static NSString *cellName = @"TFBookStoreComicMaxStyleCell"; TFBookStoreComicMaxStyleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName]; if (!cell) { cell = [[TFBookStoreComicMaxStyleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName]; } cell.labelModel = labelModel; cell.showTopMoreButton = labelModel.can_more; cell.cellSelectMoreBlock = ^(TFBookStoreLabelModel * _Nonnull labelModel) { TFBookStoreMoreViewController *vc = [[TFBookStoreMoreViewController alloc] init]; vc.productionType = weakSelf.productionType; vc.recommend_id = [TFUtilsHelper formatStringWithInteger:labelModel.recommend_id]; [weakSelf.navigationController pushViewController:vc animated:YES]; }; cell.cellDidSelectItemBlock = ^(NSInteger production_id) { [weakSelf pushToMallDetail:production_id]; }; return cell; } - (UITableViewCell *)createMiddleStyleComicCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel { WS(weakSelf) static NSString *cellName = @"TFBookStoreComicMiddleStyleCell"; TFBookStoreComicMiddleStyleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName]; if (!cell) { cell = [[TFBookStoreComicMiddleStyleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName]; } cell.labelModel = labelModel; cell.showTopMoreButton = labelModel.can_more; cell.cellSelectMoreBlock = ^(TFBookStoreLabelModel * _Nonnull labelModel) { TFBookStoreMoreViewController *vc = [[TFBookStoreMoreViewController alloc] init]; vc.productionType = weakSelf.productionType; vc.recommend_id = [TFUtilsHelper formatStringWithInteger:labelModel.recommend_id]; [weakSelf.navigationController pushViewController:vc animated:YES]; }; cell.cellDidSelectItemBlock = ^(NSInteger production_id) { [weakSelf pushToMallDetail:production_id]; }; return cell; } - (UITableViewCell *)createNormalStyleComicCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel { WS(weakSelf) static NSString *cellName = @"TFBookStoreComicNormalStyleCell"; TFBookStoreComicNormalStyleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName]; if (!cell) { cell = [[TFBookStoreComicNormalStyleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName]; } cell.labelModel = labelModel; cell.showTopMoreButton = labelModel.can_more; cell.cellSelectMoreBlock = ^(TFBookStoreLabelModel * _Nonnull labelModel) { TFBookStoreMoreViewController *vc = [[TFBookStoreMoreViewController alloc] init]; vc.productionType = weakSelf.productionType; vc.recommend_id = [TFUtilsHelper formatStringWithInteger:labelModel.recommend_id]; [weakSelf.navigationController pushViewController:vc animated:YES]; }; cell.cellDidSelectItemBlock = ^(NSInteger production_id) { [weakSelf pushToMallDetail:production_id]; }; return cell; } - (UITableViewCell *)createAdStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath adModel:(TFBookStoreLabelModel *)labelModel { static NSString *cellName = @"TFPublicAdvertisementViewCell"; TFPublicAdvertisementViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName]; if (!cell) { cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName]; } [cell setAdModel:labelModel refresh:self.needRefresh]; cell.mainTableView = tableView; return cell; } //section头部间距 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == 0) { return kHalfMargin; } return CGFLOAT_MIN; } //section头部视图 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHalfMargin)]; view.backgroundColor = kGrayViewColor; return view; } //section底部间距 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { if (section == self.monthlyModel.label.count - 1) { return PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET; } return CGFLOAT_MIN; } //section底部视图 - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET)]; view.backgroundColor = [UIColor clearColor]; return view; } - (void)pushToMallDetail:(NSInteger)production_id { switch (self.productionType) { #if TF_Enable_Book case TFProductionTypeNovel: { TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init]; vc.book_id = production_id; [self.navigationController pushViewController:vc animated:YES]; } break; #endif #if TF_Enable_Comic case TFProductionTypeComic: { TFComicDetailViewController *comicDetail = [[TFComicDetailViewController alloc] init]; comicDetail.comic_id = production_id; [self.navigationController pushViewController:comicDetail animated:YES]; } break; #endif #if TF_Enable_Audio case TFProductionTypeAudio: { TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init]; vc.audio_id = production_id; [self.navigationController pushViewController:vc animated:YES]; } break; #endif default: break; } } - (void)netRequest { NSString *site_type = @""; switch (self.productionType) { case TFProductionTypeNovel: site_type = @"1"; break; case TFProductionTypeComic: site_type = @"2"; break; case TFProductionTypeAudio: site_type = @"3"; break; default: break; } WS(weakSelf) [TFNetworkTools POST:Member_Monthly parameters:@{@"site_id":site_type} model:TFMemberModel.class success:^(BOOL isSuccess, TFMemberModel *_Nullable t_model, TFNetworkRequestModel *requestModel) { if (isSuccess) { weakSelf.monthlyModel = t_model; } weakSelf.headerView.userInfoModel = weakSelf.monthlyModel.user; weakSelf.headerView.banner = weakSelf.monthlyModel.banner; weakSelf.headerView.privilege = weakSelf.monthlyModel.privilege; if (weakSelf.monthlyModel.banner.count > 0) { weakSelf.emptyView.contentViewY = 350; } else { weakSelf.emptyView.contentViewY = 200; } [weakSelf.mainTableViewGroup setTableHeaderView:weakSelf.headerView]; [weakSelf.mainTableViewGroup endRefreshing]; weakSelf.needRefresh = YES; [weakSelf.mainTableViewGroup reloadData]; dispatch_async(dispatch_get_main_queue(), ^{ weakSelf.needRefresh = NO; }); [weakSelf.mainTableViewGroup xtfei_endLoading]; } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { [weakSelf.mainTableViewGroup endRefreshing]; [weakSelf.mainTableViewGroup xtfei_endLoading]; }]; } @end