123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- //
- // LDLinkPhoneController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/21.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDLinkPhoneController.h"
- #import "LDPhoneFieldView.h"
- #import "LDLoginRequest.h"
- #import "LDLinkFansController.h"
- #import "LDPushToWeixViewController.h"
- @interface LDLinkPhoneController ()
- {
- LDPhoneFieldView *_phoneFieldView;
- }
- @end
- @implementation LDLinkPhoneController
- - (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];
-
- LDPhoneFieldView *fieldView = [[LDPhoneFieldView 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 {
- sender.enabled = NO;
- [SVProgressHUD show];
- NSString *phone = [_phoneFieldView getPhoneText];
- NSString *code = [_phoneFieldView getCodeText];
- NSDictionary *para = @{@"phone":phone,
- @"code":code,
- @"union_id":self.wx_union_id};
-
- [LDLoginRequest post:ValidLoginAPI params:para success:^(id json) {
- [SVProgressHUD dismiss];
- sender.enabled = YES;
- BOOL is_binded_code =[json[@"is_binded_code"] boolValue];
- if (is_binded_code) {
- //手机号绑定成功,已绑定邀请码,登录成功
- AccountModel *model = [AccountModel yy_modelWithJSON:json];
- model.unionid = self.wx_union_id;
- model.openId = self.wx_open_id;
- [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:NO completion:nil];
-
-
- }else {
- //绑定手机成功 去绑定邀请码
- [self dismissViewControllerAnimated:NO completion:^{
- LDLinkFansController *linkFnas = [[LDLinkFansController alloc] init];
- linkFnas.wx_union_id = self.wx_union_id;
- linkFnas.wx_open_id = self.wx_open_id;
- linkFnas.modalPresentationStyle = UIModalPresentationFullScreen;
- [[self currentViewController] presentViewController:linkFnas animated:YES completion:nil];
- }];
-
- }
-
- } failure:^(NSError *error) {
- [MBProgressHUD showMessage:@"加载失败,请稍后重试"];
- [SVProgressHUD dismiss];
- sender.enabled = YES;
- }];
- }
- - (UIViewController *)currentViewController{
-
- UIViewController * currVC = nil;
- UIWindow *window = [UIApplication sharedApplication].delegate.window;
- UIViewController * Rootvc = window.rootViewController;
-
- do {
- if ([Rootvc isKindOfClass:[UINavigationController class]]) {
- UINavigationController * nav = (UINavigationController *)Rootvc;
- UIViewController * v = [nav.viewControllers lastObject];
- currVC = v;
- Rootvc = v.presentedViewController;
- continue;
- }else if([Rootvc isKindOfClass:[UITabBarController class]]){
- UITabBarController * tabVC = (UITabBarController *)Rootvc;
- currVC = tabVC;
- Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
- continue;
- }
- } while (Rootvc!=nil);
-
- return currVC;
- }
- - (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
|