// // YMRegisterView.m // MSYOUPAI // // Created by YoMi on 2024/2/5. // Copyright © 2024 MS. All rights reserved. // #import "YMRegisterView.h" #import "YMRegisterViewModel.h" @interface YMRegisterView () /// 注册VM @property (nonatomic, strong) YMRegisterViewModel *viewModel; /// 背景图 @property (nonatomic, strong) UIImageView *bgImgv; /// 注册提示 @property (nonatomic, strong) UILabel *registerTipsLb; /// 分割线 @property (nonatomic, strong) UIView *line1; /// 分割线 @property (nonatomic, strong) UIView *line2; /// 分割线 @property (nonatomic, strong) UIView *line3; /// 手机视图 @property (nonatomic, strong) UIView *mobileView; /// 手机号标签 @property (nonatomic, strong) UILabel *mobileLb; /// 手机号输入框 @property (nonatomic, strong) UITextField *mobileInputBox; /// 验证码视图 @property (nonatomic, strong) UIView *verifyCodeView; /// 验证码标签 @property (nonatomic, strong) UILabel *verifyCodeLb; /// 验证码输入框 @property (nonatomic, strong) UITextField *verifyCodeInputBox; /// 获取验证码 @property (nonatomic, strong) YMCaptchaCountdownButton *getVerifyCodeBtn; /// 密码视图 @property (nonatomic, strong) UIView *passwordView; /// 密码标签 @property (nonatomic, strong) UILabel *passwordLb; /// 密码输入框 @property (nonatomic, strong) UITextField *passwordInputBox; /// 协议视图 @property (nonatomic, strong) UIView *agreementView; /// 单选按钮 @property (nonatomic, strong) UIButton *radioBtn; /// 协议标签 @property (nonatomic, strong) YYLabel *agreementLb; /// 确定按钮 @property (nonatomic, strong) UIButton *registerBtn; @end @implementation YMRegisterView - (instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { } return self; } - (void)ym_setupViews{ [self addSubview:self.bgImgv]; [self addSubview:self.registerTipsLb]; [self addSubview:self.mobileView]; [self.mobileView addSubview:self.mobileLb]; [self.mobileView addSubview:self.mobileInputBox]; [self addSubview:self.verifyCodeView]; [self.verifyCodeView addSubview:self.verifyCodeLb]; [self.verifyCodeView addSubview:self.verifyCodeInputBox]; [self.verifyCodeView addSubview:self.getVerifyCodeBtn]; [self addSubview:self.passwordView]; [self.passwordView addSubview:self.passwordLb]; [self.passwordView addSubview:self.passwordInputBox]; [self addSubview:self.agreementView]; [self.agreementView addSubview:self.radioBtn]; [self.agreementView addSubview:self.agreementLb]; [self addSubview:self.registerBtn]; self.line1 = [UIView new]; self.line2 = [UIView new]; self.line3 = [UIView new]; for (UIView *line in @[self.line1,self.line2,self.line3]) { line.backgroundColor = HexColorFromRGBA(0x7E868E,0.24); } [self.mobileView addSubview:self.line1]; [self.verifyCodeView addSubview:self.line2]; [self.passwordView addSubview:self.line3]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.bgImgv mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.equalTo(self); make.height.mas_equalTo(adapt(360)); }]; [self.registerTipsLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(adapt(24)); make.left.equalTo(self).offset(adapt(30)); make.right.equalTo(self).offset(adapt(-30)); make.height.mas_equalTo(adapt(60)); }]; [self.mobileView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.registerTipsLb.mas_bottom).offset(adapt(16)); make.left.equalTo(self).offset(adapt(30)); make.right.equalTo(self).offset(adapt(-30)); make.height.mas_equalTo(adapt(55)); }]; [self.mobileLb mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.mobileView); make.centerY.equalTo(self.mobileView); make.width.mas_equalTo(adapt(70)); }]; [self.mobileInputBox mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.mobileLb.mas_right).offset(adapt(10)); make.right.equalTo(self.passwordView).offset(adapt(-10)); make.centerY.equalTo(self.mobileLb); make.height.mas_equalTo(adapt(55)); }]; [self.line1 mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.mobileView); make.left.equalTo(self.mobileLb.mas_right); make.height.mas_equalTo(adapt(34)); make.width.mas_equalTo(1); }]; [self.verifyCodeView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.mobileView.mas_bottom).offset(adapt(16)); make.left.equalTo(self.mobileView.mas_left); make.right.equalTo(self.mobileView.mas_right); make.height.mas_equalTo(adapt(55)); }]; [self.verifyCodeLb mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.verifyCodeView); make.centerY.equalTo(self.verifyCodeView); make.width.mas_equalTo(adapt(70)); }]; [self.verifyCodeInputBox mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.verifyCodeLb.mas_right).offset(adapt(10)); make.centerY.equalTo(self.verifyCodeLb); make.height.mas_equalTo(adapt(55)); }]; [self.verifyCodeInputBox setContentCompressionResistancePriority:(UILayoutPriorityDefaultLow) forAxis:(UILayoutConstraintAxisHorizontal)]; [self.getVerifyCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.verifyCodeInputBox.mas_right).offset(adapt(10)); make.right.equalTo(self.verifyCodeView).offset(-20); make.top.equalTo(self.verifyCodeView); make.bottom.equalTo(self.verifyCodeView); }]; [self.line2 mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.verifyCodeView); make.left.equalTo(self.verifyCodeLb.mas_right); make.height.mas_equalTo(adapt(34)); make.width.mas_equalTo(1); }]; [self.passwordView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.verifyCodeView.mas_bottom).offset(adapt(16)); make.left.equalTo(self.mobileView.mas_left); make.right.equalTo(self.mobileView.mas_right); make.height.mas_equalTo(adapt(55)); }]; [self.passwordLb mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.passwordView); make.centerY.equalTo(self.passwordView); make.width.mas_equalTo(adapt(70)); }]; [self.passwordInputBox mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.passwordLb.mas_right).offset(adapt(10)); make.centerY.equalTo(self.passwordLb); make.right.equalTo(self.passwordView).offset(adapt(-10)); make.height.mas_equalTo(adapt(30)); }]; [self.line3 mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.passwordView); make.left.equalTo(self.passwordLb.mas_right); make.height.mas_equalTo(adapt(34)); make.width.mas_equalTo(1); }]; [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.passwordView.mas_bottom).offset(adapt(16)); make.left.equalTo(self.mobileView.mas_left); make.right.equalTo(self.mobileView.mas_right); make.height.mas_equalTo(adapt(55)); }]; [self.agreementView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.mas_centerX); make.bottom.equalTo(self).offset(Is_iPhoneX ? adapt(-32) : adapt(-12)); }]; [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(17)); }]; [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)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMRegisterViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; RAC(self.viewModel , mobile) = [[RACSignal merge:@[RACObserve(self.mobileInputBox, text),self.mobileInputBox.rac_textSignal]] takeUntil:self.rac_willDeallocSignal]; RAC(self.viewModel , verifyCode) = [[RACSignal merge:@[RACObserve(self.verifyCodeInputBox, text),self.verifyCodeInputBox.rac_textSignal]]takeUntil:self.rac_willDeallocSignal]; RAC(self.viewModel , password) = [[RACSignal merge:@[RACObserve(self.passwordInputBox, text),self.passwordInputBox.rac_textSignal]]takeUntil:self.rac_willDeallocSignal]; [self.viewModel.validRegisterSignal subscribeNext:^(id _Nullable value) { self.registerBtn.enabled = [value boolValue]; if ([value boolValue]) { self.registerBtn.alpha = 1; } else { self.registerBtn.alpha = 0.5; } }]; } - (UIImageView *)bgImgv { if (!_bgImgv) { _bgImgv = [[UIImageView alloc]init]; _bgImgv.image = ImageByName(@"ym_login_phone_bg"); } return _bgImgv; } - (UIView *)mobileView{ if (!_mobileView) { _mobileView = [[UIView alloc]init]; _mobileView.backgroundColor = UIColor.whiteColor; [_mobileView addRectCorner:(UIRectCornerAllCorners) radius:adapt(55) / 2.0]; } return _mobileView; } - (UILabel *)registerTipsLb { if (!_registerTipsLb) { _registerTipsLb = [[UILabel alloc]init]; _registerTipsLb.hidden = NO; _registerTipsLb.font = LCBoldFont(24); _registerTipsLb.textColor = HexColorFromRGB(0xEE538F); _registerTipsLb.textAlignment = NSTextAlignmentLeft; _registerTipsLb.text = @"您好,\n欢迎注册"; _registerTipsLb.numberOfLines = 0; } return _registerTipsLb; } - (UILabel *)mobileLb{ if (!_mobileLb) { _mobileLb = [[UILabel alloc]init]; _mobileLb.font = LCFont(14); _mobileLb.textColor = HexColorFromRGB(0x1B2739); _mobileLb.textAlignment = NSTextAlignmentCenter; _mobileLb.text = @"手机号"; } return _mobileLb; } - (UITextField *)mobileInputBox{ if (!_mobileInputBox) { NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init]; style.minimumLineHeight = 0; NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入手机号"]; placeholderAttributed.yy_paragraphStyle = style; placeholderAttributed.yy_font = LCFont(14); placeholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); _mobileInputBox = [[UITextField alloc]init]; _mobileInputBox.attributedPlaceholder = placeholderAttributed; _mobileInputBox.clearButtonMode = UITextFieldViewModeWhileEditing; _mobileInputBox.autocorrectionType = UITextAutocorrectionTypeDefault; _mobileInputBox.autocapitalizationType = UITextAutocapitalizationTypeNone; _mobileInputBox.keyboardType = UIKeyboardTypePhonePad; _mobileInputBox.ba_maxLength = 11; // @weakify(self) [[[_mobileInputBox rac_textSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { // @strongify(self) }]; } return _mobileInputBox; } - (UIView *)verifyCodeView{ if (!_verifyCodeView) { _verifyCodeView = [[UIView alloc]init]; _verifyCodeView.backgroundColor = UIColor.whiteColor; [_verifyCodeView addRectCorner:(UIRectCornerAllCorners) radius:adapt(55) / 2.0]; } return _verifyCodeView; } - (UILabel *)verifyCodeLb{ if (!_verifyCodeLb) { _verifyCodeLb = [[UILabel alloc]init]; _verifyCodeLb.font = LCFont(14); _verifyCodeLb.textColor = HexColorFromRGB(0x1B2739); _verifyCodeLb.textAlignment = NSTextAlignmentCenter; _verifyCodeLb.text = @"验证码"; } return _verifyCodeLb; } - (UITextField *)verifyCodeInputBox{ if (!_verifyCodeInputBox) { NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init]; style.minimumLineHeight = 0; NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入手机验证码"]; placeholderAttributed.yy_paragraphStyle = style; placeholderAttributed.yy_font = LCFont(14); placeholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); _verifyCodeInputBox = [[UITextField alloc]init]; _verifyCodeInputBox.attributedPlaceholder = placeholderAttributed; _verifyCodeInputBox.clearButtonMode = UITextFieldViewModeWhileEditing; _verifyCodeInputBox.autocorrectionType = UITextAutocorrectionTypeDefault; _verifyCodeInputBox.autocapitalizationType = UITextAutocapitalizationTypeNone; _verifyCodeInputBox.keyboardType = UIKeyboardTypeDecimalPad; // @weakify(self) [[[_verifyCodeInputBox rac_textSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { // @strongify(self) }]; } return _verifyCodeInputBox; } - (YMCaptchaCountdownButton *)getVerifyCodeBtn{ if (!_getVerifyCodeBtn) { _getVerifyCodeBtn = [YMCaptchaCountdownButton buttonWithType:UIButtonTypeCustom]; _getVerifyCodeBtn.titleLabel.font = LCFont(14); [_getVerifyCodeBtn setTitleColor:HexColorFromRGB(0xFF6893) forState:UIControlStateNormal]; [_getVerifyCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal]; [_getVerifyCodeBtn countDownButtonHandler:^(YMCaptchaCountdownButton *sender, NSInteger tag) { if (OCStringIsEmpty(self.mobileInputBox.text)) { [ZCHUDHelper showTitle:@"请输入手机号"]; return; } [self.mobileInputBox resignFirstResponder]; [self.verifyCodeInputBox resignFirstResponder]; [self.passwordInputBox resignFirstResponder]; [self.viewModel getVerifyCodeHandler:^(NSDictionary * _Nonnull dic, NSError * _Nullable error) { sender.enabled = NO; [sender startCountDownWithSecond:59]; [sender countDownChanging:^NSString *(YMCaptchaCountdownButton *countDownButton, NSUInteger second) { NSString *title = [NSString stringWithFormat:@"重新发送(%zds)",second]; return title; }]; [sender countDownFinished:^NSString *(YMCaptchaCountdownButton *countDownButton, NSUInteger second) { countDownButton.enabled = YES; return @"重新发送"; }]; }]; }]; } return _getVerifyCodeBtn; } - (UIView *)passwordView{ if (!_passwordView) { _passwordView = [[UIView alloc]init]; _passwordView.backgroundColor = UIColor.whiteColor; [_passwordView addRectCorner:(UIRectCornerAllCorners) radius:adapt(55) / 2.0]; } return _passwordView; } - (UILabel *)passwordLb{ if (!_passwordLb) { _passwordLb = [[UILabel alloc]init]; _passwordLb.font = LCFont(14); _passwordLb.textColor = HexColorFromRGB(0x1B2739); _passwordLb.textAlignment = NSTextAlignmentCenter; _passwordLb.text = @"密 码"; } return _passwordLb; } - (UITextField *)passwordInputBox{ if (!_passwordInputBox) { NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init]; style.minimumLineHeight = 0; NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入密码"]; placeholderAttributed.yy_paragraphStyle = style; placeholderAttributed.yy_font = LCFont(14); placeholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); _passwordInputBox = [[UITextField alloc]init]; _passwordInputBox.attributedPlaceholder = placeholderAttributed; _passwordInputBox.clearButtonMode = UITextFieldViewModeWhileEditing; _passwordInputBox.autocorrectionType = UITextAutocorrectionTypeDefault; _passwordInputBox.autocapitalizationType = UITextAutocapitalizationTypeNone; _passwordInputBox.keyboardType = UIKeyboardTypeDefault; _passwordInputBox.secureTextEntry = YES; // @weakify(self) [[[_passwordInputBox rac_textSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { // @strongify(self) }]; } return _passwordInputBox; } - (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]; [[[_radioBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { sender.selected = !sender.selected; }]; } return _radioBtn; } - (YYLabel *)agreementLb{ if (!_agreementLb) { _agreementLb = [[YYLabel alloc] init]; _agreementLb.numberOfLines = 0; _agreementLb.preferredMaxLayoutWidth = kFrameWidth - 55; NSString *agreementText = @"同意《用户协议》与《隐私政策》"; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init]; paragraphStyle.alignment = NSTextAlignmentLeft; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:agreementText]; attributedString.yy_font = LCFont(12); attributedString.yy_color = HexColorFromRGBA(0x000000,0.65); attributedString.yy_paragraphStyle = paragraphStyle; //设置高亮色和点击事件 [attributedString yy_setTextHighlightRange:[agreementText rangeOfString:@"《用户协议》"] color:HexColorFromRGB(0x6D82FD) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{ ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserProtocolH5] }]; [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{ RouterViewModel:webArticleVM } completion:nil]; }]; //设置高亮色和点击事件 [attributedString yy_setTextHighlightRange:[[attributedString string] rangeOfString:@"《隐私政策》"] color:HexColorFromRGB(0x6D82FD) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{ ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserPrivacyH5] }]; [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{ RouterViewModel:webArticleVM } completion:nil]; }]; _agreementLb.attributedText = attributedString; } return _agreementLb; } - (UIButton *)registerBtn{ if (!_registerBtn) { _registerBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _registerBtn.titleLabel.font = LCBoldFont(15); [_registerBtn setTitle:@"注册" forState:UIControlStateNormal]; [_registerBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal]; [_registerBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP]; _registerBtn.layer.cornerRadius = adapt(55)/2; _registerBtn.backgroundColor = UIColor.whiteColor; WS(weakSelf) [[[_registerBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { if (OCStringIsEmpty(weakSelf.mobileInputBox.text)) { [ZCHUDHelper showTitle:@"请输入手机号"]; return; } if (OCStringIsEmpty(weakSelf.verifyCodeInputBox.text)) { [ZCHUDHelper showTitle:@"请输入手机号"]; return; } if (OCStringIsEmpty(weakSelf.passwordInputBox.text)) { [ZCHUDHelper showTitle:@"请输入密码"]; return; } if (!weakSelf.radioBtn.selected) { YMLoginRegistrAgreementPopupView *customView = [[YMLoginRegistrAgreementPopupView alloc]init]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; [popupView pop]; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm) { @strongify(popupView) if (isConfirm) { weakSelf.radioBtn.selected = YES; [weakSelf.viewModel registerRequest]; } [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; customView.dismissBlock = ^{ @strongify(popupView) [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; return; } [weakSelf.viewModel registerRequest]; }]; } return _registerBtn; } @end