258 lines
11 KiB
Objective-C
258 lines
11 KiB
Objective-C
//
|
|
// QXNobilityDetailViewController.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/11/8.
|
|
//
|
|
|
|
#import "QXNobilityDetailViewController.h"
|
|
#import "GKCycleScrollView.h"
|
|
#import "QXNobilityDetailTopCell.h"
|
|
#import "QXMineNetwork.h"
|
|
#import "QXNobilityDetailCell.h"
|
|
#import "QXNobilityBuyViewController.h"
|
|
|
|
@interface QXNobilityDetailViewController ()<GKCycleScrollViewDataSource,GKCycleScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
|
|
@property (nonatomic,strong)GKCycleScrollView *cycleScrollView;
|
|
@property (nonatomic,strong)UIView *headerView;
|
|
@property (nonatomic,strong)UIImageView *headerImageView;
|
|
@property (nonatomic,strong)UILabel *headerLabel;
|
|
@property (nonatomic,strong)UICollectionView *collectionView;
|
|
@property (nonatomic,strong)QXNobilityListModel *currentModel;
|
|
|
|
@property (nonatomic,strong)UIView *bottomView;
|
|
@property (nonatomic,strong)UIImageView *bottomImageView;
|
|
@property (nonatomic,strong)UILabel *bottomLabel;
|
|
@property (nonatomic,strong)UIButton *openBtn;
|
|
|
|
@property (nonatomic,assign)NSInteger currentIndex;
|
|
@end
|
|
|
|
@implementation QXNobilityDetailViewController
|
|
|
|
- (void)viewDidLoad {
|
|
self.isNoChangeBgImage = YES;
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
}
|
|
-(void)viewWillAppear:(BOOL)animated{
|
|
[super viewWillAppear:animated];
|
|
[self.navigationController setNavigationBarHidden:NO animated:YES];
|
|
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:RGB16(0xffffff)};
|
|
}
|
|
-(void)viewWillDisappear:(BOOL)animated{
|
|
[super viewWillDisappear:animated];
|
|
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:RGB16(0x000000)};
|
|
}
|
|
-(void)setNavgationItems{
|
|
[super setNavgationItems];
|
|
self.navigationTintColor = RGB16(0xffffff);
|
|
self.navigationItem.title = @"爵位详情";
|
|
UIButton*createBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
|
|
[createBtn setImage:[UIImage imageNamed:@"nobility_help_icon"] forState:(UIControlStateNormal)];
|
|
createBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentTrailing;
|
|
[createBtn addTarget:self action:@selector(helpAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:createBtn];
|
|
}
|
|
|
|
-(void)helpAction{
|
|
NSString *urlString = [NSString stringWithFormat:@"%@api/Page/page_show?id=%@",ServerUrl,@"29"];
|
|
QXBaseWebViewController *vc = [[QXBaseWebViewController alloc] init];
|
|
vc.urlStr = urlString;
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}
|
|
|
|
-(void)getData{
|
|
MJWeakSelf
|
|
[QXMineNetwork getNobilityListSuccessBlock:^(NSArray<QXNobilityListModel *> * _Nonnull list) {
|
|
[weakSelf.dataArray removeAllObjects];
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
|
weakSelf.currentModel = weakSelf.dataArray.firstObject;
|
|
weakSelf.headerLabel.text = [NSString stringWithFormat:@"专属特权%@",self.currentModel.power.count_str];
|
|
[weakSelf setPirce];
|
|
for (NSInteger i = 0;i<weakSelf.dataArray.count;i++) {
|
|
QXNobilityListModel*md = weakSelf.dataArray[i];
|
|
if ([md.lid isEqualToString:weakSelf.cruuent_nobility_id]) {
|
|
weakSelf.currentIndex = i;
|
|
break;
|
|
}
|
|
}
|
|
weakSelf.cycleScrollView.defaultSelectIndex = weakSelf.currentIndex;
|
|
[weakSelf.cycleScrollView reloadData];
|
|
[weakSelf.collectionView reloadData];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
}];
|
|
}
|
|
-(void)initSubViews{
|
|
[self updateBgImage:@"nobility_detail_bg"];
|
|
[self.view addSubview:self.headerView];
|
|
[self.view addSubview:self.cycleScrollView];
|
|
[self.view addSubview:self.bottomView];
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
int itemWidth = (SCREEN_WIDTH-16*2-8*2)/3;
|
|
layout.itemSize = CGSizeMake(itemWidth, itemWidth);
|
|
layout.minimumLineSpacing = 8;
|
|
layout.minimumInteritemSpacing = 8;
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16);
|
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.headerView.bottom+16, SCREEN_WIDTH, SCREEN_HEIGHT-self.headerView.bottom-16-24-80) collectionViewLayout:layout];
|
|
[self.collectionView registerNib:[UINib nibWithNibName:@"QXNobilityDetailCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXNobilityDetailCell"];
|
|
self.collectionView.delegate = self;
|
|
self.collectionView.dataSource = self;
|
|
self.collectionView.showsHorizontalScrollIndicator = NO;
|
|
self.collectionView.bounces = NO;
|
|
self.collectionView.pagingEnabled = NO;
|
|
self.collectionView.backgroundColor = [UIColor clearColor];
|
|
[self.view addSubview:self.collectionView];
|
|
}
|
|
|
|
-(void)setPirce{
|
|
NSString *price = [NSString stringWithFormat:@"%@开通:%@/%@天",self.currentModel.name,self.currentModel.pay_price,self.currentModel.day];
|
|
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:price];
|
|
[attr yy_setColor:RGB16(0xFFDA7E) range:[price rangeOfString:self.currentModel.pay_price]];
|
|
self.bottomLabel.attributedText = attr;
|
|
}
|
|
|
|
-(void)openAction{
|
|
QXNobilityBuyViewController *vc = [[QXNobilityBuyViewController alloc] init];
|
|
vc.nobility_id = self.currentModel.lid;
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}
|
|
|
|
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
return self.currentModel.power.list.count;
|
|
}
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXNobilityDetailCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXNobilityDetailCell" forIndexPath:indexPath];
|
|
cell.model = self.currentModel.power.list[indexPath.row];
|
|
return cell;
|
|
}
|
|
|
|
#pragma mark - GKCycleScrollViewDataSource,GKCycleScrollViewDelegate
|
|
- (NSInteger)numberOfCellsInCycleScrollView:(GKCycleScrollView *)cycleScrollView {
|
|
return self.dataArray.count;
|
|
}
|
|
- (GKCycleScrollViewCell *)cycleScrollView:(GKCycleScrollView *)cycleScrollView cellForViewAtIndex:(NSInteger)index {
|
|
GKCycleScrollViewCell *cell = [cycleScrollView dequeueReusableCell];
|
|
if (!cell) {
|
|
cell = [QXNobilityDetailTopCell new];
|
|
}
|
|
QXNobilityDetailTopCell *topcell = (QXNobilityDetailTopCell*)cell;
|
|
topcell.index = index;
|
|
topcell.myIndex = self.currentIndex;
|
|
topcell.model = self.dataArray[index];
|
|
return cell;
|
|
}
|
|
|
|
- (CGSize)sizeForCellInCycleScrollView:(GKCycleScrollView *)cycleScrollView {
|
|
return CGSizeMake(220, 242);
|
|
}
|
|
-(void)cycleScrollView:(GKCycleScrollView *)cycleScrollView didScrollCellToIndex:(NSInteger)index{
|
|
self.currentModel = self.dataArray[index];
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
self.headerLabel.text = [NSString stringWithFormat:@"专属特权%@",self.currentModel.power.count_str];
|
|
[self setPirce];
|
|
[self.collectionView reloadData];
|
|
});
|
|
_openBtn.enabled = YES;
|
|
if (![self.cruuent_nobility_id isExist]) {
|
|
[_openBtn setBackgroundImage:[UIImage imageNamed:@"nobility_detail_open_btn_nor"] forState:(UIControlStateNormal)];
|
|
return;
|
|
}
|
|
if (self.currentIndex<index) {
|
|
[_openBtn setBackgroundImage:[UIImage imageNamed:@"nobility_detail_open_btn_update"] forState:(UIControlStateNormal)];
|
|
return;
|
|
}else if (self.currentIndex==index){
|
|
[_openBtn setBackgroundImage:[UIImage imageNamed:@"nobility_detail_open_btn_renew"] forState:(UIControlStateNormal)];
|
|
}else{
|
|
_openBtn.enabled = NO;
|
|
}
|
|
}
|
|
- (void)cycleScrollView:(GKCycleScrollView *)cycleScrollView didSelectCellAtIndex:(NSInteger)index {
|
|
|
|
}
|
|
|
|
|
|
-(GKCycleScrollView *)cycleScrollView{
|
|
if (!_cycleScrollView) {
|
|
_cycleScrollView = [[GKCycleScrollView alloc] initWithFrame:CGRectMake(0, NavContentHeight, SCREEN_WIDTH, 242)];
|
|
_cycleScrollView.dataSource = self;
|
|
_cycleScrollView.delegate = self;
|
|
_cycleScrollView.minimumCellAlpha = 0.0;
|
|
_cycleScrollView.leftRightMargin = 16.0f;
|
|
_cycleScrollView.topBottomMargin = 15.0f;
|
|
_cycleScrollView.isInfiniteLoop = NO;
|
|
_cycleScrollView.isAutoScroll = NO;
|
|
}
|
|
return _cycleScrollView;
|
|
}
|
|
|
|
|
|
-(UIView *)headerView{
|
|
if (!_headerView) {
|
|
_headerView = [[UIView alloc] initWithFrame:CGRectMake(0,self.cycleScrollView.bottom+16, SCREEN_WIDTH, ScaleWidth(35))];
|
|
[_headerView addSubview:self.headerImageView];;
|
|
[_headerView addSubview:self.headerLabel];;
|
|
}
|
|
return _headerView;
|
|
}
|
|
|
|
-(UIImageView *)headerImageView{
|
|
if (!_headerImageView) {
|
|
_headerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nobility_power_header_bg"]];
|
|
_headerImageView.contentMode = UIViewContentModeScaleToFill;
|
|
_headerImageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(35));
|
|
}
|
|
return _headerImageView;
|
|
}
|
|
-(UILabel *)headerLabel{
|
|
if (!_headerLabel) {
|
|
_headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(35))];
|
|
_headerLabel.textColor = RGB16(0xFFEDBD);
|
|
_headerLabel.font = [UIFont systemFontOfSize:16];
|
|
_headerLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _headerLabel;
|
|
}
|
|
|
|
-(UIView *)bottomView{
|
|
if (!_bottomView) {
|
|
_bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-24-80, SCREEN_WIDTH, 80+24)];
|
|
[_bottomView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
|
|
[_bottomView addSubview:self.bottomImageView];
|
|
[_bottomView addSubview:self.openBtn];
|
|
[_bottomView addSubview:self.bottomLabel];
|
|
}
|
|
return _bottomView;
|
|
}
|
|
|
|
-(UIImageView *)bottomImageView{
|
|
if (!_bottomImageView) {
|
|
_bottomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nobility_detail_bottom_bg"]];
|
|
_bottomImageView.frame = CGRectMake(0, 0, self.bottomView.width, self.bottomView.height);
|
|
}
|
|
return _bottomImageView;
|
|
}
|
|
-(UIButton *)openBtn{
|
|
if (!_openBtn) {
|
|
_openBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-16-128, 19, 128, 41)];
|
|
[_openBtn setBackgroundImage:[UIImage imageNamed:@"nobility_detail_open_btn_nor"] forState:(UIControlStateNormal)];
|
|
[_openBtn setBackgroundImage:[UIImage imageNamed:@"nobility_detail_open_btn_disable"] forState:(UIControlStateDisabled)];
|
|
[_openBtn addTarget:self action:@selector(openAction) forControlEvents:(UIControlEventTouchUpInside)];;
|
|
}
|
|
return _openBtn;
|
|
}
|
|
|
|
-(UILabel *)bottomLabel{
|
|
if (!_bottomLabel) {
|
|
_bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 28, self.openBtn.left-16, 24)];
|
|
_bottomLabel.textColor = RGB16(0xF7EAC9);
|
|
_bottomLabel.font = [UIFont systemFontOfSize:16];
|
|
}
|
|
return _bottomLabel;
|
|
}
|
|
@end
|