316 lines
12 KiB
Objective-C
316 lines
12 KiB
Objective-C
//
|
|
// MewRechargeSubView.m
|
|
// mew-ios
|
|
//
|
|
// Created by 触海 on 2023/11/17.
|
|
//
|
|
|
|
#import "MewRechargeSubView.h"
|
|
/// Model
|
|
|
|
/// Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <YYText/YYText.h>
|
|
/// Tool
|
|
|
|
#import "MewMacro.h"
|
|
#import "UIImage+MewUtils.h"
|
|
#import "MewHUDTool.h"
|
|
|
|
@interface MewRechargeSubView()
|
|
//余额
|
|
@property (nonatomic, strong) UIImageView *balanceBgImageView;
|
|
@property (nonatomic, strong) UIStackView *balanceStackView;
|
|
@property (nonatomic, strong) UIImageView *balanceImageView;
|
|
@property (nonatomic, strong) UILabel *balanceTitleLabel;
|
|
@property (nonatomic, strong) UILabel *balanceMoneyLabel;
|
|
|
|
//充值
|
|
@property (nonatomic, strong) NSMutableArray<UIView *> *rechargeBgViewArrays;
|
|
@property (nonatomic, strong) UIView *rechargeView;
|
|
//充值协议
|
|
@property (nonatomic,strong) YYLabel *rechargePrivacyLabel;
|
|
//@property (nonatomic, strong) UIStackView *rechargeStackView;
|
|
@property (nonatomic, strong) UIButton *rechargeButton;
|
|
@property (nonatomic, strong) MewPayItemModel *selectModel;
|
|
@property (nonatomic, assign) NSInteger index;
|
|
|
|
@end
|
|
|
|
@implementation MewRechargeSubView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self mew_initView];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Action Event
|
|
- (void)mew_rechargeButtonAction {
|
|
//立即充值
|
|
if (self.selectModel == nil) {
|
|
[MewHUDTool showErrorWithMessage:@"请选择充值的钻石"];
|
|
return;
|
|
}
|
|
|
|
|
|
if (self.delegate) {
|
|
[self.delegate mew_didSelectMewRechargeChargeProdId:self.index];
|
|
}
|
|
}
|
|
|
|
- (void)mew_didmew_rechargeButtonAction:(UITapGestureRecognizer *)tap {
|
|
for (UIView *rechargeView in self.rechargeBgViewArrays) {
|
|
rechargeView.layer.borderColor = UIColor.clearColor.CGColor;
|
|
rechargeView.layer.borderWidth = 0.0;
|
|
}
|
|
|
|
UIView *currentRechargeView = tap.view;
|
|
currentRechargeView.layer.borderColor = [MewAppColor mewGetColorOfTextWithHexString:0x9552FF].CGColor;
|
|
currentRechargeView.layer.borderWidth = 1.0;
|
|
|
|
NSInteger selectIndex = tap.view.tag - 100;
|
|
self.index = selectIndex;
|
|
self.selectModel = self.rechargeModels[selectIndex];
|
|
|
|
|
|
}
|
|
|
|
#pragma mark - Set
|
|
- (void)setWalletModel:(MewDiamondNum *)walletModel {
|
|
_walletModel = walletModel;
|
|
self.balanceMoneyLabel.text = _walletModel.diamonds;
|
|
}
|
|
|
|
- (void)setRechargeModels:(NSArray<MewPayItemModel *> *)rechargeModels {
|
|
_rechargeModels = rechargeModels;
|
|
[self mew_initRechargeViewWithModels:_rechargeModels];
|
|
}
|
|
|
|
#pragma mark - Init
|
|
- (void)mew_initView {
|
|
[self addSubview:self.balanceBgImageView];
|
|
[self addSubview:self.balanceStackView];
|
|
[self.balanceStackView addArrangedSubview:self.balanceImageView];
|
|
[self.balanceStackView addArrangedSubview:self.balanceTitleLabel];
|
|
[self addSubview:self.balanceMoneyLabel];
|
|
[self addSubview:self.rechargeView];
|
|
[self addSubview:self.rechargePrivacyLabel];
|
|
[self addSubview:self.rechargeButton];
|
|
[self mew_initLayout];
|
|
}
|
|
|
|
- (void)mew_initRechargeViewWithModels:(NSArray<MewPayItemModel *> *)rechargeModel {
|
|
CGFloat viewWidth = 144.0;
|
|
CGFloat viewHeight = 83;
|
|
CGFloat marginX = 23.0;
|
|
CGFloat marginLeft = (KMewGetScreenWidth - 2*viewWidth - marginX)/2.0;
|
|
CGFloat marginTop = 20.0;
|
|
for (int i = 0; i < rechargeModel.count; i++) {
|
|
MewPayItemModel *model = rechargeModel[i];
|
|
|
|
UIView *rechargeBgView = [[UIView alloc] init];
|
|
rechargeBgView.frame = CGRectMake((i%2 * (viewWidth + marginX)) + marginLeft, i/2 * (viewHeight + marginTop), viewWidth, viewHeight);
|
|
rechargeBgView.backgroundColor = [MewAppColor mewGetAlphaColorOfTextWithHexString:0x525566 alpha:0.8];
|
|
rechargeBgView.layer.cornerRadius = 8.0;
|
|
rechargeBgView.layer.masksToBounds = YES;
|
|
rechargeBgView.tag = i + 100;
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mew_didmew_rechargeButtonAction:)];
|
|
[rechargeBgView addGestureRecognizer:tap];
|
|
[self.rechargeBgViewArrays addObject:rechargeBgView];
|
|
[self.rechargeView addSubview:rechargeBgView];
|
|
|
|
UIView *rechargeStackView = [[UIView alloc] initWithFrame:CGRectMake(5, 14, viewWidth, 25)];
|
|
[rechargeBgView addSubview:rechargeStackView];
|
|
|
|
UIImageView *rechargeImageView = [[UIImageView alloc] init];
|
|
// rechargeImageView.frame.size = CGSizeMake(20, 20);
|
|
rechargeImageView.image = [UIImage imageNamed:@"mew_recharge_diamond_small"];
|
|
[rechargeStackView addSubview:rechargeImageView];
|
|
UILabel *rechargeDiamondLabel = [[UILabel alloc] init];
|
|
rechargeDiamondLabel.text = [NSString stringWithFormat:@"%@",model.prodName];
|
|
// [rechargeDiamondLabel sizeToFit];
|
|
rechargeDiamondLabel.textColor = UIColor.whiteColor;
|
|
rechargeDiamondLabel.font = kMewSetFontMedium(16);
|
|
[rechargeStackView addSubview:rechargeDiamondLabel];
|
|
[rechargeDiamondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.top.height.equalTo(rechargeStackView);
|
|
}];
|
|
[rechargeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.height.mas_equalTo(20);
|
|
make.centerY.equalTo(rechargeDiamondLabel);
|
|
make.right.equalTo(rechargeDiamondLabel.mas_left).offset(-5);
|
|
}];
|
|
|
|
UILabel *rechargeMoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(rechargeStackView.frame) + 13.0, viewWidth, 20)];
|
|
rechargeMoneyLabel.text = [NSString stringWithFormat:@"%@元",model.money];
|
|
rechargeMoneyLabel.textColor = [MewAppColor mewGetAlphaColorOfTextWithHexString:0xffffff alpha:0.8];
|
|
rechargeMoneyLabel.font = kMewSetFontRegular(14);
|
|
rechargeMoneyLabel.textAlignment = NSTextAlignmentCenter;
|
|
[rechargeBgView addSubview:rechargeMoneyLabel];
|
|
}
|
|
|
|
double count = ceil(self.rechargeModels.count/2);
|
|
[self.rechargeView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(400);
|
|
}];
|
|
|
|
}
|
|
|
|
- (void)mew_initLayout {
|
|
[self.balanceBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(KMewGetScreenWidth - 2*19);
|
|
make.height.mas_equalTo(124*kMewSetScreenScale);
|
|
make.top.mas_equalTo(self);
|
|
make.left.mas_equalTo(19);
|
|
}];
|
|
[self.balanceStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.balanceBgImageView).offset(27);
|
|
// make.width.mas_equalTo(self);
|
|
make.centerX.mas_equalTo(self);
|
|
make.height.mas_equalTo(25);
|
|
}];
|
|
[self.balanceMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(self.balanceStackView.mas_bottom);
|
|
make.centerX.equalTo(self.balanceBgImageView);
|
|
make.height.mas_equalTo(48);
|
|
}];
|
|
|
|
[self.rechargeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.equalTo(self);
|
|
make.top.equalTo(self.balanceBgImageView.mas_bottom).offset(19);
|
|
}];
|
|
|
|
|
|
[self.rechargeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.mas_equalTo(-60);
|
|
make.width.mas_equalTo(KMewGetScreenWidth - 2*40);
|
|
make.height.mas_equalTo(48);
|
|
make.centerX.equalTo(self);
|
|
}];
|
|
|
|
|
|
[self.rechargePrivacyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.bottom.equalTo(self.rechargeButton.mas_top).offset(-10);
|
|
make.centerX.equalTo(self);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Get
|
|
- (UIImageView *)balanceBgImageView {
|
|
if (!_balanceBgImageView) {
|
|
_balanceBgImageView = [[UIImageView alloc] init];
|
|
_balanceBgImageView.image = [UIImage imageNamed:@"mew_recharge_balance_bg"];
|
|
}
|
|
return _balanceBgImageView;
|
|
}
|
|
|
|
- (UIStackView *)balanceStackView {
|
|
if (!_balanceStackView) {
|
|
_balanceStackView = [[UIStackView alloc] init];
|
|
_balanceStackView.axis = UILayoutConstraintAxisHorizontal;
|
|
_balanceStackView.distribution = UIStackViewDistributionFill;
|
|
_balanceStackView.alignment = UIStackViewAlignmentFill;
|
|
_balanceStackView.spacing = 6;
|
|
}
|
|
return _balanceStackView;
|
|
}
|
|
|
|
- (UIImageView *)balanceImageView {
|
|
if (!_balanceImageView) {
|
|
_balanceImageView = [[UIImageView alloc] init];
|
|
_balanceImageView.image = [UIImage imageNamed:@"mew_recharge_diamond_big"];
|
|
}
|
|
return _balanceImageView;
|
|
}
|
|
|
|
- (UILabel *)balanceTitleLabel {
|
|
if (!_balanceTitleLabel) {
|
|
_balanceTitleLabel = [[UILabel alloc] init];
|
|
_balanceTitleLabel.text = @"余额";
|
|
_balanceTitleLabel.textColor = UIColor.whiteColor;
|
|
_balanceTitleLabel.font = kMewSetFontRegular(18);
|
|
}
|
|
return _balanceTitleLabel;
|
|
}
|
|
|
|
- (UILabel *)balanceMoneyLabel {
|
|
if (!_balanceMoneyLabel) {
|
|
_balanceMoneyLabel = [[UILabel alloc] init];
|
|
// _balanceMoneyLabel.text = @"1000004";
|
|
_balanceMoneyLabel.textColor = UIColor.whiteColor;
|
|
_balanceMoneyLabel.font = kMewSetFontSemibold(34);
|
|
}
|
|
return _balanceMoneyLabel;
|
|
}
|
|
|
|
- (UIView *)rechargeView {
|
|
if (!_rechargeView) {
|
|
_rechargeView = [[UIView alloc] init];
|
|
}
|
|
return _rechargeView;
|
|
}
|
|
|
|
- (YYLabel *)rechargePrivacyLabel {
|
|
if (!_rechargePrivacyLabel) {
|
|
_rechargePrivacyLabel = [[YYLabel alloc] init];
|
|
_rechargePrivacyLabel.numberOfLines = 0;
|
|
|
|
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"已阅读并同意"];
|
|
attString.yy_color = [MewAppColor mewSecondTextColor];
|
|
attString.yy_font = [UIFont systemFontOfSize:13];
|
|
|
|
NSMutableAttributedString *rechargeAttString = [[NSMutableAttributedString alloc] initWithString:@"《用户充值协议》\n" attributes:@{NSForegroundColorAttributeName:[MewAppColor mewGetColorOfTextWithHexString:0x5DA4F5]}];
|
|
@kWeakify(self);
|
|
[rechargeAttString yy_setTextHighlightRange:NSMakeRange(0, rechargeAttString.length) color:nil backgroundColor:nil userInfo:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
|
|
@kStrongify(self);
|
|
if (self.delegate) {
|
|
[self.delegate didSelectMewRechargeProtocol];
|
|
}
|
|
|
|
|
|
} longPressAction:nil];
|
|
|
|
NSMutableAttributedString *serviceAttString = [[NSMutableAttributedString alloc] initWithString:@"如有任何问题请咨询客服"];
|
|
serviceAttString.yy_color = [MewAppColor mewSecondTextColor];
|
|
serviceAttString.yy_font = [UIFont systemFontOfSize:13];
|
|
|
|
[attString appendAttributedString:rechargeAttString];
|
|
[attString appendAttributedString:serviceAttString];
|
|
_rechargePrivacyLabel.textAlignment = NSTextAlignmentCenter;
|
|
_rechargePrivacyLabel.attributedText = attString;
|
|
}
|
|
return _rechargePrivacyLabel;
|
|
}
|
|
|
|
- (UIButton *)rechargeButton {
|
|
if (!_rechargeButton) {
|
|
_rechargeButton = [[UIButton alloc] init];
|
|
[_rechargeButton setTitle:@"立即充值" forState:UIControlStateNormal];
|
|
[_rechargeButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
|
|
_rechargeButton.titleLabel.font = kMewSetFontMedium(16);
|
|
_rechargeButton.layer.cornerRadius = 24;
|
|
_rechargeButton.layer.masksToBounds = YES;
|
|
UIImage *image = [UIImage mew_gradientColorImageFromColors:@[[MewAppColor mewGetColorOfTextWithHexString:0xFF60FD],
|
|
[MewAppColor mewGetColorOfTextWithHexString:0x8974FF],
|
|
[MewAppColor mewGetColorOfTextWithHexString:0x69EBFF]
|
|
] gradientType:MewGradientTypeLeftToRight imgSize:CGSizeMake(KMewGetScreenWidth - 2*40, 48)];
|
|
_rechargeButton.backgroundColor = [UIColor colorWithPatternImage:image];
|
|
[_rechargeButton addTarget:self action:@selector(mew_rechargeButtonAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _rechargeButton;
|
|
}
|
|
|
|
- (NSMutableArray<UIView *> *)rechargeBgViewArrays {
|
|
if (!_rechargeBgViewArrays) {
|
|
_rechargeBgViewArrays = [NSMutableArray array];
|
|
}
|
|
return _rechargeBgViewArrays;
|
|
}
|
|
|
|
@end
|