YMCancellationAccountInfoView.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // YMCancellationAccountView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/17.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMCancellationAccountInfoView.h"
  9. #import "YMCancellationAccountViewModel.h"
  10. @interface YMCancellationAccountInfoView()
  11. /// 注销账号VM
  12. @property (nonatomic, strong) YMCancellationAccountViewModel *viewModel;
  13. /// 注销账号提示标签
  14. @property (nonatomic, strong) UILabel *cancellationAccountTipsLb;
  15. /// 协议视图
  16. @property (nonatomic, strong) UIView *agreementView;
  17. /// 单选按钮
  18. @property (nonatomic, strong) UIButton *radioBtn;
  19. /// 协议标签
  20. @property (nonatomic, strong) YYLabel *agreementLb;
  21. /// 注销按钮
  22. @property (nonatomic, strong) UIButton *cancellationBtn;
  23. @end
  24. @implementation YMCancellationAccountInfoView
  25. - (void)ym_setupViews{
  26. [self addSubview:self.cancellationAccountTipsLb];
  27. [self addSubview:self.agreementView];
  28. [self.agreementView addSubview:self.radioBtn];
  29. [self.agreementView addSubview:self.agreementLb];
  30. [self addSubview:self.cancellationBtn];
  31. [self addSubview:self.maskView];
  32. [self setNeedsUpdateConstraints];
  33. [self updateConstraintsIfNeeded];
  34. }
  35. - (void)updateConstraints{
  36. [self.cancellationAccountTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.equalTo(self).offset(adapt(10));
  38. make.left.equalTo(self).offset(adapt(15));
  39. make.right.equalTo(self).offset(adapt(-15));
  40. }];
  41. [self.agreementView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.centerX.equalTo(self.mas_centerX);
  43. make.top.equalTo(self.cancellationAccountTipsLb.mas_bottom).offset(adapt(10));
  44. }];
  45. [self.radioBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.centerY.equalTo(self.agreementLb.mas_centerY);
  47. make.left.equalTo(self.agreementView).offset(adapt(5));
  48. make.width.height.mas_equalTo(adapt(12));
  49. }];
  50. [self.agreementLb mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.top.equalTo(self.agreementView).offset(adapt(10));
  52. make.left.equalTo(self.radioBtn.mas_right).offset(adapt(5));
  53. make.right.equalTo(self.agreementView).offset(adapt(-5));
  54. make.bottom.equalTo(self.agreementView).offset(adapt(-10));
  55. }];
  56. [self.cancellationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.top.equalTo(self.agreementView.mas_bottom).offset(adapt(24));
  58. make.left.equalTo(self).offset(adapt(25));
  59. make.right.equalTo(self).offset(adapt(-25));
  60. make.bottom.equalTo(self).offset(adapt(-24));
  61. make.height.mas_equalTo(adapt(40));
  62. }];
  63. [super updateConstraints];
  64. }
  65. - (void)ym_bindViewModel:(YMCancellationAccountViewModel*)viewModel{
  66. if (!viewModel) {
  67. return;
  68. }
  69. _viewModel = viewModel;
  70. RAC(self.cancellationBtn , enabled) = self.viewModel.validCancellationSignal;
  71. [self.viewModel.validCancellationSignal subscribeNext:^(id _Nullable value) {
  72. self.cancellationBtn.enabled = [value boolValue];
  73. if ([value boolValue]) {
  74. self.cancellationBtn.alpha = 1;
  75. } else {
  76. self.cancellationBtn.alpha = 0.5;
  77. }
  78. }];
  79. @weakify(self)
  80. [[[[RACObserve(self.viewModel, cancellationAccountTips) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSAttributedString * cancellationAccountTips) {
  81. @strongify(self)
  82. self.cancellationAccountTipsLb.attributedText = cancellationAccountTips;
  83. }];
  84. }
  85. - (UILabel *)cancellationAccountTipsLb{
  86. if (!_cancellationAccountTipsLb) {
  87. _cancellationAccountTipsLb = [[UILabel alloc] init];
  88. _cancellationAccountTipsLb.numberOfLines = 0;
  89. }
  90. return _cancellationAccountTipsLb;
  91. }
  92. - (UIView *)agreementView{
  93. if (!_agreementView) {
  94. _agreementView = [[UIView alloc]init];
  95. }
  96. return _agreementView;
  97. }
  98. - (UIButton *)radioBtn{
  99. if (!_radioBtn) {
  100. _radioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  101. [_radioBtn setBackgroundImage:ImageByName(@"ym_login_auth_normal_icon") forState:UIControlStateNormal];
  102. [_radioBtn setBackgroundImage:ImageByName(@"ym_login_auth_selected_icon") forState:UIControlStateSelected];
  103. WS(weakSelf)
  104. [[[_radioBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  105. sender.selected = !sender.selected;
  106. weakSelf.viewModel.isAgree = sender.selected;
  107. }];
  108. }
  109. return _radioBtn;
  110. }
  111. - (YYLabel *)agreementLb{
  112. if (!_agreementLb) {
  113. _agreementLb = [[YYLabel alloc] init];
  114. _agreementLb.numberOfLines = 0;
  115. _agreementLb.preferredMaxLayoutWidth = kFrameWidth - adapt(55);
  116. NSString *agreementText = @"我已阅读以上信息无异议";
  117. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
  118. paragraphStyle.alignment = NSTextAlignmentLeft;
  119. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:agreementText];
  120. attributedString.yy_font = LCFont(11);
  121. attributedString.yy_color = HexColorFromRGB(0x7E848D);
  122. attributedString.yy_paragraphStyle = paragraphStyle;
  123. _agreementLb.attributedText = attributedString;
  124. }
  125. return _agreementLb;
  126. }
  127. - (UIButton *)cancellationBtn{
  128. if (!_cancellationBtn) {
  129. _cancellationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  130. _cancellationBtn.titleLabel.font = LCBoldFont(15);
  131. [_cancellationBtn setTitle:@"确定" forState:UIControlStateNormal];
  132. [_cancellationBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal];
  133. [_cancellationBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  134. _cancellationBtn.layer.cornerRadius = adapt(40)/2;
  135. WS(weakSelf)
  136. [[[_cancellationBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  137. [weakSelf.viewModel submitCancellationAccountInfoData];
  138. }];
  139. }
  140. return _cancellationBtn;
  141. }
  142. @end