// // DRLinkPhoneController.m // YouHuiProject // // Created by 小花 on 2018/5/21. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRLinkPhoneController.h" #import "DRPhoneFieldView.h" #import "DRLoginRequest.h" #import "DRLinkFansController.h" @interface DRLinkPhoneController () { DRPhoneFieldView *_phoneFieldView; } @end @implementation DRLinkPhoneController - (void)viewDidLoad { [super viewDidLoad]; [self configNavigationBar]; [self configUI]; } - (void)configNavigationBar { [self.navigationBar setNavTitle:@"绑定手机号"]; self.navigationBar.backgroundColor = [UIColor changeColor]; self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; } - (void)backAction { [self dismissViewControllerAnimated:YES completion:nil]; } - (void)configUI { self.view.backgroundColor = [UIColor whiteColor]; // UIButton *closeButton = [[UIButton alloc] initWithFrame:CGRectMake(20, 25, 30, 30)]; // [closeButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal]; // [closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside]; // [self.view addSubview:closeButton]; // // UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, Fitsize(91), SCREEN_WIDTH-20, 28)]; // title.font = [UIFont boldSystemFontOfSize:Fitsize(20)]; // title.textAlignment = NSTextAlignmentCenter; // title.textColor = [UIColor YHColorWithHex:0x333333]; // title.text = @"为了您的账户安全,请绑定手机号"; // [self.view addSubview:title]; DRPhoneFieldView *fieldView = [[DRPhoneFieldView alloc] initWithFrame:CGRectMake(0, NavBarHeight+Fitsize(100), SCREEN_WIDTH, 100) wx_union_id:self.wx_union_id]; [self.view addSubview:fieldView]; _phoneFieldView = fieldView; UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, fieldView.bottom+Fitsize(60), Fitsize(189), Fitsize(40))]; nextBtn.backgroundColor = [UIColor YHColorWithHex:0xd8d8d8]; [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [nextBtn setTitle:@"下一步" forState:UIControlStateNormal]; nextBtn.centerX = SCREEN_WIDTH/2; nextBtn.layer.cornerRadius = nextBtn.height/2; [nextBtn addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside]; nextBtn.enabled = NO; [self.view addSubview:nextBtn]; fieldView.nextEnable = ^(BOOL nextEnable) { nextBtn.enabled = nextEnable; nextBtn.backgroundColor = nextEnable ? [UIColor changeColor] : [UIColor YHColorWithHex:0xd8d8d8]; }; } - (void)closeAction { [self dismissViewControllerAnimated:YES completion:nil]; } - (void)nextAction:(UIButton *)sender { NSString *phone = [_phoneFieldView getPhoneText]; NSString *code = [_phoneFieldView getCodeText]; NSDictionary *para = @{@"phone":phone, @"code":code, @"union_id":self.wx_union_id}; [SVProgressHUD show]; [DRLoginRequest post:ValidLoginAPI params:para success:^(id json) { //手机号绑定成功,登录成功 AccountModel *model = [AccountModel yy_modelWithJSON:json]; [AccountTool saveAccount:model]; NSString *sex = [NSString stringWithFormat:@"%@",json[@"sex"]]; [[NSUserDefaults standardUserDefaults] setObject:sex forKey:UserSexKey]; [[NSUserDefaults standardUserDefaults] synchronize]; [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil]; [self dismissViewControllerAnimated:YES completion:nil]; [SVProgressHUD dismiss]; } failure:^(NSError *error) { [SVProgressHUD dismiss]; [MBProgressHUD showMessage:@"加载失败,请稍后重试"]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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