// // QXMeetActivityRankView.m // QXLive // // Created by 启星 on 2025/8/30. // #import "QXMeetActivityRankView.h" @interface QXMeetActivityRankView() @property(nonatomic,strong)UIView* bgView; @property(nonatomic,strong)UIImageView* ruleImageView; @property(nonatomic,strong)UIImageView* bgImageView; @property(nonatomic,strong)UIView* bgCoverView; @property(nonatomic,strong)UITableView* tableView; @property(nonatomic,strong)NSMutableArray* allRecordArray; @property(nonatomic,assign)NSInteger page; @property(nonatomic,strong)UIButton* drawRankBtn; @property(nonatomic,strong)UIButton* luckRankBtn; @end @implementation QXMeetActivityRankView - (instancetype)init { self = [super init]; if (self) { self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); [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, SCREEN_WIDTH, ScaleWidth(663))]; [self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)]; [self addSubview:self.bgView]; self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"meet_rule_bg"]]; self.bgImageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(663)); self.bgImageView.contentMode = UIViewContentModeScaleToFill; [self.bgView addSubview:self.bgImageView]; self.ruleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ac_meet_rank_icon"]]; self.ruleImageView.contentMode = UIViewContentModeScaleToFill; self.ruleImageView.frame = CGRectMake((SCREEN_WIDTH-ScaleWidth(188))/2, 0, ScaleWidth(188), ScaleWidth(90)); [self.bgView addSubview:self.ruleImageView]; self.bgCoverView = [[UIView alloc] initWithFrame:CGRectMake(16, self.ruleImageView.bottom+12, self.bgView.width-32, self.bgView.height-self.ruleImageView.bottom-24)]; self.bgCoverView.backgroundColor = RGB16A(0x000000, 0.5); [self.bgView addSubview:self.bgCoverView]; self.drawRankBtn = [[UIButton alloc] initWithFrame:CGRectMake((self.bgCoverView.width)/2-88-8, 20, 88, 32)]; [self.drawRankBtn setTitle:@"抽奖榜单" forState:(UIControlStateNormal)]; [self.drawRankBtn setTitleColor:RGB16(0xE8E8E8) forState:(UIControlStateNormal)]; self.drawRankBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14]; [self.drawRankBtn setBackgroundImage:[UIImage imageWithColor:RGB16(0xD0C2FF)] forState:(UIControlStateNormal)]; [self.drawRankBtn setBackgroundImage:[UIImage imageWithColor:RGB16(0x7C57FB)] forState:(UIControlStateSelected)]; [self.drawRankBtn addTarget:self action:@selector(drawRankAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.bgCoverView addSubview:self.drawRankBtn]; self.drawRankBtn.selected = YES; self.luckRankBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.drawRankBtn.right+16, 20, 88, 32)]; [self.luckRankBtn setTitle:@"幸运榜单" forState:(UIControlStateNormal)]; [self.luckRankBtn setTitleColor:RGB16(0xE8E8E8) forState:(UIControlStateNormal)]; self.luckRankBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14]; [self.luckRankBtn setBackgroundImage:[UIImage imageWithColor:RGB16(0xD0C2FF)] forState:(UIControlStateNormal)]; [self.luckRankBtn setBackgroundImage:[UIImage imageWithColor:RGB16(0x7C57FB)] forState:(UIControlStateSelected)]; [self.luckRankBtn addTarget:self action:@selector(luckRankAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.bgCoverView addSubview:self.luckRankBtn]; [self.drawRankBtn addRoundedCornersWithRadius:16]; [self.luckRankBtn addRoundedCornersWithRadius:16]; [self.bgCoverView addSubview:self.tableView]; } -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ return touch.view == self; } -(void)setRoomId:(NSString *)roomId{ _roomId = roomId; self.page = 1; [self getRecordListWithType:@"1"]; } -(void)getRecordListWithType:(NSString*)type{ if (![self.roomId isExist]) { return; } MJWeakSelf NSDictionary *parameters = @{ @"room_id":self.roomId?self.roomId:@"", @"page":[NSNumber numberWithInteger:self.page] }; if ([type isEqualToString:@"1"]) { NSString *url = [NSString stringWithFormat:@"%@%@",ServerUrl,@"api/BlindBoxTurntable/get_xlh_all_record"]; [[QXRequset shareInstance] postWithUrl:url parameters:parameters needCache:NO success:^(id responseObject) { if (weakSelf.page == 1) { [weakSelf.allRecordArray removeAllObjects]; } NSArray *arr = [NSArray yy_modelArrayWithClass:[QXActivityRecordModel class] json:responseObject[@"data"]]; [weakSelf.allRecordArray addObjectsFromArray:arr]; [weakSelf.tableView reloadData]; if (arr.count == 0) { weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData; }else{ [weakSelf.tableView.mj_footer endRefreshing]; } [weakSelf.tableView.mj_header endRefreshing]; } fail:^(NSError *error, NSString *msg, NSURLSessionDataTask *task) { [weakSelf.tableView.mj_footer endRefreshing]; [weakSelf.tableView.mj_header endRefreshing]; }]; }else{ NSString *url = [NSString stringWithFormat:@"%@%@",ServerUrl,@"api/BlindBoxTurntable/get_xlh_ranking"]; [[QXRequset shareInstance] postWithUrl:url parameters:parameters needCache:NO success:^(id responseObject) { if (weakSelf.page == 1) { [weakSelf.allRecordArray removeAllObjects]; } NSArray *arr = [NSArray yy_modelArrayWithClass:[QXActivityRecordModel class] json:responseObject[@"data"]]; [weakSelf.allRecordArray addObjectsFromArray:arr]; [weakSelf.tableView reloadData]; if (arr.count == 0) { weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData; }else{ [weakSelf.tableView.mj_footer endRefreshing]; } [weakSelf.tableView.mj_header endRefreshing]; } fail:^(NSError *error, NSString *msg, NSURLSessionDataTask *task) { [weakSelf.tableView.mj_footer endRefreshing]; [weakSelf.tableView.mj_header endRefreshing]; }]; } } -(void)drawRankAction{ self.drawRankBtn.selected = YES; self.luckRankBtn.selected = NO; self.page = 1; [self getRecordListWithType:@"1"]; } -(void)luckRankAction{ self.drawRankBtn.selected = NO; self.luckRankBtn.selected = YES; self.page = 1; [self getRecordListWithType:@"2"]; } -(UITableView *)tableView{ if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.drawRankBtn.bottom+10, self.bgCoverView.width, self.bgCoverView.height-self.drawRankBtn.bottom-10) style:(UITableViewStylePlain)]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.rowHeight = 70; _tableView.backgroundColor = [UIColor clearColor]; MJWeakSelf _tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{ weakSelf.page++; if (self.drawRankBtn.selected) { [weakSelf getRecordListWithType:@"1"]; }else{ [weakSelf getRecordListWithType:@"2"]; } }]; _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ weakSelf.page = 1; if (self.drawRankBtn.selected) { [weakSelf getRecordListWithType:@"1"]; }else{ [weakSelf getRecordListWithType:@"2"]; } }]; } return _tableView; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.allRecordArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (self.drawRankBtn.selected) { QXMeetRankCell *cell = [QXMeetRankCell cellWithTableView:tableView]; cell.model = self.allRecordArray[indexPath.row]; return cell; }else{ QXMeetRankLuckCell *cell = [QXMeetRankLuckCell cellWithTableView:tableView]; cell.model = self.allRecordArray[indexPath.row]; return cell; } } -(void)showInView:(UIView *)view{ self.bgView.y = SCREEN_HEIGHT; [view addSubview:self]; [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = SCREEN_HEIGHT-ScaleWidth(663); }]; } -(void)hide{ // [self stopSlowAnimate]; [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = SCREEN_HEIGHT; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } -(NSMutableArray *)allRecordArray{ if (!_allRecordArray) { _allRecordArray = [NSMutableArray array]; } return _allRecordArray; } @end @implementation QXMeetRankCell +(instancetype)cellWithTableView:(UITableView*)tableView{ static NSString *cellId = @"QXMeetRankCell"; QXMeetRankCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; if (!cell) { cell = [[QXMeetRankCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellId]; cell.backgroundColor = [UIColor clearColor]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self initSubviews]; } return self; } -(void)setModel:(QXActivityRecordModel *)model{ _model = model; self.giftInfoLabel.text = [NSString stringWithFormat:@"%@x%@",model.gift_name,model.count]; self.recieveInfoLabel.text = [NSString stringWithFormat:@"%@",model.nickname]; [self.giftImageView sd_setImageWithURL:[NSURL URLWithString:model.base_image]]; self.timeLabel.text = model.createtime; } -(void)initSubviews{ self.contentView.backgroundColor = [UIColor clearColor]; self.recieveInfoLabel = [[UILabel alloc] init]; self.recieveInfoLabel.textColor = RGB16(0xffffff); self.recieveInfoLabel.font = [UIFont systemFontOfSize:14]; [self.contentView addSubview:self.recieveInfoLabel]; [self.recieveInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(12); make.left.mas_equalTo(12); make.height.mas_equalTo(24); }]; self.timeLabel = [[UILabel alloc] init]; self.timeLabel.textColor = RGB16(0x5B5B5B); self.timeLabel.font = [UIFont systemFontOfSize:10]; [self.contentView addSubview:self.timeLabel]; [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.contentView).offset(-12); make.left.mas_equalTo(12); make.height.mas_equalTo(17); }]; self.giftImageView = [[UIImageView alloc] init]; self.giftImageView.contentMode = UIViewContentModeScaleAspectFit; [self.contentView addSubview:self.giftImageView]; [self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView).offset(-12); make.height.width.mas_equalTo(21); make.centerY.equalTo(self.recieveInfoLabel); }]; self.giftInfoLabel = [[UILabel alloc] init]; self.giftInfoLabel.textColor = RGB16(0xffffff); self.giftInfoLabel.font = [UIFont systemFontOfSize:16]; [self.contentView addSubview:self.giftInfoLabel]; [self.giftInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.giftImageView.mas_left); make.centerY.equalTo(self.recieveInfoLabel); }]; self.bottomLine = [[UIView alloc] init]; self.bottomLine.backgroundColor = RGB16(0xffffff); [self.contentView addSubview:self.bottomLine]; [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.contentView); make.left.mas_equalTo(12); make.right.mas_equalTo(-12); make.height.mas_equalTo(1); }]; } @end @implementation QXMeetRankLuckCell +(instancetype)cellWithTableView:(UITableView*)tableView{ static NSString *cellId = @"QXMeetRankLuckCell"; QXMeetRankLuckCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; if (!cell) { cell = [[QXMeetRankLuckCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellId]; cell.backgroundColor = [UIColor clearColor]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self initSubviews]; } return self; } -(void)setModel:(QXActivityRecordModel *)model{ _model = model; self.numberLabel.text = model.periods; self.giftInfoLabel.text = [NSString stringWithFormat:@"%@",model.gift_name]; self.recieveInfoLabel.text = [NSString stringWithFormat:@"%@",model.nickname]; [self.giftImageView sd_setImageWithURL:[NSURL URLWithString:model.base_image]]; self.timeLabel.text = model.createtime; } -(void)initSubviews{ self.contentView.backgroundColor = [UIColor clearColor]; self.numberLabel = [[UILabel alloc] init]; self.numberLabel.textColor = RGB16(0xA085FF); self.numberLabel.font = [UIFont systemFontOfSize:14]; [self.contentView addSubview:self.numberLabel]; [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(12); make.left.mas_equalTo(12); make.height.mas_equalTo(21); }]; self.timeLabel = [[UILabel alloc] init]; self.timeLabel.textColor = RGB16(0x5B5B5B); self.timeLabel.font = [UIFont systemFontOfSize:10]; [self.contentView addSubview:self.timeLabel]; [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-12); make.centerY.equalTo(self.numberLabel); }]; self.recieveInfoLabel = [[UILabel alloc] init]; self.recieveInfoLabel.textColor = RGB16(0xffffff); self.recieveInfoLabel.font = [UIFont systemFontOfSize:14]; [self.contentView addSubview:self.recieveInfoLabel]; [self.recieveInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(-12); make.left.mas_equalTo(12); make.height.mas_equalTo(21); }]; self.giftImageView = [[UIImageView alloc] init]; self.giftImageView.contentMode = UIViewContentModeScaleAspectFit; [self.contentView addSubview:self.giftImageView]; [self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView).offset(-12); make.height.width.mas_equalTo(21); make.centerY.equalTo(self.recieveInfoLabel); }]; self.giftInfoLabel = [[UILabel alloc] init]; self.giftInfoLabel.textColor = RGB16(0xffffff); self.giftInfoLabel.font = [UIFont systemFontOfSize:16]; [self.contentView addSubview:self.giftInfoLabel]; [self.giftInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.giftImageView.mas_left); make.centerY.equalTo(self.recieveInfoLabel); }]; self.bottomLine = [[UIView alloc] init]; self.bottomLine.backgroundColor = RGB16(0xffffff); [self.contentView addSubview:self.bottomLine]; [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.contentView); make.left.mas_equalTo(12); make.right.mas_equalTo(-12); make.height.mas_equalTo(1); }]; } @end