Files
midi_ios/QXLive/Tabbar/弹窗/QXFirstRechargePopView.m

311 lines
14 KiB
Mathematica
Raw Normal View History

2025-08-14 10:07:49 +08:00
//
// QXFirstRechargePopView.m
// QXLive
//
// Created by on 2025/5/13.
//
#import "QXFirstRechargePopView.h"
#import "GKPageControl.h"
#import <NSAttributedString+YYText.h>
#import "QXGiftCell.h"
#import "QXHomePageNetwork.h"
@interface QXFirstRechargePopView()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong)UIImageView *lightBgImageView;
@property (nonatomic,strong)UIImageView *bgImageView;
@property (nonatomic,strong)UILabel *priceLabel;
@property (nonatomic,strong)UIButton *firstBtn;
@property (nonatomic,strong)UIButton *secondBtn;
@property (nonatomic,strong)UIButton *thirdBtn;
@property (nonatomic,strong)UIButton *selectedBtn;
@property (nonatomic,strong)UIView *giftBgView;
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)GKPageControl *pageControl;
@property (nonatomic,strong)UIButton *getBtn;
@property (nonatomic,strong)UIButton *closeBtn;
@property (nonatomic,strong)QXFirstRechargeModel *md1;
@property (nonatomic,strong)QXFirstRechargeModel *md2;
@property (nonatomic,strong)QXFirstRechargeModel *md3;
@property (nonatomic,strong)QXFirstRechargeModel *smd;
@end
@implementation QXFirstRechargePopView
- (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_pop_first_recharge"]];
[self addSubview:self.bgImageView];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.centerY.equalTo(self);
make.size.mas_equalTo(CGSizeMake(ScaleWidth(275), ScaleWidth(338)));
}];
self.priceLabel = [[UILabel alloc] init];
// self.priceLabel.attributedText =
[self addSubview:self.priceLabel];
[self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.bgImageView).offset(ScaleWidth(98));
make.left.equalTo(self.bgImageView).offset(ScaleWidth(119));
make.height.mas_equalTo(ScaleWidth(20));
make.right.equalTo(self.bgImageView).offset(-5);
}];
self.firstBtn = [[UIButton alloc] init];
self.firstBtn.hidden = YES;
UIImage *firstNorImage = [UIImage imageWithColor:RGB16(0xFFFFFF)];
UIImage *firstSelImage = [UIImage imageWithColor:RGB16(0xF4DF39)];
[self.firstBtn setBackgroundImage:firstNorImage forState:(UIControlStateNormal)];
[self.firstBtn setBackgroundImage:firstSelImage forState:(UIControlStateSelected)];
self.firstBtn.selected = YES;
// [self.firstBtn setTitle:@"9元" forState:(UIControlStateNormal)];
[self.firstBtn setTitleColor:RGB16(0x333333) forState:(UIControlStateNormal)];
[self.firstBtn addRoundedCornersWithRadius:ScaleWidth(13)];
self.firstBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[self.firstBtn addTarget:self action:@selector(rechargeSelectedAction:) forControlEvents:(UIControlEventTouchUpInside)];
self.selectedBtn = self.firstBtn;
[self addSubview:self.firstBtn];
[self.firstBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.bgImageView).offset(ScaleWidth(24));
make.top.equalTo(self.priceLabel.mas_bottom).offset(ScaleWidth(11));
make.height.mas_equalTo(ScaleWidth(26));
make.width.mas_equalTo(ScaleWidth(42));
}];
self.secondBtn = [[UIButton alloc] init];
self.secondBtn.hidden = YES;
UIImage *secondNorImage = [UIImage imageWithColor:RGB16(0xFFFFFF)];
UIImage *secondSelImage = [UIImage imageWithColor:RGB16(0xF4DF39)];
[self.secondBtn setBackgroundImage:secondNorImage forState:(UIControlStateNormal)];
[self.secondBtn setBackgroundImage:secondSelImage forState:(UIControlStateSelected)];
// [self.secondBtn setTitle:@"30元" forState:(UIControlStateNormal)];
[self.secondBtn setTitleColor:RGB16(0x333333) forState:(UIControlStateNormal)];
[self.secondBtn addRoundedCornersWithRadius:ScaleWidth(13)];
self.secondBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[self.secondBtn addTarget:self action:@selector(rechargeSelectedAction:) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.secondBtn];
[self.secondBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.firstBtn.mas_right).offset(12);
make.top.equalTo(self.firstBtn);
make.height.mas_equalTo(ScaleWidth(26));
make.width.mas_equalTo(ScaleWidth(42));
}];
self.thirdBtn = [[UIButton alloc] init];
self.thirdBtn.hidden = YES;
UIImage *thirdNorImage = [UIImage imageWithColor:RGB16(0xFFFFFF)];
UIImage *thirdSelImage = [UIImage imageWithColor:RGB16(0xF4DF39)];
[self.thirdBtn setBackgroundImage:thirdNorImage forState:(UIControlStateNormal)];
[self.thirdBtn setBackgroundImage:thirdSelImage forState:(UIControlStateSelected)];
// [self.thirdBtn setTitle:@"60元" forState:(UIControlStateNormal)];
[self.thirdBtn setTitleColor:RGB16(0x333333) forState:(UIControlStateNormal)];
[self.thirdBtn addRoundedCornersWithRadius:ScaleWidth(13)];
self.thirdBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[self.thirdBtn addTarget:self action:@selector(rechargeSelectedAction:) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.thirdBtn];
[self.thirdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.secondBtn.mas_right).offset(12);
make.top.equalTo(self.firstBtn);
make.height.mas_equalTo(ScaleWidth(26));
make.width.mas_equalTo(ScaleWidth(42));
}];
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.firstBtn.mas_bottom).offset(ScaleWidth(12));
make.left.equalTo(self.bgImageView).offset(24);
make.right.equalTo(self.bgImageView).offset(-24);
make.height.mas_equalTo(108);
}];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake((ScaleWidth(275)-24*2-3*8-12*2)/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(12);
make.height.mas_equalTo(ScaleWidth(76));
make.right.mas_equalTo(-12);
}];
_pageControl = [[GKPageControl alloc] init];
_pageControl.style = GKPageControlStyleRectangle;
_pageControl.dotWidth = 15;
_pageControl.dotHeight = 5;
_pageControl.dotMargin = 2;
_pageControl.hidden = YES;
_pageControl.pageIndicatorTintColor = RGB16(0xEBEBEB);
_pageControl.currentPageIndicatorTintColor = QXConfig.textColor;
[self.giftBgView addSubview:self.pageControl];
[self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.collectionView.mas_bottom).offset(3);
make.height.mas_equalTo(5);
make.right.mas_equalTo(-48);
make.left.mas_equalTo(48);
}];
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(rechargeAction) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.getBtn];
[self.getBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.bgImageView).offset(-12);
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)reloadData{
[self getFirstRechargeGiftList];
}
-(void)getFirstRechargeGiftList{
MJWeakSelf
[QXHomePageNetwork getFirstRechargeGiftListSuccessBlock:^(NSArray<QXFirstRechargeModel *> * _Nonnull list) {
for (int i = 0; i<list.count; i++) {
if (i == 0) {
weakSelf.md1 = list[i];
weakSelf.firstBtn.hidden = NO;
[weakSelf.firstBtn setTitle:weakSelf.md1.name forState:(UIControlStateNormal)];
continue;
}
if (i == 1) {
weakSelf.md2 = list[i];
weakSelf.secondBtn.hidden = NO;
[weakSelf.secondBtn setTitle:weakSelf.md2.name forState:(UIControlStateNormal)];
continue;
}
if (i == 2) {
weakSelf.md3 = list[i];
weakSelf.thirdBtn.hidden = NO;
[weakSelf.thirdBtn setTitle:weakSelf.md3.name forState:(UIControlStateNormal)];
continue;
}
}
[weakSelf rechargeSelectedAction:weakSelf.firstBtn];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
showToast(msg);
}];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if ([scrollView isKindOfClass:[UICollectionView class]]) {
long offsetX = (long)scrollView.contentOffset.x;
int width = ScaleWidth(275-15*2-12*2-3*8);
int remainder = offsetX % width;
NSInteger index;
if (remainder>(width)/2) {
index = offsetX/width+1;
}else{
index = offsetX/width;
}
self.pageControl.currentPage = index;
}
}
//-(void)setGiftArray:(NSArray *)giftArray{
// _giftArray = giftArray;
// self.pageControl.numberOfPages = giftArray.count/4+1;
// self.pageControl.currentPage = 0;
// [self.collectionView reloadData];
//}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.giftArray.count;
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
QXGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXGiftCell" forIndexPath:indexPath];
cell.roomGiftModel = self.giftArray[indexPath.row];
cell.cellType = QXGiftCellTypeNiceGift;
return cell;
}
-(void)rechargeSelectedAction:(UIButton*)sender{
self.selectedBtn.selected = !self.selectedBtn.selected;
sender.selected = !sender.selected;
self.selectedBtn = sender;
QXFirstRechargeModel *md = nil;
if (sender == self.firstBtn) {
md = self.md1;
self.giftArray = self.md1.gift_list;
}else if (sender == self.secondBtn){
self.giftArray = self.md2.gift_list;
md = self.md2;
}else if (sender == self.thirdBtn){
self.giftArray = self.md3.gift_list;
md = self.md3;
}
self.smd = md;
if (md == nil) {
return;
}
NSAttributedString *attr = [self changePrice:md.title1 giftPrice:md.title2];
self.priceLabel.attributedText = attr;
self.pageControl.numberOfPages = self.giftArray.count/4+1;
self.pageControl.currentPage = 0;
[self.collectionView reloadData];
}
-(NSAttributedString *)changePrice:(NSString*)price giftPrice:(NSString*)giftPrice{
NSString *str = [NSString stringWithFormat:@"%@ %@",price,giftPrice];
2025-09-19 11:38:43 +08:00
NSAttributedString *attr = [str deleteLineWithTextColor:RGB16(0x333333) lineColor:RGB16(0x333333) range:[str rangeOfString:giftPrice]];
2025-08-14 10:07:49 +08:00
NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithAttributedString:attr];
2025-09-19 11:38:43 +08:00
[att yy_setFont:[UIFont boldSystemFontOfSize:14] range:[str rangeOfString:price]];
2025-08-14 10:07:49 +08:00
[att yy_setFont:[UIFont systemFontOfSize:12] range:[str rangeOfString:giftPrice]];
2025-09-19 11:38:43 +08:00
[att yy_setColor:RGB16(0xFFE200) range:[str rangeOfString:price]];
2025-08-14 10:07:49 +08:00
return att;
}
-(void)rechargeAction{
if (self.rechargeActionBlock) {
self.rechargeActionBlock(self.smd.money);
}
}
-(void)closeAction{
if (self.closeActionBlock) {
self.closeActionBlock();
}
}
@end