// // QXAllRoomHourRankView.m // QXLive // // Created by 启星 on 2025/9/29. // #import "QXAllRoomHourRankView.h" #import "QXMineNetwork.h" #import "NSString+QX.h" @interface QXAllRoomHourRankView() @property (nonatomic,strong)UIView *bgView; /// 顶部视图 /// 顶部容器 @property (nonatomic,strong)UIView *topView; /// 顶部背景视图 @property (nonatomic,strong)UIImageView *topImageView; /// 帮助按钮 @property (nonatomic,strong)UIButton *helpBtn; /// 时间背景 @property (nonatomic,strong)UIImageView *timeBgImageView; /// 时间标签 @property (nonatomic,strong)UILabel *timeLabel; /// 列表视图 @property (nonatomic,strong)UICollectionView *collectionView; @property (nonatomic,strong)NSMutableArray *dataArray; @property (nonatomic,assign)NSInteger page; @end @implementation QXAllRoomHourRankView - (instancetype)init { self = [super init]; if (self) { self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); self.page = 1; [self initSubviews]; } return self; } -(void)initSubviews{ UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)]; tap.delegate = self; [self addGestureRecognizer:tap]; self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3]; self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScaleWidth(256), self.height)]; self.bgView.backgroundColor = RGB16(0x32057F); [self addSubview:self.bgView]; self.topView = [[UIView alloc] init]; [self.bgView addSubview:self.topView]; [self.topView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.equalTo(self.bgView); make.height.mas_equalTo(ScaleWidth(ScaleWidth(281))); }]; self.topImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_hour_rank_top_bg"]]; [self.topView addSubview:self.topImageView]; [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.topView); }]; self.timeBgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_hour_rank_top_time_bg"]]; [self.topView addSubview:self.timeBgImageView]; [self.timeBgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.topView); make.top.mas_equalTo(ScaleWidth(119)); make.height.mas_equalTo(ScaleWidth(23)); make.width.mas_equalTo(ScaleWidth(150)); }]; self.timeLabel = [[UILabel alloc] init]; self.timeLabel.text = @"榜单时间"; self.timeLabel.font = [UIFont systemFontOfSize:12]; self.timeLabel.textAlignment = NSTextAlignmentCenter; self.timeLabel.textColor = RGB16(0xffffff); [self.bgView addSubview:self.timeLabel]; [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.timeBgImageView); }]; self.helpBtn = [[UIButton alloc] init]; [self.helpBtn setImage:[UIImage imageNamed:@"room_hour_rank_help"] forState:(UIControlStateNormal)]; [self.helpBtn addTarget:self action:@selector(helpAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.bgView addSubview:self.helpBtn]; [self.helpBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.bgView); make.top.mas_equalTo(ScaleWidth(50)); make.height.mas_equalTo(ScaleWidth(40)); make.width.mas_equalTo(ScaleWidth(40)); }]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 4; layout.minimumInteritemSpacing = 4; layout.itemSize = CGSizeMake(self.bgView.width, 88); self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.bounces = YES; self.collectionView.backgroundColor = [UIColor clearColor]; MJWeakSelf self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ weakSelf.page = 1; [weakSelf getRankList]; }]; self.collectionView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{ weakSelf.page++; [weakSelf getRankList]; }]; [self.collectionView registerClass:[QXAllRoomHourRankCell class] forCellWithReuseIdentifier:@"QXAllRoomHourRankCell"]; [self.bgView addSubview:self.collectionView]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.bgView); make.top.equalTo(self.topView.mas_bottom).offset(10); make.bottom.equalTo(self.bgView); }]; } -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ return touch.view == self; } -(void)getRankList{ MJWeakSelf [QXMineNetwork roomHourRankWithPage:self.page successBlock:^(QXRoomHourRankModel * _Nonnull model) { if (weakSelf.page == 1) { [weakSelf.dataArray removeAllObjects]; } weakSelf.timeLabel.text = [NSString stringWithFormat:@"榜单时间 %@",model.time_range]; [weakSelf.dataArray addObjectsFromArray:model.lists]; [weakSelf.collectionView reloadData]; if (model.lists.count == 0) { weakSelf.collectionView.mj_footer.state = MJRefreshStateNoMoreData; }else{ [weakSelf.collectionView.mj_footer endRefreshing]; } [weakSelf.collectionView.mj_header endRefreshing]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { [weakSelf.collectionView.mj_header endRefreshing]; [weakSelf.collectionView.mj_footer endRefreshing]; }]; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.dataArray.count; } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ QXAllRoomHourRankCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXAllRoomHourRankCell" forIndexPath:indexPath]; cell.rankNumber = indexPath.row; cell.model = self.dataArray[indexPath.row]; return cell; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ QXRoomHourRankSubModel *model = self.dataArray[indexPath.row]; [[QXGlobal shareGlobal] joinRoomWithRoomId:model.room_id isRejoin:NO navagationController:self.navigationController]; } -(void)showInView:(UIView *)view{ self.page = 1; [self getRankList]; self.bgView.x = SCREEN_WIDTH; [view addSubview:self]; [UIView animateWithDuration:0.3 animations:^{ self.bgView.x = SCREEN_WIDTH-ScaleWidth(256); }]; } -(void)hide{ [UIView animateWithDuration:0.3 animations:^{ self.bgView.x = SCREEN_WIDTH; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } -(void)helpAction{ QXBaseWebViewController *vc = [[QXBaseWebViewController alloc] init]; NSString *urlString = [NSString stringWithFormat:@"%@api/Page/page_show?id=%@",ServerUrl,@"24"]; vc.urlStr = urlString; [self.viewController.navigationController pushViewController:vc animated:YES]; } -(NSMutableArray *)dataArray{ if (!_dataArray) { _dataArray = [NSMutableArray array]; } return _dataArray; } @end @implementation QXAllRoomHourRankCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)initSubviews{ self.contentView.backgroundColor = RGB16(0x420B93); self.rankNumberImageView = [[UIImageView alloc] init]; [self.contentView addSubview:self.rankNumberImageView]; [self.rankNumberImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(5); make.top.equalTo(self.contentView); make.width.mas_equalTo(32); make.height.mas_equalTo(32); }]; self.rankNumberLabel = [[UILabel alloc] init]; self.rankNumberLabel.textAlignment = NSTextAlignmentCenter; self.rankNumberLabel.textColor = RGB16(0xA6A77E); self.rankNumberLabel.font = [UIFont systemFontOfSize:12]; [self.contentView addSubview:self.rankNumberLabel]; [self.rankNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.rankNumberImageView); }]; self.roomCoverImageView = [[UIImageView alloc] init]; self.roomCoverImageView.contentMode = UIViewContentModeScaleAspectFill; self.roomCoverImageView.layer.borderWidth = 1; self.roomCoverImageView.layer.borderColor = RGB16(0xD000FF).CGColor; [self.contentView addSubview:self.roomCoverImageView]; [self.roomCoverImageView addRoundedCornersWithRadius:6]; [self.roomCoverImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(21); make.centerY.equalTo(self.contentView); make.width.height.mas_equalTo(64); }]; self.animationView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"activity_room_animate"]]; [self.contentView addSubview:self.animationView]; [self.animationView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.roomCoverImageView.mas_right).offset(-3); make.top.equalTo(self.roomCoverImageView.mas_top).offset(3); make.width.height.mas_equalTo(12); }]; self.redpacketImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"redbag_tag_icon"]]; [self.contentView addSubview:self.redpacketImageView]; [self.redpacketImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.right.mas_equalTo(-5); make.centerY.equalTo(self.contentView); make.width.mas_equalTo(60); make.height.mas_equalTo(60); }]; self.activityBgView = [[UIView alloc] init]; self.activityBgView.hidden = YES; [self.contentView addSubview:self.activityBgView]; [self.activityBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.right.mas_equalTo(-5); make.centerY.equalTo(self.contentView); // make.top.mas_equalTo(8); make.width.mas_equalTo(63); make.height.mas_equalTo(67); }]; self.activityStatusBgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"activity_status_ing"]]; // self.activityStatusBgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"activity_status_will"]]; [self.activityBgView addSubview:self.activityStatusBgImageView]; [self.activityStatusBgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.equalTo(self.activityBgView); make.height.mas_equalTo(14); }]; self.statusLabel = [[UILabel alloc] init]; self.statusLabel.font = [UIFont systemFontOfSize:12]; self.statusLabel.textColor = RGB16(0xffffff); self.statusLabel.textAlignment = NSTextAlignmentCenter; [self.activityBgView addSubview:self.statusLabel]; [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.activityStatusBgImageView); }]; self.activityImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ac_tag_icon"]]; [self.activityBgView addSubview:self.activityImageView]; [self.activityImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.activityBgView); make.centerX.equalTo(self.activityBgView); make.width.height.mas_equalTo(55); }]; self.nameLabel = [[UILabel alloc] init]; self.nameLabel.textColor = RGB16(0xffffff); self.nameLabel.font = [UIFont boldSystemFontOfSize:12]; [self.contentView addSubview:self.nameLabel]; [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.roomCoverImageView.mas_right).offset(8); make.right.equalTo(self.activityBgView.mas_left).offset(-8); make.top.equalTo(self.roomCoverImageView); make.height.mas_equalTo(15); }]; self.labelImageView = [[UIImageView alloc] init]; [self.contentView addSubview:self.labelImageView]; [self.labelImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(44); make.height.mas_equalTo(24); make.centerY.equalTo(self.contentView); make.left.equalTo(self.nameLabel); }]; self.hotImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_hot_icon"]]; [self.contentView addSubview:self.hotImageView]; [self.hotImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.mas_equalTo(15); make.bottom.equalTo(self.roomCoverImageView.mas_bottom).offset(2); make.left.equalTo(self.nameLabel); }]; self.hotLabel = [[UILabel alloc] init]; self.hotLabel.font = [UIFont systemFontOfSize:12]; self.hotLabel.textColor = RGB16(0xffffff); [self.contentView addSubview:self.hotLabel]; [self.hotLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.hotImageView); make.left.equalTo(self.hotImageView.mas_right); }]; [self.contentView bringSubviewToFront:self.rankNumberImageView]; [self.contentView bringSubviewToFront:self.rankNumberLabel]; [self.contentView bringSubviewToFront:self.activityStatusBgImageView]; [self.contentView bringSubviewToFront:self.statusLabel]; } -(void)setRankNumber:(NSInteger)rankNumber{ _rankNumber = rankNumber; if (rankNumber == 0) { self.rankNumberLabel.hidden = YES; self.rankNumberImageView.image = [UIImage imageNamed:@"activity_room_rank_first"]; return; } if (rankNumber == 1) { self.rankNumberLabel.hidden = YES; self.rankNumberImageView.image = [UIImage imageNamed:@"activity_room_rank_second"]; return; } if (rankNumber == 2) { self.rankNumberLabel.hidden = YES; self.rankNumberImageView.image = [UIImage imageNamed:@"activity_room_rank_third"]; return; } self.rankNumberLabel.hidden = NO; self.rankNumberLabel.text = [NSString stringWithFormat:@"%ld",rankNumber+1]; self.rankNumberImageView.image = [UIImage imageNamed:@"activity_room_rank_other"]; } -(void)setModel:(QXRoomHourRankSubModel *)model{ _model = model; [self.roomCoverImageView sd_setImageWithURL:[NSURL URLWithString:model.room_cover]]; self.nameLabel.text = model.room_name; [self.labelImageView sd_setImageWithURL:[NSURL URLWithString:model.label_icon]]; self.hotLabel.text = [NSString qx_showHotCountNum:model.total_price.longLongValue]; if (model.redpacket_status > 0) { self.redpacketImageView.hidden = NO; }else{ self.redpacketImageView.hidden = YES; } // if (model.xlh_status == 0) { // self.activityBgView.hidden = YES; // }else if (model.xlh_status == 2){ // self.activityBgView.hidden = NO; // self.activityStatusBgImageView.image = [UIImage imageNamed:@"activity_status_will"]; // self.statusLabel.text = @"即将开始"; // }else{ // self.activityBgView.hidden = NO; // self.activityStatusBgImageView.image = [UIImage imageNamed:@"activity_status_ing"]; // self.statusLabel.text = @"进行中"; // } } @end @implementation QXAllRoomHourRankTagView - (instancetype)init { self = [super init]; if (self) { self.frame = CGRectMake(SCREEN_WIDTH-60, NavContentHeight, 60, 25); [self initSubviews]; } return self; } -(void)initSubviews{ UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; [self addGestureRecognizer:panRecognizer]; self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_hour_rank_icon"]]; [self addSubview:self.bgImageView]; [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self); }]; self.titleLabel = [[UILabel alloc] init]; self.titleLabel.font = [UIFont systemFontOfSize:11]; self.titleLabel.text = @"小时榜"; self.titleLabel.textColor = RGB16(0xffffff); self.titleLabel.textAlignment = NSTextAlignmentRight; [self addSubview:self.titleLabel]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self); }]; self.button = [[UIButton alloc] init]; [self.button addTarget:self action:@selector(buttonAction) forControlEvents:(UIControlEventTouchUpInside)]; [self addSubview:self.button]; [self.button mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self); }]; } -(void)buttonAction{ if (self.startBlock) { self.startBlock(); } } -(void)handlePan:(UIPanGestureRecognizer*)recognizer{ if (recognizer.state == UIGestureRecognizerStateEnded) { NSLog(@"拖动结束"); } CGPoint translation = [recognizer translationInView:self.viewController.view]; CGPoint panCenter = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y); if (panCenter.y < kSafeAreaTop || panCenter.y> SCREEN_HEIGHT-kSafeAreaBottom) { return; } recognizer.view.center = CGPointMake(SCREEN_WIDTH-60/2, recognizer.view.center.y + translation.y); [recognizer setTranslation:CGPointZero inView:self.viewController.view]; } @end