猎豆优选

LDLinkPhoneController.m 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // LDLinkPhoneController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/21.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDLinkPhoneController.h"
  9. #import "LDPhoneFieldView.h"
  10. #import "LDLoginRequest.h"
  11. #import "LDLinkFansController.h"
  12. #import "LDPushToWeixViewController.h"
  13. @interface LDLinkPhoneController ()
  14. {
  15. LDPhoneFieldView *_phoneFieldView;
  16. }
  17. @end
  18. @implementation LDLinkPhoneController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self configNavigationBar];
  22. [self configUI];
  23. }
  24. - (void)configNavigationBar {
  25. [self.navigationBar setNavTitle:@"绑定手机号"];
  26. self.navigationBar.backgroundColor = [UIColor changeColor];
  27. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  28. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  29. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  30. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  31. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  32. }
  33. - (void)backAction {
  34. [self dismissViewControllerAnimated:YES completion:nil];
  35. }
  36. - (void)configUI {
  37. self.view.backgroundColor = [UIColor whiteColor];
  38. // UIButton *closeButton = [[UIButton alloc] initWithFrame:CGRectMake(20, 25, 30, 30)];
  39. // [closeButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
  40. // [closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  41. // [self.view addSubview:closeButton];
  42. //
  43. // UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, Fitsize(91), SCREEN_WIDTH-20, 28)];
  44. // title.font = [UIFont boldSystemFontOfSize:Fitsize(20)];
  45. // title.textAlignment = NSTextAlignmentCenter;
  46. // title.textColor = [UIColor YHColorWithHex:0x333333];
  47. // title.text = @"为了您的账户安全,请绑定手机号";
  48. // [self.view addSubview:title];
  49. LDPhoneFieldView *fieldView = [[LDPhoneFieldView alloc] initWithFrame:CGRectMake(0, NavBarHeight+Fitsize(100), SCREEN_WIDTH, 100) wx_union_id:self.wx_union_id];
  50. [self.view addSubview:fieldView];
  51. _phoneFieldView = fieldView;
  52. UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, fieldView.bottom+Fitsize(60), Fitsize(189), Fitsize(40))];
  53. nextBtn.backgroundColor = [UIColor YHColorWithHex:0xd8d8d8];
  54. [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  55. [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
  56. nextBtn.centerX = SCREEN_WIDTH/2;
  57. nextBtn.layer.cornerRadius = nextBtn.height/2;
  58. [nextBtn addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
  59. nextBtn.enabled = NO;
  60. [self.view addSubview:nextBtn];
  61. fieldView.nextEnable = ^(BOOL nextEnable) {
  62. nextBtn.enabled = nextEnable;
  63. nextBtn.backgroundColor = nextEnable ? [UIColor changeColor] : [UIColor YHColorWithHex:0xd8d8d8];
  64. };
  65. }
  66. - (void)closeAction {
  67. [self dismissViewControllerAnimated:YES completion:nil];
  68. }
  69. - (void)nextAction:(UIButton *)sender {
  70. sender.enabled = NO;
  71. [SVProgressHUD show];
  72. NSString *phone = [_phoneFieldView getPhoneText];
  73. NSString *code = [_phoneFieldView getCodeText];
  74. NSDictionary *para = @{@"phone":phone,
  75. @"code":code,
  76. @"union_id":self.wx_union_id};
  77. [LDLoginRequest post:ValidLoginAPI params:para success:^(id json) {
  78. [SVProgressHUD dismiss];
  79. sender.enabled = YES;
  80. BOOL is_binded_code =[json[@"is_binded_code"] boolValue];
  81. if (is_binded_code) {
  82. //手机号绑定成功,已绑定邀请码,登录成功
  83. AccountModel *model = [AccountModel yy_modelWithJSON:json];
  84. model.unionid = self.wx_union_id;
  85. model.openId = self.wx_open_id;
  86. [AccountTool saveAccount:model];
  87. NSString *sex = [NSString stringWithFormat:@"%@",json[@"sex"]];
  88. [[NSUserDefaults standardUserDefaults] setObject:sex forKey:UserSexKey];
  89. [[NSUserDefaults standardUserDefaults] synchronize];
  90. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil];
  91. [self dismissViewControllerAnimated:NO completion:nil];
  92. }else {
  93. //绑定手机成功 去绑定邀请码
  94. [self dismissViewControllerAnimated:NO completion:^{
  95. LDLinkFansController *linkFnas = [[LDLinkFansController alloc] init];
  96. linkFnas.wx_union_id = self.wx_union_id;
  97. linkFnas.wx_open_id = self.wx_open_id;
  98. linkFnas.modalPresentationStyle = UIModalPresentationFullScreen;
  99. [[self currentViewController] presentViewController:linkFnas animated:YES completion:nil];
  100. }];
  101. }
  102. } failure:^(NSError *error) {
  103. [MBProgressHUD showMessage:@"加载失败,请稍后重试"];
  104. [SVProgressHUD dismiss];
  105. sender.enabled = YES;
  106. }];
  107. }
  108. - (UIViewController *)currentViewController{
  109. UIViewController * currVC = nil;
  110. UIWindow *window = [UIApplication sharedApplication].delegate.window;
  111. UIViewController * Rootvc = window.rootViewController;
  112. do {
  113. if ([Rootvc isKindOfClass:[UINavigationController class]]) {
  114. UINavigationController * nav = (UINavigationController *)Rootvc;
  115. UIViewController * v = [nav.viewControllers lastObject];
  116. currVC = v;
  117. Rootvc = v.presentedViewController;
  118. continue;
  119. }else if([Rootvc isKindOfClass:[UITabBarController class]]){
  120. UITabBarController * tabVC = (UITabBarController *)Rootvc;
  121. currVC = tabVC;
  122. Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
  123. continue;
  124. }
  125. } while (Rootvc!=nil);
  126. return currVC;
  127. }
  128. - (void)didReceiveMemoryWarning {
  129. [super didReceiveMemoryWarning];
  130. // Dispose of any resources that can be recreated.
  131. }
  132. /*
  133. #pragma mark - Navigation
  134. // In a storyboard-based application, you will often want to do a little preparation before navigation
  135. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  136. // Get the new view controller using [segue destinationViewController].
  137. // Pass the selected object to the new view controller.
  138. }
  139. */
  140. @end