377 lines
17 KiB
Objective-C
377 lines
17 KiB
Objective-C
//
|
|
// QXNewPeoplePopView.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/5/13.
|
|
//
|
|
|
|
#import "QXNewPeoplePopView.h"
|
|
#import "GKPageControl.h"
|
|
#import <NSAttributedString+YYText.h>
|
|
#import "QXGiftCell.h"
|
|
#import "QXHomePageNetwork.h"
|
|
|
|
@interface QXNewPeoplePopView()<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 *oneMouthBtn;
|
|
@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)QXNiceGiftRechargeModel *md1;
|
|
@property (nonatomic,strong)QXNiceGiftRechargeModel *md2;
|
|
@property (nonatomic,strong)QXNiceGiftRechargeModel *md3;
|
|
@property (nonatomic,strong)QXNiceGiftRechargeModel *md4;
|
|
@property (nonatomic,strong)QXNiceGiftRechargeModel *smd;
|
|
|
|
@end
|
|
|
|
@implementation QXNewPeoplePopView
|
|
|
|
- (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_new_user_recharge"]];
|
|
self.bgImageView.contentMode = UIViewContentModeScaleToFill;
|
|
[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.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)];
|
|
UIImage *firstDisImage = [UIImage imageWithColor:RGB16(0xE9E9E9)];
|
|
[self.firstBtn setBackgroundImage:firstNorImage forState:(UIControlStateNormal)];
|
|
[self.firstBtn setBackgroundImage:firstSelImage forState:(UIControlStateSelected)];
|
|
[self.firstBtn setBackgroundImage:firstDisImage forState:(UIControlStateDisabled)];
|
|
// 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)];
|
|
UIImage *secondDisImage = [UIImage imageWithColor:RGB16(0xE9E9E9)];
|
|
[self.secondBtn setBackgroundImage:secondNorImage forState:(UIControlStateNormal)];
|
|
[self.secondBtn setBackgroundImage:secondSelImage forState:(UIControlStateSelected)];
|
|
[self.secondBtn setBackgroundImage:secondDisImage forState:(UIControlStateDisabled)];
|
|
// [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(50));
|
|
}];
|
|
|
|
|
|
self.thirdBtn = [[UIButton alloc] init];
|
|
self.thirdBtn.hidden = YES;
|
|
UIImage *thirdNorImage = [UIImage imageWithColor:RGB16(0xFFFFFF)];
|
|
UIImage *thirdSelImage = [UIImage imageWithColor:RGB16(0xF4DF39)];
|
|
UIImage *thirdDisImage = [UIImage imageWithColor:RGB16(0xE9E9E9)];
|
|
[self.thirdBtn setBackgroundImage:thirdNorImage forState:(UIControlStateNormal)];
|
|
[self.thirdBtn setBackgroundImage:thirdSelImage forState:(UIControlStateSelected)];
|
|
[self.thirdBtn setBackgroundImage:thirdDisImage forState:(UIControlStateDisabled)];
|
|
// [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(50));
|
|
}];
|
|
|
|
self.oneMouthBtn = [[UIButton alloc] init];
|
|
self.oneMouthBtn.hidden = YES;
|
|
UIImage *one_mouth_norImage = [UIImage imageNamed:@"one_mouth_money"];
|
|
UIImage *one_mouth_selImage = [UIImage imageNamed:@"one_mouth_money_sel"];
|
|
[self.oneMouthBtn setBackgroundImage:one_mouth_norImage forState:(UIControlStateNormal)];
|
|
[self.oneMouthBtn setBackgroundImage:one_mouth_selImage forState:(UIControlStateSelected)];
|
|
[self.oneMouthBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)];
|
|
[self.oneMouthBtn addRoundedCornersWithRadius:ScaleWidth(13)];
|
|
self.oneMouthBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
[self.oneMouthBtn addTarget:self action:@selector(rechargeSelectedAction:) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[self addSubview:self.oneMouthBtn];
|
|
[self.oneMouthBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.equalTo(self.bgImageView.mas_right).offset(-27);
|
|
make.centerY.equalTo(self.firstBtn);
|
|
make.height.mas_equalTo(ScaleWidth(24));
|
|
make.width.mas_equalTo(ScaleWidth(66));
|
|
}];
|
|
|
|
|
|
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(287)-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 getNewUserGiftListSuccessBlock:^(NSArray<QXNiceGiftRechargeModel *> * _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)];
|
|
if (weakSelf.md1.status.intValue == 1) {
|
|
weakSelf.firstBtn.enabled = YES;
|
|
weakSelf.firstBtn.selected = YES;
|
|
weakSelf.selectedBtn = weakSelf.firstBtn;
|
|
}else{
|
|
weakSelf.firstBtn.enabled = NO;
|
|
}
|
|
continue;
|
|
}
|
|
if (i == 1) {
|
|
weakSelf.md2 = list[i];
|
|
weakSelf.secondBtn.hidden = NO;
|
|
[weakSelf.secondBtn setTitle:weakSelf.md2.name forState:(UIControlStateNormal)];
|
|
if (weakSelf.md2.status.intValue == 1) {
|
|
weakSelf.secondBtn.enabled = YES;
|
|
if (!weakSelf.selectedBtn.selected) {
|
|
weakSelf.secondBtn.selected = YES;
|
|
weakSelf.selectedBtn = weakSelf.secondBtn;
|
|
}
|
|
}else{
|
|
weakSelf.secondBtn.enabled = NO;
|
|
}
|
|
continue;
|
|
}
|
|
if (i == 2) {
|
|
weakSelf.md3 = list[i];
|
|
weakSelf.thirdBtn.hidden = NO;
|
|
[weakSelf.thirdBtn setTitle:weakSelf.md3.name forState:(UIControlStateNormal)];
|
|
if (weakSelf.md3.status.intValue == 1) {
|
|
weakSelf.thirdBtn.enabled = YES;
|
|
if (!weakSelf.selectedBtn.selected) {
|
|
weakSelf.thirdBtn.selected = YES;
|
|
weakSelf.selectedBtn = weakSelf.thirdBtn;
|
|
}
|
|
}else{
|
|
weakSelf.thirdBtn.enabled = NO;
|
|
}
|
|
continue;
|
|
}
|
|
if (i == 3) {
|
|
weakSelf.md4 = list[i];
|
|
[weakSelf.oneMouthBtn setTitle:weakSelf.md4.name forState:(UIControlStateNormal)];
|
|
weakSelf.oneMouthBtn.hidden = NO;
|
|
continue;
|
|
}
|
|
}
|
|
[weakSelf rechargeSelectedAction:weakSelf.firstBtn];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
showToast(msg);
|
|
if (weakSelf.refreshBlcock) {
|
|
weakSelf.refreshBlcock();
|
|
}
|
|
}];
|
|
}
|
|
-(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;
|
|
QXNiceGiftRechargeModel *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;
|
|
}else if (sender == self.oneMouthBtn){
|
|
self.giftArray = self.md4.gift_list;
|
|
md = self.md4;
|
|
}
|
|
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];
|
|
NSAttributedString *attr = [str deleteLineWithTextColor:RGB16(0x333333) lineColor:RGB16(0x333333) range:[str rangeOfString:giftPrice]];
|
|
NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithAttributedString:attr];
|
|
[att yy_setFont:[UIFont boldSystemFontOfSize:14] range:[str rangeOfString:price]];
|
|
[att yy_setFont:[UIFont systemFontOfSize:12] range:[str rangeOfString:giftPrice]];
|
|
[att yy_setColor:RGB16(0xFFE200) range:[str rangeOfString:price]];
|
|
return att;
|
|
}
|
|
-(void)rechargeAction{
|
|
if (self.rechargeActionBlock) {
|
|
self.rechargeActionBlock(self.smd.money,self.smd.gift_bag_id);
|
|
}
|
|
}
|
|
-(void)closeAction{
|
|
if (self.closeActionBlock) {
|
|
self.closeActionBlock();
|
|
}
|
|
}
|
|
@end
|