省钱达人

DRLinkPhoneController.m 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. @interface DRLinkPhoneController ()
  13. {
  14. DRPhoneFieldView *_phoneFieldView;
  15. }
  16. @end
  17. @implementation DRLinkPhoneController
  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. DRPhoneFieldView *fieldView = [[DRPhoneFieldView 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. [DRLoginRequest post:ValidLoginAPI params:para success:^(id json) {
  76. //手机号绑定成功,登录成功
  77. AccountModel *model = [AccountModel yy_modelWithJSON:json];
  78. [AccountTool saveAccount:model];
  79. NSString *sex = [NSString stringWithFormat:@"%@",json[@"sex"]];
  80. [[NSUserDefaults standardUserDefaults] setObject:sex forKey:UserSexKey];
  81. [[NSUserDefaults standardUserDefaults] synchronize];
  82. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil];
  83. [self dismissViewControllerAnimated:YES completion:nil];
  84. [SVProgressHUD dismiss];
  85. } failure:^(NSError *error) {
  86. [SVProgressHUD dismiss];
  87. [MBProgressHUD showMessage:@"加载失败,请稍后重试"];
  88. }];
  89. }
  90. - (void)didReceiveMemoryWarning {
  91. [super didReceiveMemoryWarning];
  92. // Dispose of any resources that can be recreated.
  93. }
  94. /*
  95. #pragma mark - Navigation
  96. // In a storyboard-based application, you will often want to do a little preparation before navigation
  97. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  98. // Get the new view controller using [segue destinationViewController].
  99. // Pass the selected object to the new view controller.
  100. }
  101. */
  102. @end