// // NYLoginBindViewController.m // jiaPei // // Created by Ning.ge on 2025/3/31. // Copyright © 2025 JCZ. All rights reserved. // #import "NYLoginBindViewController.h" #import "RQPhoneView.h" #import "RQPasswordView.h" @interface NYLoginBindViewController () @property (nonatomic, readonly, strong) NYLoginBindViewModel *viewModel; @property (strong, readwrite, nonatomic) RQPhoneView *phoneView; @property (strong, readwrite, nonatomic) RQPasswordView *passwordView; @property (weak, nonatomic) IBOutlet UIView *containerView; @property (weak, nonatomic) IBOutlet UIButton *submit_btn; @end @implementation NYLoginBindViewController @dynamic viewModel; - (void)viewDidLoad { [super viewDidLoad]; /// 设置 [self rq_setup]; [self setupSubViews]; } #pragma mark - 设置子控件 - (void)setupSubViews { @weakify(self) /// 手机号码 RQPhoneView *phoneView = [RQPhoneView loginCodeView]; self.phoneView = phoneView; [self.containerView addSubview:phoneView]; /// 密码 RQPasswordView *passwordView = [RQPasswordView passwordView]; self.passwordView = passwordView; [self.containerView addSubview:passwordView]; /// 布局 [phoneView mas_makeConstraints:^(MASConstraintMaker *make) { @strongify(self) make.top.mas_equalTo(self.containerView); make.left.mas_equalTo(self.containerView).mas_offset(16.f); make.right.mas_equalTo(self.containerView).mas_offset(-16.f); make.height.mas_offset(RQ_FIT_HORIZONTAL(44.f)); phoneView.layer.cornerRadius = RQ_FIT_HORIZONTAL(44.f) / 2.f; }]; [passwordView mas_makeConstraints:^(MASConstraintMaker *make) { @strongify(self) make.top.mas_equalTo(self.phoneView.mas_bottom).mas_offset(16.f); make.left.mas_equalTo(self.containerView).mas_offset(16.f); make.right.mas_equalTo(self.containerView).mas_offset(-16.f); make.height.mas_offset(RQ_FIT_HORIZONTAL(44.f)); passwordView.layer.cornerRadius = RQ_FIT_HORIZONTAL(44.f) / 2.f; }]; } #pragma mark - 初始化 - (void)rq_setup { if(self.viewModel.isBind){ [self.submit_btn setTitle:@"解除绑定" forState:UIControlStateNormal]; }else{ [self.submit_btn setTitle:@"立即绑定" forState:UIControlStateNormal]; } } //立即绑定 - (IBAction)loginBinddo:(id)sender { NSString *logincode = self.phoneView.loginCodeTextField.text; NSString *password = self.passwordView.passwordTextField.text; if(RQStringIsEmpty(logincode)){ ShowMsg(@"请输入账号"); return; } if(RQStringIsEmpty(password)){ ShowMsg(@"请输入密码"); return; } /// 存储登录账号 [SAMKeychain setRawLogin:logincode]; [SAMKeychain setRawLoginPassword:password]; if(self.viewModel.isBind){ //解除绑定 [MBProgressHUD rq_showProgressHUD:@""]; NSDictionary *dict = @{ @"logincode": logincode, @"password": [password md5String] }; [jiaPeiManager NYRequestAnythingDataWithURL:RQ_POST_UnBindGzptUser contentType:@"application/json" parameters:dict completion:^(NSDictionary *dict) { if([dict[@"code"] intValue]==200){ RQUserModel *user = [RQUserModel yy_modelWithDictionary:[RQ_USER_MANAGER.currentUser yy_modelToJSONObject]]; user.openId = nil; /// 存储用户数据 [RQ_USER_MANAGER loginUser:user]; ShowMsg(@"解绑成功"); [self.navigationController popViewControllerAnimated:YES]; }else{ ShowMsg(dict[@"msg"]); } [MBProgressHUD rq_hideHUD]; }]; }else{ //立即绑定 //提交-web [MBProgressHUD rq_showProgressHUD:@""]; NSDictionary *dict = @{ @"logincode": logincode, @"openid": self.viewModel.openid, @"password": [password md5String] }; [jiaPeiManager NYRequestAnythingDataWithURL:RQ_POST_BindGzptUser contentType:@"application/json" parameters:dict completion:^(NSDictionary *dict) { if([dict[@"code"] intValue]==200){ if (myDelegate.isLogin) {//已经登录提示-绑定成功 RQUserModel *user = [RQUserModel yy_modelWithDictionary:[RQ_USER_MANAGER.currentUser yy_modelToJSONObject]]; user.openId = self.viewModel.openid; /// 存储用户数据 [RQ_USER_MANAGER loginUser:user]; ShowMsg(@"绑定成功"); [self.navigationController popViewControllerAnimated:YES]; }else{ //绑定成功-登录 RQUserModel *user = [RQUserModel yy_modelWithDictionary:dict[@"data"]]; /// 存储用户数据 [RQ_USER_MANAGER loginUser:user]; // //通知登录 // [RQNotificationCenter postNotificationName:RQWeBanindOnRespNotification object:user]; [RQ_VIP_Module isActiveWithCcomplete:^(RQActivationModel * _Nullable activationModel, BOOL isSuccess) {}]; [[RQ_HTTP_Service getMyScoreWithSubject:RQHomePageSubjectType_SubjectOne] subscribeNext:^(NSArray *examResultModelArr) { RQ_COMMON_MANAGER.myExamOneCount = examResultModelArr.count; RQ_COMMON_MANAGER.examResultOneListArr = examResultModelArr; }]; [[RQ_HTTP_Service getMyScoreWithSubject:RQHomePageSubjectType_SubjectFour] subscribeNext:^(NSArray *examResultModelArr) { RQ_COMMON_MANAGER.myExamFourCount = examResultModelArr.count; RQ_COMMON_MANAGER.examResultFourListArr = examResultModelArr; }]; if (user.channel == RQUserLoginChannelTypePhone) { /// 切换更控制器 dispatch_async(dispatch_get_main_queue(), ^{ /// 发通知 [[NSNotificationCenter defaultCenter] postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeLogin)}]; }); } } }else{ ShowMsg(dict[@"msg"]); } [MBProgressHUD rq_hideHUD]; }]; } } @end