// // QXSignCoinListView.m // QXLive // // Created by 启星 on 2025/11/26. // #import "QXSignCoinListView.h" #import "QXSignCoinCell.h" #import "QXMineNetwork.h" @interface QXSignCoinListView() @property (nonatomic,strong)UIView *bgView; @property (nonatomic,strong)UIView *topView; @property (nonatomic,strong)UILabel *topLeftLabel; @property (nonatomic,strong)UIImageView *headerView; @property (nonatomic,strong)UILabel *topNicknameLabel; @property (nonatomic,strong)UILabel *topDescLabel; @property (nonatomic,strong)UICollectionView *collectionView; @property (nonatomic,strong)UIView *bottomView; @property (nonatomic,strong)UIImageView *coinImageView; @property (nonatomic,strong)UILabel *coinLabel; @property (nonatomic,strong)UIButton *rechargeBtn; @property (nonatomic,strong)QXRoomRelationModel*selectedModel; @property (nonatomic,strong)NSMutableArray *dataArray; @property (nonatomic,strong)NSString* coin; @end @implementation QXSignCoinListView - (instancetype)init { self = [super init]; if (self) { self.frame = UIScreen.mainScreen.bounds; [self initSubviews]; } return self; } -(void)initSubviews{ UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)]; self.backgroundColor = RGB16A(0x000000, 0.3); tap.delegate = self; [self addGestureRecognizer:tap]; self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(410)+kSafeAreaBottom)]; self.bgView.backgroundColor = RGB16(0x103E30); [self.bgView addRoundedCornersWithRadius:14 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)]; [self addSubview:self.bgView]; self.topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, 77)]; [self.bgView addSubview:self.topView]; self.topLeftLabel = [[UILabel alloc] init]; self.topLeftLabel.font = [UIFont systemFontOfSize:12]; self.topLeftLabel.textColor = RGB16A(0xffffff,0.45); self.topLeftLabel.text = @"竞拍"; [self.topView addSubview:self.topLeftLabel]; [self.topLeftLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(16); make.centerY.equalTo(self.topView); }]; self.headerView = [[UIImageView alloc] init]; self.headerView.contentMode = UIViewContentModeScaleAspectFill; [self.headerView addRoundedCornersWithRadius:25]; self.headerView.layer.borderColor = RGB16(0xffffff).CGColor; self.headerView.layer.borderWidth = 2; [self.topView addSubview:self.headerView]; [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.mas_equalTo(50); make.centerY.equalTo(self.topLeftLabel); make.left.equalTo(self.topLeftLabel.mas_right).offset(2); }]; self.topNicknameLabel = [[UILabel alloc] init]; self.topNicknameLabel.font = [UIFont systemFontOfSize:12]; self.topNicknameLabel.textColor = RGB16(0xffffff); [self.topView addSubview:self.topNicknameLabel]; [self.topNicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.headerView.mas_right).offset(4); make.centerY.equalTo(self.topLeftLabel); }]; self.topDescLabel = [[UILabel alloc] init]; self.topDescLabel.font = [UIFont systemFontOfSize:12]; self.topDescLabel.textColor = RGB16(0xffffff); self.topDescLabel.numberOfLines = 0; self.topDescLabel.text = @"如果没有成功拍下ta,金币将退回给您"; [self.topView addSubview:self.topDescLabel]; [self.topDescLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-16); make.width.mas_equalTo(ScaleWidth(135)); make.centerY.equalTo(self.topLeftLabel); }]; self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.bgView.height-kSafeAreaBottom-32, self.bgView.width, 32)]; [self.bgView addSubview:self.bottomView]; self.coinImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_live_gift_corn"]]; [self.bottomView addSubview:self.coinImageView]; [self.coinImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(16); make.width.height.mas_equalTo(14); make.centerY.equalTo(self.bottomView); }]; self.coinLabel = [[UILabel alloc] init]; self.coinLabel.font = [UIFont systemFontOfSize:12]; self.coinLabel.textColor = RGB16(0xffffff); self.coinLabel.numberOfLines = 0; self.coinLabel.text = @"0"; [self.bottomView addSubview:self.coinLabel]; [self.coinLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.coinImageView.mas_right); make.centerY.equalTo(self.coinImageView); }]; self.rechargeBtn = [[UIButton alloc] init]; [self.rechargeBtn setTitle:@"充值" forState:(UIControlStateNormal)]; self.rechargeBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [self.rechargeBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)]; self.rechargeBtn.backgroundColor = QXConfig.themeColor; [self.rechargeBtn addRoundedCornersWithRadius:16]; [self.rechargeBtn addTarget:self action:@selector(rechargeAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.bottomView addSubview:self.rechargeBtn]; [self.rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-16); make.height.mas_equalTo(32); make.width.mas_equalTo(60); make.centerY.equalTo(self.bottomView); }]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 12; layout.minimumInteritemSpacing = 12; layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16); layout.itemSize = CGSizeMake((SCREEN_WIDTH-16*2-12*3)/4, ScaleWidth(119)); layout.scrollDirection = UICollectionViewScrollDirectionVertical; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.topView.bottom+10, self.bgView.width, self.bottomView.top-self.topView.bottom-20) collectionViewLayout:layout]; [self.collectionView registerNib:[UINib nibWithNibName:@"QXSignCoinCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXSignCoinCell"]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.showsHorizontalScrollIndicator = NO; self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.bounces = NO; self.collectionView.backgroundColor = [UIColor clearColor]; [self.bgView addSubview:self.collectionView]; } -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ return touch.view == self; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.dataArray.count; } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ QXSignCoinCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXSignCoinCell" forIndexPath:indexPath]; cell.model = self.dataArray[indexPath.row]; return cell; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if (self.delegate && [self.delegate respondsToSelector:@selector(coinListDidSignWithCoin:)]) { QXRoomRelationModel *md = self.dataArray[indexPath.row]; [self.delegate coinListDidSignWithCoin:md.name]; } } -(void)rechargeAction{ if (self.delegate && [self.delegate respondsToSelector:@selector(coinListDidClickRecharge)]) { [self.delegate coinListDidClickRecharge]; } } -(void)setSignId:(NSString *)signId{ _signId = signId; [self getCoinList]; } -(void)getMyWallet{ MJWeakSelf [QXMineNetwork getWalletInfoSuccessBlock:^(NSString * _Nonnull coin, NSString * _Nonnull earnings, NSString * _Nonnull title, NSString * _Nonnull url) { weakSelf.coinLabel.text = coin; weakSelf.coin = coin; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; self.rechargeBtn.hidden = !QXGlobal.shareGlobal.isOpenRecharge; } -(void)setPitModel:(QXRoomPitModel *)pitModel{ _pitModel = pitModel; [self.headerView sd_setImageWithURL:[NSURL URLWithString:pitModel.avatar]]; self.topNicknameLabel.text = pitModel.nickname; } -(void)getCoinList{ MJWeakSelf self.selectedModel = nil; [self.collectionView reloadData]; [QXMineNetwork signCoinListWithSignId:self.signId successBlock:^(NSArray * _Nonnull list) { [weakSelf.dataArray removeAllObjects]; for (NSString*title in list) { QXRoomRelationModel *md = [[QXRoomRelationModel alloc] init]; md.name = title; [weakSelf.dataArray addObject:md]; } [weakSelf.collectionView reloadData]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(msg); // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // [weakSelf getCoinList]; // }); }]; } -(void)refreshCoinListWith:(NSArray *)coinList{ [self getMyWallet]; [self.dataArray removeAllObjects]; for (NSString*title in coinList) { QXRoomRelationModel *md = [[QXRoomRelationModel alloc] init]; md.name = title; [self.dataArray addObject:md]; } [self.collectionView reloadData]; } -(void)showInView:(UIView *)view{ [self getCoinList]; [self getMyWallet]; self.bgView.y = SCREEN_HEIGHT; [view addSubview:self]; [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = SCREEN_HEIGHT-ScaleWidth(410)-kSafeAreaBottom; }]; } -(void)hide{ if (!self.superview) { NSLog(@"⚠️ View already removed from superview"); return; } [UIView animateWithDuration:0.3 animations:^{ if (self.bgView) { self.bgView.y = SCREEN_HEIGHT; } } completion:^(BOOL finished) { // 检查是否已经被移除 if (self.superview) { [self removeFromSuperview]; } // 避免在 dealloc 过程中访问其他属性 // 不要在 completion block 中访问或设置其他属性 }]; } -(NSMutableArray *)dataArray{ if (!_dataArray) { _dataArray = [NSMutableArray array]; } return _dataArray; } @end