《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRLinkPhoneController.m 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // DRLinkPhoneController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/21.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRLinkPhoneController.h"
  9. #import "DRPhoneFieldView.h"
  10. #import "DRLoginRequest.h"
  11. #import "DRLinkFansController.h"
  12. #import "DRPushToWeixViewController.h"
  13. @interface DRLinkPhoneController ()
  14. {
  15. DRPhoneFieldView *_phoneFieldView;
  16. }
  17. @end
  18. @implementation DRLinkPhoneController
  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. DRPhoneFieldView *fieldView = [[DRPhoneFieldView 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. NSString *url = [NSString stringWithFormat:@"%@%@",BaseURL,@"/api/v2/users/loginCodeNew"];
  78. [DRLoginRequest post:url params:para success:^(id json) {
  79. [SVProgressHUD dismiss];
  80. sender.enabled = YES;
  81. //手机号绑定成功,登录成功
  82. AccountModel *model = [AccountModel yy_modelWithJSON:json];
  83. model.openId = self.wx_open_id;
  84. model.unionid = self.wx_union_id;
  85. [AccountTool saveAccount:model];
  86. NSString *sex = [NSString stringWithFormat:@"%@",json[@"sex"]];
  87. [[NSUserDefaults standardUserDefaults] setObject:sex forKey:UserSexKey];
  88. [[NSUserDefaults standardUserDefaults] synchronize];
  89. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil];
  90. [self dismissViewControllerAnimated:NO completion:nil];
  91. [SVProgressHUD dismiss];
  92. } failure:^(NSError *error) {
  93. if (error) {
  94. [MBProgressHUD showMessage:@"加载失败,请稍后重试"];
  95. [SVProgressHUD dismiss];
  96. sender.enabled = YES;
  97. }
  98. }];
  99. }
  100. - (UIViewController *)currentViewController{
  101. UIViewController * currVC = nil;
  102. UIWindow *window = [UIApplication sharedApplication].delegate.window;
  103. UIViewController * Rootvc = window.rootViewController;
  104. do {
  105. if ([Rootvc isKindOfClass:[UINavigationController class]]) {
  106. UINavigationController * nav = (UINavigationController *)Rootvc;
  107. UIViewController * v = [nav.viewControllers lastObject];
  108. currVC = v;
  109. Rootvc = v.presentedViewController;
  110. continue;
  111. }else if([Rootvc isKindOfClass:[UITabBarController class]]){
  112. UITabBarController * tabVC = (UITabBarController *)Rootvc;
  113. currVC = tabVC;
  114. Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
  115. continue;
  116. }
  117. } while (Rootvc!=nil);
  118. return currVC;
  119. }
  120. - (void)didReceiveMemoryWarning {
  121. [super didReceiveMemoryWarning];
  122. // Dispose of any resources that can be recreated.
  123. }
  124. /*
  125. #pragma mark - Navigation
  126. // In a storyboard-based application, you will often want to do a little preparation before navigation
  127. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  128. // Get the new view controller using [segue destinationViewController].
  129. // Pass the selected object to the new view controller.
  130. }
  131. */
  132. @end