// // KBLinkFansController.m // YouHuiProject // // Created by 小花 on 2018/5/21. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBLinkFansController.h" #import "SubLBXScanViewController.h" @interface KBLinkFansController (){ UITextField *_codeField; UILabel *_desLabel; } @end @implementation KBLinkFansController - (void)viewDidLoad { [super viewDidLoad]; [self configNavigationBar]; [self configUI]; [self loadDesText]; } - (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)loadDesText{ NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/serviceWechat",BaseURL]; [KBHttp post:url params:nil success:^(id json) { _desLabel.text = json[@"wechat"]; } failure:^(NSError *error) { }]; } - (void)configUI { self.view.backgroundColor = [UIColor whiteColor]; UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(Fitsize(35), Fitsize(176), 18, 14)]; icon.image = [UIImage imageNamed:@"invite_left"]; [self.view addSubview:icon]; UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(icon.right+Fitsize(16), 0, Fitsize(205), 40)]; textField.centerY = icon.centerY; textField.placeholder = @"输入邀请码"; textField.font = [UIFont systemFontOfSize:14]; textField.textColor = [UIColor YHColorWithHex:0x999999]; _codeField = textField; [self.view addSubview:textField]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(Fitsize(35), icon.bottom+14, SCREEN_WIDTH-Fitsize(70), 1)]; line.backgroundColor = [UIColor YHColorWithHex:0xD8D8D8]; [self.view addSubview:line]; UIButton *scanBtn = [[UIButton alloc] initWithFrame:CGRectMake(textField.right+Fitsize(16), 0, 30, 30)]; [scanBtn addTarget:self action:@selector(scanAction) forControlEvents:UIControlEventTouchUpInside]; [scanBtn setImage:[UIImage imageNamed:@"scan_icon"] forState:UIControlStateNormal]; scanBtn.centerY = textField.centerY; scanBtn.hidden = YES; [self.view addSubview:scanBtn]; UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(0,textField.bottom+Fitsize(97), Fitsize(257), Fitsize(37))]; 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.titleLabel.font = [UIFont systemFontOfSize:14]; [nextBtn addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside]; nextBtn.enabled = NO; [self.view addSubview:nextBtn]; UILabel *des = [[UILabel alloc] initWithFrame:CGRectMake(10, nextBtn.bottom+10, SCREEN_WIDTH-20, 40)]; des.textColor = [UIColor YHColorWithHex:0x999999]; des.font = [UIFont systemFontOfSize:13]; des.textAlignment = NSTextAlignmentCenter; des.numberOfLines = 0; _desLabel = des; [self.view addSubview:des]; RACSignal *textSingal = [textField.rac_textSignal map:^id(NSString * value) { return @(value.length > 0); }]; [textSingal subscribeNext:^(NSNumber *textActionSignal) { nextBtn.enabled = [textActionSignal boolValue]; nextBtn.backgroundColor = [textActionSignal boolValue] ? [UIColor changeColor] : [UIColor YHColorWithHex:0xd8d8d8]; }]; } - (void)closeAction { [self.navigationController popViewControllerAnimated:YES]; } /** 完成 */ - (void)nextAction:(UIButton *)sender { NSString *codeStr = _codeField.text; NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/bindingInvitationCode",BaseURL]; NSDictionary *para = @{@"code":codeStr, @"unionid":(self.wx_union_id==nil?@"":self.wx_union_id) }; [KBHttp post:url params:para success:^(id json) { NSDictionary *dict = json[@"data"]; if ([dict[@"flag"] boolValue]) { AccountModel *model = [AccountModel yy_modelWithJSON:dict]; [AccountTool saveAccount:model]; NSString *sex = [NSString stringWithFormat:@"%@",dict[@"sex"]]; [[NSUserDefaults standardUserDefaults] setObject:sex forKey:UserSexKey]; [[NSUserDefaults standardUserDefaults] synchronize]; [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil]; if (self.linkFansBlock) { self.linkFansBlock(); } [self dismissViewControllerAnimated:YES completion:nil]; } [MBProgressHUD showMessage:dict[@"info"]]; } failure:^(NSError *error) { [MBProgressHUD showMessage:@"加载失败,请稍后重试"]; }]; } /** 扫描 */ - (void)scanAction { SubLBXScanViewController *scan = [[SubLBXScanViewController alloc] init]; [self presentViewController:scan animated:YES completion:nil]; } - (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