// // QXBindMobileViewController.m // QXLive // // Created by 启星 on 2025/5/12. // #import "QXBindMobileViewController.h" #import "QXLoginTextField.h" #import "QXMineNetwork.h" #import "QXLoginNetwork.h" @interface QXBindMobileViewController () @property (nonatomic,strong)UILabel *mobileLabel; @property (nonatomic,strong)QXLoginTextField *oldMobileCodeTextField; @property (nonatomic,strong)QXLoginTextField *accountTextField; @property (nonatomic,strong)QXLoginTextField *codeTextField; @property (nonatomic,strong)UIButton *commitBtn; @property (nonatomic,assign)BOOL isNetworking; @end @implementation QXBindMobileViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } -(void)setNavgationItems{ [super setNavgationItems]; self.navigationItem.title = QXText(@"手机绑定"); } -(void)initSubViews{ if (self.haveMobile) { self.mobileLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, NavContentHeight+17, SCREEN_WIDTH-32, 18)]; self.mobileLabel.textColor = RGB16(0x999999); self.mobileLabel.font = [UIFont systemFontOfSize:12]; NSString *pMobile = [QXGlobal.shareGlobal.loginModel.mobile stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"]; NSString *mobile = [NSString stringWithFormat:@"当前手机号 %@",pMobile]; NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:mobile]; [attr yy_setFont:[UIFont boldSystemFontOfSize:16] range:[mobile rangeOfString:pMobile]]; [attr yy_setColor:RGB16(0x333333) range:[mobile rangeOfString:pMobile]]; self.mobileLabel.attributedText = attr; [self.view addSubview:self.mobileLabel]; self.oldMobileCodeTextField = [[QXLoginTextField alloc] initWithFrame:CGRectMake(16, self.mobileLabel.bottom+12, SCREEN_WIDTH-32, 44) type:(LoginTextTypeCode)]; self.oldMobileCodeTextField.backgroundColor = RGB16(0xEFF2F8); self.oldMobileCodeTextField.textField.placeholder = @"请输入旧手机号验证码"; [self.oldMobileCodeTextField addRoundedCornersWithRadius:11]; self.oldMobileCodeTextField.delegate = self; [self.view addSubview:self.oldMobileCodeTextField]; self.accountTextField = [[QXLoginTextField alloc] initWithFrame:CGRectMake(16, self.oldMobileCodeTextField.bottom+12, SCREEN_WIDTH-32, 44) type:(LoginTextTypeAccount)]; self.accountTextField.backgroundColor = RGB16(0xEFF2F8); [self.accountTextField addRoundedCornersWithRadius:11]; self.codeTextField.textField.placeholder = @"请输入新手机号"; [self.view addSubview:self.accountTextField]; self.codeTextField = [[QXLoginTextField alloc] initWithFrame:CGRectMake(16, self.accountTextField.bottom+12, SCREEN_WIDTH-32, 44) type:(LoginTextTypeCode)]; self.codeTextField.backgroundColor = RGB16(0xEFF2F8); [self.codeTextField addRoundedCornersWithRadius:11]; self.codeTextField.delegate = self; self.codeTextField.textField.placeholder = @"请输入新手机号验证码"; [self.view addSubview:self.codeTextField]; self.commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(38, self.codeTextField.bottom+16, SCREEN_WIDTH-38*2, 42)]; self.commitBtn.needEventInterval = 1; [self.commitBtn setTitle:QXText(@"立即绑定") forState:(UIControlStateNormal)]; [self.commitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)]; [self.commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.commitBtn addRoundedCornersWithRadius:21]; self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:14]; self.commitBtn.backgroundColor = QXConfig.themeColor; [self.view addSubview:self.commitBtn]; }else{ self.accountTextField = [[QXLoginTextField alloc] initWithFrame:CGRectMake(16, NavContentHeight+12, SCREEN_WIDTH-32, 44) type:(LoginTextTypeAccount)]; self.accountTextField.backgroundColor = RGB16(0xEFF2F8); [self.accountTextField addRoundedCornersWithRadius:11]; [self.view addSubview:self.accountTextField]; self.codeTextField = [[QXLoginTextField alloc] initWithFrame:CGRectMake(16, self.accountTextField.bottom+12, SCREEN_WIDTH-32, 44) type:(LoginTextTypeCode)]; self.codeTextField.backgroundColor = RGB16(0xEFF2F8); [self.codeTextField addRoundedCornersWithRadius:11]; self.codeTextField.delegate = self; [self.view addSubview:self.codeTextField]; self.commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(38, self.codeTextField.bottom+16, SCREEN_WIDTH-38*2, 42)]; self.commitBtn.needEventInterval = 1; [self.commitBtn setTitle:QXText(@"立即绑定") forState:(UIControlStateNormal)]; [self.commitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)]; [self.commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.commitBtn addRoundedCornersWithRadius:21]; self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:14]; self.commitBtn.backgroundColor = QXConfig.themeColor; [self.view addSubview:self.commitBtn]; } } -(void)didClickSendCode:(UIButton *)sender{ GetSmscodeType type = GetSmscodeTypeFindBindMobile; if (self.haveMobile) { GetSmscodeType type = GetSmscodeTypeFindChangeMobile; } if (sender == self.codeTextField.codeBtn) { sender.userInteractionEnabled = NO; if (self.accountTextField.textField.text.length < 11) { showToast(QXText(@"请输入正确的手机号码")); return; } if ([self.accountTextField.textField.text isEqualToString:QXGlobal.shareGlobal.loginModel.mobile]) { showToast(QXText(@"新手机号不能与旧手机号相同")); return; } MJWeakSelf self.isNetworking = YES; [QXLoginNetwork getSmscodeWithMobile:self.accountTextField.textField.text type:type successBlock:^(id _Nonnull responseObject) { [weakSelf.codeTextField startTimeDown]; sender.userInteractionEnabled = YES; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(msg); sender.userInteractionEnabled = YES; }]; }else{ NSString *oldMobile = [QXGlobal shareGlobal].loginModel.mobile; MJWeakSelf sender.userInteractionEnabled = NO; [QXLoginNetwork getSmscodeWithMobile:oldMobile type:type successBlock:^(id _Nonnull responseObject) { [weakSelf.oldMobileCodeTextField startTimeDown]; sender.userInteractionEnabled = YES; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(msg); sender.userInteractionEnabled = YES; }]; } } -(void)commitAction{ NSString *oldMobile = [QXGlobal shareGlobal].loginModel.mobile; NSString *mobile = self.accountTextField.textField.text; NSString *sms_code = self.codeTextField.textField.text; [QXMineNetwork changeMobileWithOldMobile:oldMobile new_mobile:mobile sms_code:sms_code successBlock:^(NSDictionary * _Nonnull dict) { showToast(QXText(@"绑定成功")); [QXGlobal shareGlobal].loginModel.mobile = mobile; [[QXGlobal shareGlobal]updateUserInfoWithMolde:[QXGlobal shareGlobal].loginModel]; [self.navigationController popToRootViewControllerAnimated:YES]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(msg) }]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end