123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- //
- // KBLinkPhoneController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/21.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBLinkPhoneController.h"
- #import "KBPhoneFieldView.h"
- #import "KBLoginRequest.h"
- #import "KBLinkFansController.h"
- @interface KBLinkPhoneController ()
- {
- KBPhoneFieldView *_phoneFieldView;
- }
- @end
- @implementation KBLinkPhoneController
- - (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];
-
- KBPhoneFieldView *fieldView = [[KBPhoneFieldView 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 {
- NSString *phone = [_phoneFieldView getPhoneText];
- NSString *code = [_phoneFieldView getCodeText];
- NSDictionary *para = @{@"phone":phone,
- @"code":code,
- @"union_id":self.wx_union_id};
-
- [SVProgressHUD show];
- [KBLoginRequest post:ValidLoginAPI params:para success:^(id json) {
-
-
- //手机号绑定成功,登录成功
- AccountModel *model = [AccountModel yy_modelWithJSON:json];
- model.openId = self.wx_open_id;
- model.unionid = self.wx_union_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];
- [SVProgressHUD dismiss];
-
- } failure:^(NSError *error) {
- [SVProgressHUD dismiss];
- [MBProgressHUD showMessage:@"加载失败,请稍后重试"];
- }];
- }
- - (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
|