// // YMCancellationAccountView.m // MSYOUPAI // // Created by YoMi on 2024/3/17. // Copyright © 2024 MS. All rights reserved. // #import "YMCancellationAccountInfoView.h" #import "YMCancellationAccountViewModel.h" @interface YMCancellationAccountInfoView() /// 注销账号VM @property (nonatomic, strong) YMCancellationAccountViewModel *viewModel; /// 注销账号提示标签 @property (nonatomic, strong) UILabel *cancellationAccountTipsLb; /// 协议视图 @property (nonatomic, strong) UIView *agreementView; /// 单选按钮 @property (nonatomic, strong) UIButton *radioBtn; /// 协议标签 @property (nonatomic, strong) YYLabel *agreementLb; /// 注销按钮 @property (nonatomic, strong) UIButton *cancellationBtn; @end @implementation YMCancellationAccountInfoView - (void)ym_setupViews{ [self addSubview:self.cancellationAccountTipsLb]; [self addSubview:self.agreementView]; [self.agreementView addSubview:self.radioBtn]; [self.agreementView addSubview:self.agreementLb]; [self addSubview:self.cancellationBtn]; [self addSubview:self.maskView]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.cancellationAccountTipsLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(adapt(10)); make.left.equalTo(self).offset(adapt(15)); make.right.equalTo(self).offset(adapt(-15)); }]; [self.agreementView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.mas_centerX); make.top.equalTo(self.cancellationAccountTipsLb.mas_bottom).offset(adapt(10)); }]; [self.radioBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.agreementLb.mas_centerY); make.left.equalTo(self.agreementView).offset(adapt(5)); make.width.height.mas_equalTo(adapt(12)); }]; [self.agreementLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.agreementView).offset(adapt(10)); make.left.equalTo(self.radioBtn.mas_right).offset(adapt(5)); make.right.equalTo(self.agreementView).offset(adapt(-5)); make.bottom.equalTo(self.agreementView).offset(adapt(-10)); }]; [self.cancellationBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.agreementView.mas_bottom).offset(adapt(24)); make.left.equalTo(self).offset(adapt(25)); make.right.equalTo(self).offset(adapt(-25)); make.bottom.equalTo(self).offset(adapt(-24)); make.height.mas_equalTo(adapt(40)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMCancellationAccountViewModel*)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; RAC(self.cancellationBtn , enabled) = self.viewModel.validCancellationSignal; [self.viewModel.validCancellationSignal subscribeNext:^(id _Nullable value) { self.cancellationBtn.enabled = [value boolValue]; if ([value boolValue]) { self.cancellationBtn.alpha = 1; } else { self.cancellationBtn.alpha = 0.5; } }]; @weakify(self) [[[[RACObserve(self.viewModel, cancellationAccountTips) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSAttributedString * cancellationAccountTips) { @strongify(self) self.cancellationAccountTipsLb.attributedText = cancellationAccountTips; }]; } - (UILabel *)cancellationAccountTipsLb{ if (!_cancellationAccountTipsLb) { _cancellationAccountTipsLb = [[UILabel alloc] init]; _cancellationAccountTipsLb.numberOfLines = 0; } return _cancellationAccountTipsLb; } - (UIView *)agreementView{ if (!_agreementView) { _agreementView = [[UIView alloc]init]; } return _agreementView; } - (UIButton *)radioBtn{ if (!_radioBtn) { _radioBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_radioBtn setBackgroundImage:ImageByName(@"ym_login_auth_normal_icon") forState:UIControlStateNormal]; [_radioBtn setBackgroundImage:ImageByName(@"ym_login_auth_selected_icon") forState:UIControlStateSelected]; WS(weakSelf) [[[_radioBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { sender.selected = !sender.selected; weakSelf.viewModel.isAgree = sender.selected; }]; } return _radioBtn; } - (YYLabel *)agreementLb{ if (!_agreementLb) { _agreementLb = [[YYLabel alloc] init]; _agreementLb.numberOfLines = 0; _agreementLb.preferredMaxLayoutWidth = kFrameWidth - adapt(55); NSString *agreementText = @"我已阅读以上信息无异议"; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init]; paragraphStyle.alignment = NSTextAlignmentLeft; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:agreementText]; attributedString.yy_font = LCFont(11); attributedString.yy_color = HexColorFromRGB(0x7E848D); attributedString.yy_paragraphStyle = paragraphStyle; _agreementLb.attributedText = attributedString; } return _agreementLb; } - (UIButton *)cancellationBtn{ if (!_cancellationBtn) { _cancellationBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _cancellationBtn.titleLabel.font = LCBoldFont(15); [_cancellationBtn setTitle:@"确定" forState:UIControlStateNormal]; [_cancellationBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal]; [_cancellationBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP]; _cancellationBtn.layer.cornerRadius = adapt(40)/2; WS(weakSelf) [[[_cancellationBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { [weakSelf.viewModel submitCancellationAccountInfoData]; }]; } return _cancellationBtn; } @end