445 lines
18 KiB
Objective-C
445 lines
18 KiB
Objective-C
//
|
|
// XPFirstRechargeView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by duoban on 2023/2/27.
|
|
//
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor+FirstRecharge.h"
|
|
#import "UIImage+Utils.h"
|
|
#import "XPFirstRechargeFlowLayout.h"
|
|
///Model
|
|
#import "FirstRechargeModel.h"
|
|
///View
|
|
#import "XPFirstRechargeCollectionViewCell.h"
|
|
#import "XPFirstRechargeCollectionView.h"
|
|
///P
|
|
#import "XPFirstRechargePresenter.h"
|
|
#import "XPFirstRechargeProtocol.h"
|
|
///VC
|
|
#import "XPMineRechargeViewController.h"
|
|
#import "XPWebViewController.h"
|
|
#import "XPFirstRechargeView.h"
|
|
#import "Api+FirstRecharge.h"
|
|
#import "FirstRechargeModel.h"
|
|
#import "XPSkillCardPlayerManager.h"
|
|
@interface XPFirstRechargeView ()<UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
|
|
///
|
|
@property (nonatomic,strong) UIButton *backBtn;
|
|
///背景图
|
|
@property (nonatomic,strong) UIImageView *backImageView;
|
|
///奖励的容器 segment 额外奖励的 礼物的
|
|
@property (nonatomic,strong) UIImageView * rewardBackView;
|
|
///
|
|
@property (nonatomic,strong) UIImageView *typeArrowView;
|
|
///tab 切换
|
|
@property (nonatomic,strong) UIStackView * segmentView;
|
|
///额外的奖励说明
|
|
@property (nonatomic,strong) UIButton *extraButton;
|
|
///列表
|
|
@property (nonatomic,strong) UICollectionView *collectionView;
|
|
///奖励说明
|
|
@property (nonatomic,strong) UIButton *rewardHelpButton;
|
|
///礼包说明背景
|
|
@property (nonatomic, strong) UIImageView *descripBgView;
|
|
///礼包说明
|
|
@property (nonatomic, strong) UITextView *descripTextView;
|
|
///立即充值
|
|
@property (nonatomic, strong) UIButton *rechargeButton;
|
|
///数据源
|
|
@property (nonatomic,strong) NSArray<FirstRechargeRewardModel *> *rewardArray;
|
|
///初始数据源
|
|
@property (nonatomic,strong) NSArray<FirstRechargeModel *> *originArray;
|
|
///当前的导航栏
|
|
@property (nonatomic,weak) UINavigationController * currentNav;
|
|
///
|
|
@property (nonatomic,strong) XPFirstRechargeCollectionView *rechargeView;
|
|
@end
|
|
@implementation XPFirstRechargeView
|
|
|
|
-(instancetype)initWithFrame:(CGRect)frame{
|
|
self = [super initWithFrame:frame];
|
|
if(self){
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
[self getFirstRechargeRewardList];
|
|
|
|
}
|
|
return self;
|
|
}
|
|
|
|
-(void)getFirstRechargeRewardList{
|
|
[XNDJTDDLoadingTool showLoading];
|
|
[Api firstRechargeRewardList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
[XNDJTDDLoadingTool hideHUD];
|
|
if(code == 200){
|
|
NSArray * array = [FirstRechargeModel modelsWithArray:data.data];
|
|
[self getFirstRechargeListSuccess:array];
|
|
return;
|
|
}
|
|
[XNDJTDDLoadingTool showErrorWithMessage:msg];
|
|
} channelType:@"3"];
|
|
}
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
|
|
[self addSubview:self.backBtn];
|
|
[self addSubview:self.backImageView];
|
|
[self.backImageView addSubview:self.rewardHelpButton];
|
|
|
|
[self.backImageView addSubview:self.segmentView];
|
|
[self.backImageView addSubview:self.rewardBackView];
|
|
[self.backImageView addSubview:self.typeArrowView];
|
|
[self.rewardBackView addSubview:self.extraButton];
|
|
[self.backImageView addSubview:self.rechargeButton];
|
|
[self.rewardBackView addSubview:self.collectionView];
|
|
[self.rewardBackView addSubview:self.rechargeView];
|
|
[self addSubview:self.descripBgView];
|
|
[self.descripBgView addSubview:self.descripTextView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self);
|
|
}];
|
|
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.center.mas_equalTo(self);
|
|
make.height.mas_equalTo(kGetScaleWidth(460));
|
|
make.width.mas_equalTo(kGetScaleWidth(306));
|
|
}];
|
|
[self.rewardHelpButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(-kGetScaleWidth(11));
|
|
make.top.mas_equalTo(kGetScaleWidth(121));
|
|
make.width.height.mas_equalTo(kGetScaleWidth(20));
|
|
}];
|
|
[self.segmentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.rewardHelpButton.mas_bottom).mas_offset(kGetScaleWidth(12));
|
|
make.height.mas_equalTo(kGetScaleWidth(30));
|
|
make.right.mas_equalTo(-kGetScaleWidth(15));
|
|
make.left.mas_equalTo(kGetScaleWidth(15));
|
|
}];
|
|
[self.rewardBackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.equalTo(self.segmentView);
|
|
make.top.mas_equalTo(self.segmentView.mas_bottom).offset(kGetScaleWidth(12));
|
|
make.height.mas_equalTo(kGetScaleWidth(230));
|
|
}];
|
|
[self.typeArrowView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(kGetScaleWidth(15));
|
|
make.width.mas_equalTo(kGetScaleWidth(13));
|
|
make.height.mas_equalTo(kGetScaleWidth(7));
|
|
make.bottom.equalTo(self.rewardBackView.mas_top);
|
|
}];
|
|
|
|
[self.extraButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(kGetScaleWidth(276), kGetScaleWidth(20)));
|
|
make.top.mas_equalTo(kGetScaleWidth(11));
|
|
make.centerX.mas_equalTo(self.rewardBackView);
|
|
}];
|
|
[self.rechargeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(kGetScaleWidth(183), kGetScaleWidth(54)));
|
|
make.centerX.mas_equalTo(self.backImageView);
|
|
make.centerY.mas_equalTo(self.backImageView.mas_bottom);
|
|
}];
|
|
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.extraButton.mas_bottom);
|
|
make.left.right.mas_equalTo(self.rewardBackView);
|
|
make.bottom.mas_equalTo(self.rewardBackView);
|
|
}];
|
|
[self.rechargeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(kGetScaleWidth(127));
|
|
make.center.equalTo(self.collectionView);
|
|
make.width.mas_equalTo(kGetScaleWidth(100));
|
|
}];
|
|
[self.descripBgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.rewardHelpButton.mas_bottom).mas_offset(-2);
|
|
make.right.equalTo(self.backImageView.mas_right).mas_offset(4);
|
|
make.width.mas_equalTo(152);
|
|
make.height.mas_equalTo(81);
|
|
}];
|
|
[self.descripTextView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.descripBgView).offset(10);
|
|
make.right.mas_equalTo(self.descripBgView).inset(5);
|
|
make.left.mas_equalTo(self.descripBgView).inset(10);
|
|
make.bottom.mas_equalTo(self.descripBgView).mas_offset(-10);
|
|
}];
|
|
}
|
|
|
|
- (void)createExtraRewardAttrebute:(FirstRechargeModel *)model {
|
|
self.descripTextView.text = model.chargeProdDesc;
|
|
|
|
NSString * title = model.chargeProdTitle;
|
|
NSString * giveMoneyStr = [NSString stringWithFormat:@"%ld", model.giveMoney];
|
|
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName:kFontRegular(12), NSForegroundColorAttributeName:UIColorFromRGB(0xBE5AF6)}];
|
|
[attribute addAttribute:NSFontAttributeName value:kFontSemibold(12) range:[title rangeOfString:giveMoneyStr]];
|
|
[self.extraButton setAttributedTitle:attribute forState:UIControlStateNormal];
|
|
}
|
|
|
|
#pragma mark - XPFirstRechargeProtocol
|
|
- (void)getFirstRechargeListSuccess:(NSArray *)array {
|
|
if (array.count <= 0) return;
|
|
self.typeArrowView.hidden = NO;
|
|
self.originArray = array;
|
|
if (self.segmentView.arrangedSubviews.count > 0) {
|
|
[[self.segmentView arrangedSubviews] enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
[obj removeFromSuperview];
|
|
}];
|
|
}
|
|
for (int i = 0 ; i < array.count; i++) {
|
|
FirstRechargeModel * modelInfo = [array safeObjectAtIndex1:i];
|
|
NSString * title = [NSString stringWithFormat:@"$%.2f ", modelInfo.chargeMoney];
|
|
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
|
|
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
button.titleLabel.font = kFontMedium(15);
|
|
[button setTitle:title forState:UIControlStateNormal];
|
|
[button setTitle:title forState:UIControlStateSelected];
|
|
button.tag = i;
|
|
|
|
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
[button setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal];
|
|
[button setBackgroundImage:[UIImage imageNamed:@"room_first_recharge_segment_select"] forState:UIControlStateSelected];
|
|
[self.segmentView addArrangedSubview:button];
|
|
if (i == 0) {
|
|
button.selected = YES;
|
|
[self createExtraRewardAttrebute:modelInfo];
|
|
self.rewardArray = modelInfo.firstChargeRewardList;
|
|
[self.collectionView reloadData];
|
|
button.layer.cornerRadius = 0;
|
|
button.layer.masksToBounds = YES;
|
|
button.layer.borderWidth = 0;
|
|
}else{
|
|
button.layer.cornerRadius = kGetScaleWidth(8);
|
|
button.layer.masksToBounds = YES;
|
|
button.layer.borderWidth = kGetScaleWidth(1);
|
|
button.layer.borderColor = [UIColor colorWithWhite:1 alpha:0.5].CGColor;
|
|
button.backgroundColor = [UIColor colorWithWhite:1 alpha:0.3];
|
|
}
|
|
}
|
|
[self.segmentView layoutIfNeeded];
|
|
CGFloat x = kGetScaleWidth(15) + self.segmentView.arrangedSubviews.firstObject.frame.origin.x + self.segmentView.arrangedSubviews.firstObject.frame.size.width / 2 - kGetScaleWidth(7)/2;
|
|
[self.typeArrowView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(x);
|
|
}];
|
|
self.collectionView.hidden = self.rewardArray.count < 2;
|
|
self.rechargeView.hidden = self.rewardArray.count != 1;
|
|
if(self.rewardArray.count == 1){
|
|
self.rechargeView.rewardInfo = self.rewardArray.firstObject;
|
|
}
|
|
}
|
|
|
|
#pragma mark - UICollectionViewDelegate And UICollectionViewDatasource
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
return self.rewardArray.count;
|
|
}
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
XPFirstRechargeCollectionViewCell * cell= [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPFirstRechargeCollectionViewCell class]) forIndexPath:indexPath];
|
|
cell.rewardInfo = [self.rewardArray safeObjectAtIndex1:indexPath.row];
|
|
return cell;
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
|
|
|
|
- (void)rewardHelpButtonAction:(UIButton *)sender {
|
|
sender.selected = !sender.selected;
|
|
self.descripBgView.hidden = !sender.selected;
|
|
}
|
|
|
|
- (void)rechargeButtonAction {
|
|
if(self.delegate && [self.delegate respondsToSelector:@selector(rechargeHandle)]){
|
|
[self.delegate rechargeHandle];
|
|
}
|
|
[self backAction];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
-(void)backAction{
|
|
[self removeFromSuperview];
|
|
}
|
|
- (void)buttonAction:(UIButton *)sender {
|
|
if (sender.tag <= self.originArray.count) {
|
|
FirstRechargeModel * model = [self.originArray safeObjectAtIndex1:sender.tag];
|
|
[self createExtraRewardAttrebute:model];
|
|
self.rewardArray = model.firstChargeRewardList;
|
|
self.collectionView.hidden = self.rewardArray.count < 2;
|
|
self.rechargeView.hidden = self.rewardArray.count != 1;
|
|
if(self.rewardArray.count == 1){
|
|
self.rechargeView.rewardInfo = self.rewardArray.firstObject;
|
|
}
|
|
[self.collectionView reloadData];
|
|
}
|
|
CGFloat x = kGetScaleWidth(15) + sender.frame.origin.x + sender.frame.size.width / 2 - kGetScaleWidth(7)/2;
|
|
[self.typeArrowView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(x);
|
|
}];
|
|
[[self.segmentView arrangedSubviews] enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
UIButton * button = obj;
|
|
if (button.tag <= self.originArray.count) {
|
|
FirstRechargeModel * model = [self.originArray safeObjectAtIndex1:sender.tag];
|
|
[self createExtraRewardAttrebute:model];
|
|
}
|
|
button.selected = NO;
|
|
if (sender.tag == button.tag) {
|
|
button.layer.cornerRadius = 0;
|
|
button.layer.borderWidth = 0;
|
|
button.backgroundColor = [UIColor clearColor];
|
|
}else{
|
|
button.layer.cornerRadius = kGetScaleWidth(8);
|
|
button.layer.masksToBounds = YES;
|
|
button.layer.borderWidth = kGetScaleWidth(1);
|
|
button.layer.borderColor = [UIColor colorWithWhite:1 alpha:0.5].CGColor;
|
|
button.backgroundColor = [UIColor colorWithWhite:1 alpha:0.3];
|
|
}
|
|
}];
|
|
sender.selected = !sender.selected;
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (UICollectionView *)collectionView{
|
|
if (!_collectionView) {
|
|
XPFirstRechargeFlowLayout *layout = [[XPFirstRechargeFlowLayout alloc] init];
|
|
layout.itemSize = CGSizeMake(kGetScaleWidth(65), kGetScaleWidth(96));
|
|
layout.minimumLineSpacing = kGetScaleWidth(9);
|
|
layout.sectionInset = UIEdgeInsetsMake(kGetScaleWidth(11), kGetScaleWidth(18), kGetScaleWidth(12), kGetScaleWidth(17));
|
|
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
_collectionView.dataSource = self;
|
|
_collectionView.delegate = self;
|
|
_collectionView.backgroundColor = [UIColor clearColor];
|
|
[_collectionView registerClass:[XPFirstRechargeCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPFirstRechargeCollectionViewCell class])];
|
|
}
|
|
return _collectionView;
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UIImageView *)backImageView {
|
|
if (!_backImageView) {
|
|
_backImageView = [[UIImageView alloc] init];
|
|
_backImageView.userInteractionEnabled = YES;
|
|
_backImageView.image = [UIImage imageNamed:@"room_first_recharge_bg"];
|
|
}
|
|
return _backImageView;
|
|
}
|
|
|
|
- (UIImageView *)rewardBackView {
|
|
if (!_rewardBackView) {
|
|
_rewardBackView = [[UIImageView alloc] init];
|
|
_rewardBackView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
|
|
_rewardBackView.layer.cornerRadius = kGetScaleWidth(16);
|
|
_rewardBackView.layer.masksToBounds = YES;
|
|
_rewardBackView.layer.shadowColor = [UIColor colorWithRed:240/255.0 green:162/255.0 blue:244/255.0 alpha:1.0].CGColor;
|
|
_rewardBackView.layer.shadowOffset = CGSizeMake(0,kGetScaleWidth(2));
|
|
_rewardBackView.layer.shadowOpacity = kGetScaleWidth(1);
|
|
_rewardBackView.layer.shadowRadius = kGetScaleWidth(4);
|
|
_rewardBackView.userInteractionEnabled = YES;
|
|
|
|
_rewardBackView.backgroundColor = [UIColor whiteColor];
|
|
}
|
|
return _rewardBackView;
|
|
}
|
|
|
|
- (UIButton *)extraButton {
|
|
if (!_extraButton) {
|
|
_extraButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_extraButton setBackgroundImage:kImage(@"room_first_recharge_extra") forState:UIControlStateNormal];
|
|
|
|
}
|
|
return _extraButton;
|
|
}
|
|
|
|
- (UIStackView *)segmentView {
|
|
if (!_segmentView) {
|
|
_segmentView = [[UIStackView alloc] init];
|
|
_segmentView.axis = UILayoutConstraintAxisHorizontal;
|
|
_segmentView.distribution = UIStackViewDistributionFillEqually;
|
|
_segmentView.alignment = UIStackViewAlignmentFill;
|
|
_segmentView.spacing = kGetScaleWidth(12);
|
|
}
|
|
return _segmentView;
|
|
}
|
|
|
|
- (UIImageView *)descripBgView {
|
|
if (!_descripBgView) {
|
|
_descripBgView = [[UIImageView alloc] init];
|
|
_descripBgView.image = [[UIImage imageNamed:@"room_first_recharge_descrip_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(35, 120, 35, 20) resizingMode:UIImageResizingModeStretch];
|
|
_descripBgView.contentMode = UIViewContentModeScaleToFill;
|
|
_descripBgView.hidden = YES;
|
|
}
|
|
return _descripBgView;
|
|
}
|
|
|
|
- (UITextView *)descripTextView {
|
|
if (!_descripTextView) {
|
|
_descripTextView = [[UITextView alloc] init];
|
|
_descripTextView.text = YMLocalizedString(@"XPFirstRechargeViewController0");
|
|
_descripTextView.textColor = UIColorFromRGB(0x333333);
|
|
_descripTextView.backgroundColor = [UIColor clearColor];
|
|
_descripTextView.font = [UIFont systemFontOfSize:11];
|
|
_descripTextView.editable = NO;
|
|
}
|
|
return _descripTextView;
|
|
}
|
|
|
|
- (UIButton *)rewardHelpButton {
|
|
if (!_rewardHelpButton) {
|
|
_rewardHelpButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_rewardHelpButton setImage:[UIImage imageNamed:@"room_first_recharge_help"] forState:UIControlStateNormal];
|
|
[_rewardHelpButton setImage:[UIImage imageNamed:@"room_first_recharge_help"] forState:UIControlStateSelected];
|
|
[_rewardHelpButton addTarget:self action:@selector(rewardHelpButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _rewardHelpButton;
|
|
}
|
|
|
|
- (UIButton *)rechargeButton {
|
|
if (!_rechargeButton) {
|
|
_rechargeButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_rechargeButton setBackgroundImage:[UIImage imageNamed:@"room_first_recharge_recharge"] forState:UIControlStateNormal];
|
|
[_rechargeButton setBackgroundImage:[UIImage imageNamed:@"room_first_recharge_recharge"] forState:UIControlStateSelected];
|
|
[_rechargeButton setTitle:YMLocalizedString(@"XPFirstRechargeViewController1") forState:UIControlStateNormal];
|
|
_rechargeButton.titleLabel.font = kFontSemibold(18);
|
|
[_rechargeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
[_rechargeButton addTarget:self action:@selector(rechargeButtonAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _rechargeButton;
|
|
}
|
|
- (UIImageView *)typeArrowView{
|
|
if (!_typeArrowView){
|
|
_typeArrowView = [UIImageView new];
|
|
_typeArrowView.image = kImage(@"room_first_recharge_recharge_arrow");
|
|
_typeArrowView.hidden = YES;
|
|
}
|
|
return _typeArrowView;
|
|
}
|
|
- (XPFirstRechargeCollectionView *)rechargeView{
|
|
if (!_rechargeView){
|
|
_rechargeView = [[XPFirstRechargeCollectionView alloc]initWithFrame:CGRectZero isFirst:YES];
|
|
_rechargeView.hidden = YES;
|
|
}
|
|
return _rechargeView;
|
|
}
|
|
- (UIButton *)backBtn{
|
|
if (!_backBtn){
|
|
_backBtn = [UIButton new];
|
|
[_backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
}
|
|
return _backBtn;
|
|
}
|
|
|
|
@end
|