口袋优选

KBLinkPhoneController.m 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // KBLinkPhoneController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/21.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBLinkPhoneController.h"
  9. #import "KBPhoneFieldView.h"
  10. #import "KBLoginRequest.h"
  11. #import "KBLinkFansController.h"
  12. @interface KBLinkPhoneController ()
  13. {
  14. KBPhoneFieldView *_phoneFieldView;
  15. }
  16. @end
  17. @implementation KBLinkPhoneController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self configNavigationBar];
  21. [self configUI];
  22. }
  23. - (void)configNavigationBar {
  24. [self.navigationBar setNavTitle:@"绑定手机号"];
  25. self.navigationBar.backgroundColor = [UIColor changeColor];
  26. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  27. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  28. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  29. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  30. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  31. }
  32. - (void)backAction {
  33. [self dismissViewControllerAnimated:YES completion:nil];
  34. }
  35. - (void)configUI {
  36. self.view.backgroundColor = [UIColor whiteColor];
  37. // UIButton *closeButton = [[UIButton alloc] initWithFrame:CGRectMake(20, 25, 30, 30)];
  38. // [closeButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
  39. // [closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  40. // [self.view addSubview:closeButton];
  41. //
  42. // UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, Fitsize(91), SCREEN_WIDTH-20, 28)];
  43. // title.font = [UIFont boldSystemFontOfSize:Fitsize(20)];
  44. // title.textAlignment = NSTextAlignmentCenter;
  45. // title.textColor = [UIColor YHColorWithHex:0x333333];
  46. // title.text = @"为了您的账户安全,请绑定手机号";
  47. // [self.view addSubview:title];
  48. KBPhoneFieldView *fieldView = [[KBPhoneFieldView alloc] initWithFrame:CGRectMake(0, NavBarHeight+Fitsize(100), SCREEN_WIDTH, 100) wx_union_id:self.wx_union_id];
  49. [self.view addSubview:fieldView];
  50. _phoneFieldView = fieldView;
  51. UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, fieldView.bottom+Fitsize(60), Fitsize(189), Fitsize(40))];
  52. nextBtn.backgroundColor = [UIColor YHColorWithHex:0xd8d8d8];
  53. [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  54. [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
  55. nextBtn.centerX = SCREEN_WIDTH/2;
  56. nextBtn.layer.cornerRadius = nextBtn.height/2;
  57. [nextBtn addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
  58. nextBtn.enabled = NO;
  59. [self.view addSubview:nextBtn];
  60. fieldView.nextEnable = ^(BOOL nextEnable) {
  61. nextBtn.enabled = nextEnable;
  62. nextBtn.backgroundColor = nextEnable ? [UIColor changeColor] : [UIColor YHColorWithHex:0xd8d8d8];
  63. };
  64. }
  65. - (void)closeAction {
  66. [self dismissViewControllerAnimated:YES completion:nil];
  67. }
  68. - (void)nextAction:(UIButton *)sender {
  69. NSString *phone = [_phoneFieldView getPhoneText];
  70. NSString *code = [_phoneFieldView getCodeText];
  71. NSDictionary *para = @{@"phone":phone,
  72. @"code":code,
  73. @"union_id":self.wx_union_id};
  74. [SVProgressHUD show];
  75. [KBLoginRequest post:ValidLoginAPI params:para success:^(id json) {
  76. //手机号绑定成功,登录成功
  77. AccountModel *model = [AccountModel yy_modelWithJSON:json];
  78. model.openId = self.wx_open_id;
  79. model.unionid = self.wx_union_id;
  80. [AccountTool saveAccount:model];
  81. NSString *sex = [NSString stringWithFormat:@"%@",json[@"sex"]];
  82. [[NSUserDefaults standardUserDefaults] setObject:sex forKey:UserSexKey];
  83. [[NSUserDefaults standardUserDefaults] synchronize];
  84. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil];
  85. [self dismissViewControllerAnimated:NO completion:nil];
  86. [SVProgressHUD dismiss];
  87. } failure:^(NSError *error) {
  88. [SVProgressHUD dismiss];
  89. [MBProgressHUD showMessage:@"加载失败,请稍后重试"];
  90. }];
  91. }
  92. - (void)didReceiveMemoryWarning {
  93. [super didReceiveMemoryWarning];
  94. // Dispose of any resources that can be recreated.
  95. }
  96. /*
  97. #pragma mark - Navigation
  98. // In a storyboard-based application, you will often want to do a little preparation before navigation
  99. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  100. // Get the new view controller using [segue destinationViewController].
  101. // Pass the selected object to the new view controller.
  102. }
  103. */
  104. @end