YMAccountBalanceRechargePopupView.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // YMAccountBalanceRechargePopupView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/16.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMAccountBalanceRechargePopupView.h"
  9. #import "YMAccountBalanceViewModel.h"
  10. #import "YMAccountBalanceRechargeItemView.h"
  11. #import "YMAccountBalancePayMethodView.h"
  12. @interface YMAccountBalanceRechargePopupView ()
  13. /// 账户余额VM
  14. @property (nonatomic, strong) YMAccountBalanceViewModel *viewModel;
  15. /// 容器滚动视图
  16. @property (nonatomic, strong) UIScrollView *contentScrollView;
  17. /// 容器视图
  18. @property (nonatomic, strong) UIView *contentView;
  19. /// 账户余额充值项目视图
  20. @property (nonatomic, strong) YMAccountBalanceRechargeItemView *accountBalanceRechargeItemView;
  21. /// 账户余额支付方式视图
  22. @property (nonatomic, strong) YMAccountBalancePayMethodView *accountBalancePayMethodView;
  23. /// 立即充值按钮
  24. @property (nonatomic, strong) UIButton *rechargeNowBtn;
  25. @end
  26. @implementation YMAccountBalanceRechargePopupView
  27. - (void)ym_setupViews{
  28. self.frame = CGRectMake(0, 0, kFrameWidth, kFrameHeight*0.7);
  29. [OCNotificationCenter addObserver:self selector:@selector(weChatOrAlipayPaymentSuccess:) name:ALIPAY_SUCCESS_NOTIFICATION object:nil];
  30. [OCNotificationCenter addObserver:self selector:@selector(weChatOrAlipayPaymentSuccess:) name:WECHATPAY_SUCCESS_NOTIFICATION object:nil];
  31. [self addSubview:self.contentScrollView];
  32. [self.contentScrollView addSubview:self.contentView];
  33. [self.contentView addSubview:self.accountBalanceRechargeItemView];
  34. [self.contentView addSubview:self.accountBalancePayMethodView];
  35. [self addSubview:self.rechargeNowBtn];
  36. [self setNeedsUpdateConstraints];
  37. [self updateConstraintsIfNeeded];
  38. }
  39. - (void)updateConstraints{
  40. [self.contentScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.top.equalTo(self);
  42. make.left.equalTo(self);
  43. make.right.equalTo(self);
  44. make.bottom.equalTo(self);
  45. }];
  46. [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.edges.equalTo(self.contentScrollView);
  48. make.width.equalTo(self.contentScrollView.mas_width);
  49. }];
  50. [self.accountBalanceRechargeItemView mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.top.equalTo(self.contentView).offset(adapt(10));
  52. make.left.equalTo(self.contentView).offset(adapt(10));
  53. make.right.equalTo(self.contentView).offset(adapt(-10));
  54. }];
  55. [self.accountBalancePayMethodView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.top.equalTo(self.accountBalanceRechargeItemView.mas_bottom).offset(adapt(20));
  57. make.left.equalTo(self.contentView).offset(adapt(10));
  58. make.right.equalTo(self.contentView).offset(adapt(-10));
  59. make.bottom.equalTo(self.contentView).offset(adapt(-90));
  60. }];
  61. [self.rechargeNowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.left.equalTo(self).offset(adapt(32));
  63. make.right.equalTo(self).offset(adapt(-32));
  64. make.bottom.equalTo(self).offset(Is_iPhoneX ? adapt(-32) : adapt(-12));
  65. make.height.mas_equalTo(adapt(50));
  66. }];
  67. [super updateConstraints];
  68. }
  69. - (void)dealloc{
  70. [OCNotificationCenter removeObserver:self];
  71. }
  72. - (void)ym_bindViewModel:(YMAccountBalanceViewModel *)viewModel{
  73. if (!viewModel) {
  74. return;
  75. }
  76. _viewModel = viewModel;
  77. [self.accountBalanceRechargeItemView ym_bindViewModel:self.viewModel];
  78. [self.accountBalancePayMethodView ym_bindViewModel:self.viewModel];
  79. [self.viewModel getAccountBalanceInfoData];
  80. }
  81. - (void)weChatOrAlipayPaymentSuccess:(NSNotification *)notice{
  82. if (self.dismissBlock) {
  83. self.dismissBlock();
  84. }
  85. }
  86. - (UIScrollView *)contentScrollView{
  87. if (!_contentScrollView) {
  88. _contentScrollView = [[UIScrollView alloc]init];
  89. _contentScrollView.alwaysBounceVertical = YES;
  90. _contentScrollView.showsVerticalScrollIndicator = NO;
  91. _contentScrollView.showsHorizontalScrollIndicator = NO;
  92. _contentScrollView.backgroundColor = HexColorFromRGB(0xF8F8FA);
  93. _contentScrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
  94. }
  95. return _contentScrollView;
  96. }
  97. - (UIView *)contentView{
  98. if (!_contentView) {
  99. _contentView = [[UIView alloc]init];
  100. }
  101. return _contentView;
  102. }
  103. - (YMAccountBalanceRechargeItemView *)accountBalanceRechargeItemView{
  104. if (!_accountBalanceRechargeItemView) {
  105. _accountBalanceRechargeItemView = [[YMAccountBalanceRechargeItemView alloc]init];
  106. }
  107. return _accountBalanceRechargeItemView;
  108. }
  109. - (YMAccountBalancePayMethodView *)accountBalancePayMethodView{
  110. if (!_accountBalancePayMethodView) {
  111. _accountBalancePayMethodView = [[YMAccountBalancePayMethodView alloc]init];
  112. }
  113. return _accountBalancePayMethodView;
  114. }
  115. - (UIButton *)rechargeNowBtn{
  116. if (!_rechargeNowBtn) {
  117. _rechargeNowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  118. _rechargeNowBtn.titleLabel.font = LCBoldFont(18);
  119. [_rechargeNowBtn setTitle:@"立即充值" forState:UIControlStateNormal];
  120. [_rechargeNowBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal];
  121. [_rechargeNowBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  122. _rechargeNowBtn.layer.cornerRadius = adapt(50)/2;
  123. _rechargeNowBtn.layer.masksToBounds = YES;
  124. WS(weakSelf)
  125. [[[_rechargeNowBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  126. [weakSelf.viewModel detectionAccountBalanceRechargeInfoData];
  127. }];
  128. }
  129. return _rechargeNowBtn;
  130. }
  131. @end