// // QXFirstRechargeView.m // QXLive // // Created by 启星 on 2025/10/12. // #import "QXFirstRechargeView.h" #import "QXHomePageNetwork.h" #import "QXGiftCell.h" @interface QXFirstRechargeView() @property (nonatomic,strong)UIImageView *lightBgImageView; @property (nonatomic,strong)UIImageView *bgImageView; @property (nonatomic,strong)UILabel *timeDownLabel; @property (nonatomic,strong)UIView *giftBgView; //@property (nonatomic,strong)UIButton *ruleBtn; @property (nonatomic,strong)UICollectionView *collectionView; @property (nonatomic,strong)UILabel *messageLabel; @property (nonatomic,strong)UIButton *getBtn; @property (nonatomic,strong)UIButton *closeBtn; @property (nonatomic,strong)QXFirstRechargeModel *model; @end @implementation QXFirstRechargeView - (instancetype)init { self = [super init]; if (self) { self.frame = CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(582)); [self initSubViews]; } return self; } -(void)initSubViews{ self.lightBgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"a_pop_bg"]]; [self addSubview:self.lightBgImageView]; [self.lightBgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.bottom.equalTo(self); }]; self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"a_first_recharge_bg"]]; [self addSubview:self.bgImageView]; [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.centerY.equalTo(self); make.size.mas_equalTo(CGSizeMake(ScaleWidth(287), ScaleWidth(338))); }]; self.giftBgView = [[UIView alloc] init]; // self.giftBgView.backgroundColor = [UIColor whiteColor]; [self.giftBgView addRoundedCornersWithRadius:13]; [self addSubview:self.giftBgView]; [self.giftBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.bgImageView).offset(ScaleWidth(135)); make.left.equalTo(self.bgImageView).offset(ScaleWidth(18)); make.right.equalTo(self.bgImageView).offset(-ScaleWidth(22)); make.bottom.equalTo(self.bgImageView).offset(-ScaleWidth(51)); }]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.itemSize = CGSizeMake((ScaleWidth(287-18-22-12*2-3*8))/4, ScaleWidth(76)); layout.minimumLineSpacing = 8; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; [self.collectionView registerNib:[UINib nibWithNibName:@"QXGiftCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXGiftCell"]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.showsHorizontalScrollIndicator = NO; self.collectionView.bounces = NO; self.collectionView.pagingEnabled = YES; [self.giftBgView addSubview:self.collectionView]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12); make.top.mas_equalTo(ScaleWidth(16)); make.height.mas_equalTo(ScaleWidth(76)); make.right.mas_equalTo(-12); }]; self.messageLabel = [[UILabel alloc] init]; self.messageLabel.font = [UIFont systemFontOfSize:12]; self.messageLabel.numberOfLines = 0; self.messageLabel.text = QXText(@"充值6元即可获得总价值888金币的道具或装扮"); self.messageLabel.textColor = QXConfig.textColor; [self.giftBgView addSubview:self.messageLabel]; [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12); make.right.mas_equalTo(-12); make.top.equalTo(self.collectionView.mas_bottom).offset(2); make.bottom.equalTo(self.giftBgView).offset(-5); }]; self.getBtn = [[UIButton alloc] init]; [self.getBtn addRoundedCornersWithRadius:21]; self.getBtn.backgroundColor = QXConfig.themeColor; [self.getBtn setTitle:QXText(@"立即充值") forState:(UIControlStateNormal)]; [self.getBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)]; self.getBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [self.getBtn addTarget:self action:@selector(getAction) forControlEvents:(UIControlEventTouchUpInside)]; [self addSubview:self.getBtn]; [self.getBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.bgImageView).offset(-ScaleWidth(16)); make.height.mas_equalTo(42); make.right.equalTo(self.bgImageView).offset(-48); make.left.equalTo(self.bgImageView).offset(48); }]; self.closeBtn = [[UIButton alloc] init]; [self.closeBtn setBackgroundImage:[UIImage imageNamed:@"home_white_close"] forState:(UIControlStateNormal)]; [self.closeBtn addTarget:self action:@selector(closeAction) forControlEvents:(UIControlEventTouchUpInside)]; [self addSubview:self.closeBtn]; [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self); make.top.equalTo(self.bgImageView.mas_bottom).offset(8); make.height.width.mas_equalTo(30); }]; [self getFirstRechargeGiftList]; } -(void)getFirstRechargeGiftList{ MJWeakSelf [QXHomePageNetwork getFirstRechargeGiftListSuccessBlock:^(NSArray * _Nonnull list) { QXFirstRechargeModel *md = list.firstObject; if (md) { weakSelf.model = md; [weakSelf.collectionView reloadData]; } } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(msg); if (weakSelf.refreshBlcock) { weakSelf.refreshBlcock(); } }]; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.model.gift_list.count; } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ QXGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXGiftCell" forIndexPath:indexPath]; cell.cellType = QXGiftCellTypeNiceGift; cell.niceGiftModel = self.model.gift_list[indexPath.row]; return cell; } // 立即领取 -(void)getAction{ if (self.rechargeActionBlock) { self.rechargeActionBlock(self.model.money,self.model.gift_bag_id); } } -(void)closeAction{ if (self.closeActionBlock) { self.closeActionBlock(); } } @end