// // YMAccountBalanceRechargePopupView.m // MSYOUPAI // // Created by YoMi on 2024/3/16. // Copyright © 2024 MS. All rights reserved. // #import "YMAccountBalanceRechargePopupView.h" #import "YMAccountBalanceViewModel.h" #import "YMAccountBalanceRechargeItemView.h" #import "YMAccountBalancePayMethodView.h" @interface YMAccountBalanceRechargePopupView () /// 账户余额VM @property (nonatomic, strong) YMAccountBalanceViewModel *viewModel; /// 容器滚动视图 @property (nonatomic, strong) UIScrollView *contentScrollView; /// 容器视图 @property (nonatomic, strong) UIView *contentView; /// 账户余额充值项目视图 @property (nonatomic, strong) YMAccountBalanceRechargeItemView *accountBalanceRechargeItemView; /// 账户余额支付方式视图 @property (nonatomic, strong) YMAccountBalancePayMethodView *accountBalancePayMethodView; /// 立即充值按钮 @property (nonatomic, strong) UIButton *rechargeNowBtn; @end @implementation YMAccountBalanceRechargePopupView - (void)ym_setupViews{ self.frame = CGRectMake(0, 0, kFrameWidth, kFrameHeight*0.7); [OCNotificationCenter addObserver:self selector:@selector(weChatOrAlipayPaymentSuccess:) name:ALIPAY_SUCCESS_NOTIFICATION object:nil]; [OCNotificationCenter addObserver:self selector:@selector(weChatOrAlipayPaymentSuccess:) name:WECHATPAY_SUCCESS_NOTIFICATION object:nil]; [self addSubview:self.contentScrollView]; [self.contentScrollView addSubview:self.contentView]; [self.contentView addSubview:self.accountBalanceRechargeItemView]; [self.contentView addSubview:self.accountBalancePayMethodView]; [self addSubview:self.rechargeNowBtn]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.contentScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self); make.left.equalTo(self); make.right.equalTo(self); make.bottom.equalTo(self); }]; [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.contentScrollView); make.width.equalTo(self.contentScrollView.mas_width); }]; [self.accountBalanceRechargeItemView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(adapt(10)); make.left.equalTo(self.contentView).offset(adapt(10)); make.right.equalTo(self.contentView).offset(adapt(-10)); }]; [self.accountBalancePayMethodView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.accountBalanceRechargeItemView.mas_bottom).offset(adapt(20)); make.left.equalTo(self.contentView).offset(adapt(10)); make.right.equalTo(self.contentView).offset(adapt(-10)); make.bottom.equalTo(self.contentView).offset(adapt(-90)); }]; [self.rechargeNowBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self).offset(adapt(32)); make.right.equalTo(self).offset(adapt(-32)); make.bottom.equalTo(self).offset(Is_iPhoneX ? adapt(-32) : adapt(-12)); make.height.mas_equalTo(adapt(50)); }]; [super updateConstraints]; } - (void)dealloc{ [OCNotificationCenter removeObserver:self]; } - (void)ym_bindViewModel:(YMAccountBalanceViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; [self.accountBalanceRechargeItemView ym_bindViewModel:self.viewModel]; [self.accountBalancePayMethodView ym_bindViewModel:self.viewModel]; [self.viewModel getAccountBalanceInfoData]; } - (void)weChatOrAlipayPaymentSuccess:(NSNotification *)notice{ if (self.dismissBlock) { self.dismissBlock(); } } - (UIScrollView *)contentScrollView{ if (!_contentScrollView) { _contentScrollView = [[UIScrollView alloc]init]; _contentScrollView.alwaysBounceVertical = YES; _contentScrollView.showsVerticalScrollIndicator = NO; _contentScrollView.showsHorizontalScrollIndicator = NO; _contentScrollView.backgroundColor = HexColorFromRGB(0xF8F8FA); _contentScrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; } return _contentScrollView; } - (UIView *)contentView{ if (!_contentView) { _contentView = [[UIView alloc]init]; } return _contentView; } - (YMAccountBalanceRechargeItemView *)accountBalanceRechargeItemView{ if (!_accountBalanceRechargeItemView) { _accountBalanceRechargeItemView = [[YMAccountBalanceRechargeItemView alloc]init]; } return _accountBalanceRechargeItemView; } - (YMAccountBalancePayMethodView *)accountBalancePayMethodView{ if (!_accountBalancePayMethodView) { _accountBalancePayMethodView = [[YMAccountBalancePayMethodView alloc]init]; } return _accountBalancePayMethodView; } - (UIButton *)rechargeNowBtn{ if (!_rechargeNowBtn) { _rechargeNowBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _rechargeNowBtn.titleLabel.font = LCBoldFont(18); [_rechargeNowBtn setTitle:@"立即充值" forState:UIControlStateNormal]; [_rechargeNowBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal]; [_rechargeNowBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP]; _rechargeNowBtn.layer.cornerRadius = adapt(50)/2; _rechargeNowBtn.layer.masksToBounds = YES; WS(weakSelf) [[[_rechargeNowBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [weakSelf.viewModel detectionAccountBalanceRechargeInfoData]; }]; } return _rechargeNowBtn; } @end