2022-07-28 11:56:59 +08:00
|
|
|
//
|
|
|
|
// XPNewUserRechargeViewController.m
|
|
|
|
// xplan-ios
|
|
|
|
//
|
|
|
|
// Created by GreenLand on 2022/7/27.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "XPNewUserRechargeViewController.h"
|
|
|
|
///Third
|
|
|
|
#import <Masonry/Masonry.h>
|
|
|
|
///Tool
|
|
|
|
#import "XPMacro.h"
|
|
|
|
#import "ThemeColor+FirstRecharge.h"
|
|
|
|
#import "UIImage+Utils.h"
|
|
|
|
#import "XPFirstRechargeFlowLayout.h"
|
2022-07-29 18:56:08 +08:00
|
|
|
#import "Timestamp.h"
|
2022-07-28 11:56:59 +08:00
|
|
|
///Model
|
2022-07-29 18:56:08 +08:00
|
|
|
#import "NewUserRechargeModel.h"
|
2022-07-28 11:56:59 +08:00
|
|
|
///View
|
2022-07-29 18:56:08 +08:00
|
|
|
#import "XPNewUserRechargeCollectionViewCell.h"
|
2022-07-28 11:56:59 +08:00
|
|
|
///P
|
|
|
|
#import "MainPresenter.h"
|
|
|
|
#import "MainProtocol.h"
|
|
|
|
///VC
|
|
|
|
#import "XPMineRechargeViewController.h"
|
|
|
|
|
|
|
|
@interface XPNewUserRechargeViewController ()<MainProtocol, UICollectionViewDelegate, UICollectionViewDataSource>
|
|
|
|
///顶部的View
|
|
|
|
@property (nonatomic,strong) UIView * topView;
|
|
|
|
///底部的View
|
|
|
|
@property (nonatomic,strong) UIView * bottomView;
|
|
|
|
///背景图
|
|
|
|
@property (nonatomic,strong) UIImageView *backImageView;
|
|
|
|
///关闭按钮
|
|
|
|
@property (nonatomic, strong) UIButton *closeBtn;
|
|
|
|
///优惠倒计时
|
|
|
|
@property (nonatomic, strong) UILabel *countDownLabel;
|
|
|
|
///奖励的容器 segment 额外奖励的 礼物的
|
|
|
|
@property (nonatomic,strong) UIImageView * rewardBackView;
|
|
|
|
///tab 切换
|
|
|
|
@property (nonatomic,strong) UIStackView * segmentView;
|
|
|
|
///额外的奖励说明
|
|
|
|
@property (nonatomic,strong) UIButton *extraButton;
|
|
|
|
///列表
|
|
|
|
@property (nonatomic,strong) UICollectionView *collectionView;
|
|
|
|
///立即充值
|
|
|
|
@property (nonatomic, strong) UIButton *rechargeButton;
|
2022-07-29 18:56:08 +08:00
|
|
|
///总数据
|
|
|
|
@property (nonatomic, strong) NewUserRechargeModel *rechargeInfo;
|
2022-07-28 11:56:59 +08:00
|
|
|
///数据源
|
|
|
|
@property (nonatomic,strong) NSArray<FirstRechargeRewardModel *> *rewardArray;
|
|
|
|
///初始数据源
|
|
|
|
@property (nonatomic,strong) NSArray<FirstRechargeModel *> *originArray;
|
|
|
|
///当前的导航栏
|
|
|
|
@property (nonatomic,weak) UINavigationController * currentNav;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation XPNewUserRechargeViewController
|
|
|
|
|
|
|
|
- (instancetype)initWithNavigation:(UINavigationController *)nav {
|
|
|
|
if (self = [super init]) {
|
|
|
|
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
|
|
self.currentNav = nav;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (MainPresenter *)createPresenter {
|
|
|
|
return [[MainPresenter alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
[self.presenter getNewUserRechargeList];
|
|
|
|
[self initSubViews];
|
|
|
|
[self initSubViewConstraints];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Private Method
|
|
|
|
- (void)initSubViews {
|
|
|
|
self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
|
|
|
|
[self.view addSubview:self.topView];
|
|
|
|
[self.view addSubview:self.backImageView];
|
|
|
|
[self.view addSubview:self.bottomView];
|
|
|
|
[self.view addSubview:self.closeBtn];
|
|
|
|
[self.view addSubview:self.countDownLabel];
|
|
|
|
|
|
|
|
[self.backImageView addSubview:self.rechargeButton];
|
|
|
|
[self.backImageView addSubview:self.rewardBackView];
|
|
|
|
|
|
|
|
[self.rewardBackView addSubview:self.segmentView];
|
|
|
|
[self.rewardBackView addSubview:self.extraButton];
|
|
|
|
[self.rewardBackView addSubview:self.collectionView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initSubViewConstraints {
|
|
|
|
[self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.right.top.mas_equalTo(self.view);
|
|
|
|
make.bottom.mas_equalTo(self.backImageView.mas_top);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.center.mas_equalTo(self.view);
|
|
|
|
make.height.mas_equalTo(405);
|
|
|
|
make.width.mas_equalTo(315);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.right.bottom.mas_equalTo(self.view);
|
|
|
|
make.top.mas_equalTo(self.backImageView.mas_bottom);
|
|
|
|
}];
|
|
|
|
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.mas_equalTo(self.backImageView.mas_top);
|
|
|
|
make.width.height.mas_equalTo(21);
|
|
|
|
make.right.mas_equalTo(self.backImageView).mas_offset(8);
|
|
|
|
}];
|
|
|
|
[self.countDownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.top.mas_equalTo(self.backImageView).mas_offset(87);
|
|
|
|
make.left.mas_equalTo(self.backImageView).mas_offset(47);
|
|
|
|
make.height.mas_equalTo(14);
|
|
|
|
}];
|
|
|
|
[self.rechargeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.size.mas_equalTo(CGSizeMake(244, 44));
|
|
|
|
make.centerX.mas_equalTo(self.backImageView);
|
|
|
|
make.bottom.mas_equalTo(self.backImageView.mas_bottom).offset(-28);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.rewardBackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.top.mas_equalTo(self.backImageView).offset(128);
|
|
|
|
make.height.mas_equalTo(205);
|
|
|
|
make.width.mas_equalTo(266);
|
|
|
|
make.centerX.mas_equalTo(self.backImageView);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.segmentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.width.mas_equalTo(266);
|
|
|
|
make.centerX.top.mas_equalTo(self.rewardBackView);
|
|
|
|
make.height.mas_equalTo(50);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.extraButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
2022-07-29 18:56:08 +08:00
|
|
|
make.size.mas_equalTo(CGSizeMake(266, 17));
|
2022-07-28 11:56:59 +08:00
|
|
|
make.top.mas_equalTo(self.segmentView.mas_bottom).offset(12);
|
|
|
|
make.centerX.mas_equalTo(self.rewardBackView);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.top.mas_equalTo(self.extraButton.mas_bottom).offset(12);
|
2022-07-29 18:56:08 +08:00
|
|
|
make.left.mas_equalTo(self.rewardBackView);
|
|
|
|
make.centerX.mas_equalTo(self.rewardBackView);
|
|
|
|
make.height.mas_equalTo(94);
|
2022-07-28 11:56:59 +08:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2022-07-29 18:56:08 +08:00
|
|
|
#pragma mark - MainProtocol
|
|
|
|
///获取新用户充值列表成功
|
|
|
|
- (void)getNewUserRechargeInfoSuccess:(NewUserRechargeModel *)rechargeInfo {
|
|
|
|
_rechargeInfo = rechargeInfo;
|
|
|
|
[Timestamp getInternetDateWithSuccess:^(NSTimeInterval timeInterval) {
|
|
|
|
timeInterval = timeInterval * 1000;
|
|
|
|
long aTime = (rechargeInfo.limitEndTime - timeInterval) / 1000;
|
|
|
|
self.countDownLabel.text = [NSString stringWithFormat:@"限时%@", [self countTimeWithTime:aTime]];
|
|
|
|
} failure:^(NSError * _Nonnull error) {
|
|
|
|
NSDate *datenow = [NSDate date];//现在时间
|
|
|
|
long time2 = (long)([datenow timeIntervalSince1970]*1000);
|
|
|
|
long aTime = (rechargeInfo.limitEndTime - time2) / 1000;
|
|
|
|
self.countDownLabel.text = [NSString stringWithFormat:@"限时%@", [self countTimeWithTime:aTime]];
|
|
|
|
}];
|
|
|
|
|
|
|
|
self.originArray = rechargeInfo.limitFirstChargeTaskList;
|
2022-07-28 11:56:59 +08:00
|
|
|
if (self.segmentView.arrangedSubviews.count > 0) {
|
|
|
|
[[self.segmentView arrangedSubviews] enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
|
[obj removeFromSuperview];
|
|
|
|
}];
|
|
|
|
}
|
2022-07-29 18:56:08 +08:00
|
|
|
NSInteger defaultIndex = -1;
|
|
|
|
for (int i = 0 ; i < self.originArray.count; i++) {
|
|
|
|
FirstRechargeModel * modelInfo = [self.originArray objectAtIndex:i];
|
2022-07-28 11:56:59 +08:00
|
|
|
NSString * title = [NSString stringWithFormat:@"%ld元", modelInfo.chargeMoney];
|
|
|
|
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
|
2022-07-29 18:56:08 +08:00
|
|
|
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
|
|
|
|
[button setTitleColor:[ThemeColor textThirdColor] forState:UIControlStateNormal];
|
|
|
|
button.titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
|
2022-07-28 11:56:59 +08:00
|
|
|
[button setTitle:title forState:UIControlStateNormal];
|
|
|
|
[button setTitle:title forState:UIControlStateSelected];
|
|
|
|
button.adjustsImageWhenHighlighted = NO;
|
|
|
|
button.tag = i;
|
|
|
|
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
[button setBackgroundImage:[UIImage imageNamed:@"NewUserRecharge_segment_normal_bg"] forState:UIControlStateNormal];
|
|
|
|
[button setBackgroundImage:[[UIImage imageNamed:@"NewUserRecharge_segment_selected_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 30) resizingMode:UIImageResizingModeStretch] forState:UIControlStateSelected];
|
2022-07-29 18:56:08 +08:00
|
|
|
if (modelInfo.finishCharge) {
|
|
|
|
button.userInteractionEnabled = NO;
|
|
|
|
}
|
|
|
|
if (!modelInfo.finishCharge && defaultIndex < 0) {
|
2022-07-28 11:56:59 +08:00
|
|
|
button.selected = YES;
|
2022-07-29 18:56:08 +08:00
|
|
|
defaultIndex = i;
|
|
|
|
[self.extraButton setTitle:modelInfo.chargeProdTitle forState:UIControlStateNormal];
|
2022-07-28 11:56:59 +08:00
|
|
|
self.rewardArray = modelInfo.firstChargeRewardList;
|
2022-07-29 18:56:08 +08:00
|
|
|
if (self.rewardArray.count < 4) {
|
|
|
|
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.width.mas_equalTo(64*self.rewardArray.count);
|
|
|
|
}];
|
|
|
|
}
|
2022-07-28 11:56:59 +08:00
|
|
|
[self.collectionView reloadData];
|
|
|
|
}
|
|
|
|
[self.segmentView addArrangedSubview:button];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 18:56:08 +08:00
|
|
|
- (NSString *)countTimeWithTime:(long)time {
|
|
|
|
NSInteger minute;
|
|
|
|
NSInteger hour;
|
|
|
|
NSInteger day = time / 24 / 3600;
|
|
|
|
time = time - day * 24 * 3600;
|
|
|
|
hour = time / 3600;
|
|
|
|
time = time - hour * 3600;
|
|
|
|
minute = time / 60;
|
|
|
|
if (day > 0) {
|
|
|
|
if (hour > 0) {
|
|
|
|
return [NSString stringWithFormat:@"%zd天%zd小时%zd分", day, hour, minute];
|
|
|
|
} else {
|
|
|
|
return [NSString stringWithFormat:@"%zd天%zd分", day, minute];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (hour > 0) {
|
|
|
|
return [NSString stringWithFormat:@"%zd小时%zd分", hour, minute];
|
|
|
|
} else {
|
|
|
|
return [NSString stringWithFormat:@"%zd分", minute];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 11:56:59 +08:00
|
|
|
#pragma mark - UICollectionViewDelegate And UICollectionViewDatasource
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
|
|
return self.rewardArray.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
2022-07-29 18:56:08 +08:00
|
|
|
XPNewUserRechargeCollectionViewCell * cell= [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPNewUserRechargeCollectionViewCell class]) forIndexPath:indexPath];
|
2022-07-28 11:56:59 +08:00
|
|
|
cell.rewardInfo = [self.rewardArray objectAtIndex:indexPath.row];
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Event Response
|
|
|
|
- (void)dismissFirstRechargeVC {
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rechargeButtonAction:(UIButton *)sender {
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
XPMineRechargeViewController * rechargeVC = [[XPMineRechargeViewController alloc] init];
|
|
|
|
[self.currentNav pushViewController:rechargeVC animated:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)buttonAction:(UIButton *)sender {
|
|
|
|
if (sender.tag <= self.originArray.count) {
|
|
|
|
FirstRechargeModel * model = [self.originArray objectAtIndex:sender.tag];
|
2022-07-29 18:56:08 +08:00
|
|
|
[self.extraButton setTitle:model.chargeProdTitle forState:UIControlStateNormal];
|
2022-07-28 11:56:59 +08:00
|
|
|
self.rewardArray = model.firstChargeRewardList;
|
2022-07-29 18:56:08 +08:00
|
|
|
if (self.rewardArray.count < 4) {
|
|
|
|
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.width.mas_equalTo(64*self.rewardArray.count);
|
|
|
|
}];
|
|
|
|
} else {
|
|
|
|
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(self.rewardBackView);
|
|
|
|
}];
|
|
|
|
}
|
2022-07-28 11:56:59 +08:00
|
|
|
[self.collectionView reloadData];
|
|
|
|
}
|
|
|
|
|
|
|
|
[[self.segmentView arrangedSubviews] enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
|
UIButton * button = obj;
|
|
|
|
button.selected = NO;
|
|
|
|
}];
|
|
|
|
sender.selected = !sender.selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Getters And Setters
|
|
|
|
- (UICollectionView *)collectionView{
|
|
|
|
if (!_collectionView) {
|
2022-07-29 18:56:08 +08:00
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
|
|
layout.itemSize = CGSizeMake(64, 94);
|
|
|
|
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
2022-07-28 11:56:59 +08:00
|
|
|
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
2022-07-29 18:56:08 +08:00
|
|
|
_collectionView.showsHorizontalScrollIndicator = NO;
|
2022-07-28 11:56:59 +08:00
|
|
|
_collectionView.dataSource = self;
|
|
|
|
_collectionView.delegate = self;
|
2022-07-29 18:56:08 +08:00
|
|
|
[_collectionView registerClass:[XPNewUserRechargeCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPNewUserRechargeCollectionViewCell class])];
|
2022-07-28 11:56:59 +08:00
|
|
|
}
|
|
|
|
return _collectionView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIView *)bottomView {
|
|
|
|
if (!_bottomView) {
|
|
|
|
_bottomView = [[UIView alloc] init];
|
|
|
|
_bottomView.backgroundColor = [UIColor clearColor];
|
|
|
|
UITapGestureRecognizer * tap= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissFirstRechargeVC)];
|
|
|
|
[_bottomView addGestureRecognizer:tap];
|
|
|
|
}
|
|
|
|
return _bottomView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIView *)topView {
|
|
|
|
if (!_topView) {
|
|
|
|
_topView = [[UIView alloc] init];
|
|
|
|
_topView.backgroundColor = [UIColor clearColor];
|
|
|
|
UITapGestureRecognizer * tap= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissFirstRechargeVC)];
|
|
|
|
[_topView addGestureRecognizer:tap];
|
|
|
|
}
|
|
|
|
return _topView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIImageView *)backImageView {
|
|
|
|
if (!_backImageView) {
|
|
|
|
_backImageView = [[UIImageView alloc] init];
|
|
|
|
_backImageView.userInteractionEnabled = YES;
|
|
|
|
_backImageView.image = [UIImage imageNamed:@"NewUserRecharge_bg"];
|
|
|
|
}
|
|
|
|
return _backImageView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIButton *)closeBtn {
|
|
|
|
if (!_closeBtn) {
|
|
|
|
_closeBtn = [[UIButton alloc] init];
|
|
|
|
[_closeBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
|
|
|
|
}
|
|
|
|
return _closeBtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UILabel *)countDownLabel {
|
|
|
|
if (!_countDownLabel) {
|
|
|
|
_countDownLabel = [[UILabel alloc] init];
|
|
|
|
_countDownLabel.textColor = [UIColor whiteColor];
|
|
|
|
_countDownLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightMedium];
|
|
|
|
}
|
|
|
|
return _countDownLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIImageView *)rewardBackView {
|
|
|
|
if (!_rewardBackView) {
|
|
|
|
_rewardBackView = [[UIImageView alloc] init];
|
|
|
|
_rewardBackView.userInteractionEnabled = YES;
|
|
|
|
}
|
|
|
|
return _rewardBackView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIButton *)extraButton {
|
|
|
|
if (!_extraButton) {
|
|
|
|
_extraButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
2022-07-29 18:56:08 +08:00
|
|
|
[_extraButton setTitleColor:UIColorFromRGB(0xFF3987) forState:UIControlStateNormal];
|
|
|
|
_extraButton.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightBold];
|
2022-07-28 11:56:59 +08:00
|
|
|
}
|
|
|
|
return _extraButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIButton *)rechargeButton {
|
|
|
|
if (!_rechargeButton) {
|
|
|
|
_rechargeButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
[_rechargeButton setImage:[UIImage imageNamed:@"NewUserRecharge_goto"] forState:UIControlStateNormal];
|
|
|
|
}
|
|
|
|
return _rechargeButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIStackView *)segmentView {
|
|
|
|
if (!_segmentView) {
|
|
|
|
_segmentView = [[UIStackView alloc] init];
|
|
|
|
_segmentView.axis = UILayoutConstraintAxisHorizontal;
|
|
|
|
_segmentView.distribution = UIStackViewDistributionFillEqually;
|
|
|
|
_segmentView.alignment = UIStackViewAlignmentFill;
|
|
|
|
_segmentView.spacing = 4;
|
|
|
|
}
|
|
|
|
return _segmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|