123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- //
- // LDLinkFansController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/21.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDLinkFansController.h"
- #import "SubLBXScanViewController.h"
- #import "LDPushToWeixViewController.h"
- @interface LDLinkFansController (){
- UITextField *_codeField;
- UILabel *_desLabel;
-
- UIView *backView;
- UIImageView *iconImg;
- UILabel *titleLabel;
- UILabel *tipeLabel;
- }
- @end
- @implementation LDLinkFansController
- - (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];
- [LDHttp 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];
- //监听textfield的输入状态
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(textFieldDidChangeValue:)
- name:UITextFieldTextDidChangeNotification
- object:textField];
- _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];
-
-
- backView =[[UIView alloc]initWithFrame:CGRectMake(FITSIZE(35), textField.bottom+FITSIZE(30), SCREEN_WIDTH-FITSIZE(70), FITSIZE(82))];
- [self.view addSubview:backView];
- backView.layer.cornerRadius=5;
- backView.layer.masksToBounds=YES;
- backView.layer.borderWidth=0.5;
- backView.layer.borderColor=[UIColor YHColorWithHex:0xF76B6E].CGColor;
- backView.hidden=YES;
-
- iconImg =[[UIImageView alloc]initWithFrame:CGRectMake(FITSIZE(37), FITSIZE(16), FITSIZE(50), FITSIZE(50))];
- iconImg.layer.cornerRadius=FITSIZE(25);
- iconImg.layer.masksToBounds=YES;
- iconImg.backgroundColor =[UIColor yhGrayColor];
- [backView addSubview:iconImg];
-
- titleLabel =[[UILabel alloc]initWithFrame:CGRectMake(iconImg.right+FITSIZE(20), FITSIZE(20), FITSIZE(200), FITSIZE(15))];
- titleLabel.textColor=[UIColor YHColorWithHex:0x000000];
- titleLabel.font =[UIFont systemFontOfSize:FITSIZE(16)];
- [backView addSubview:titleLabel];
-
- tipeLabel =[[UILabel alloc]initWithFrame:CGRectMake(iconImg.right+FITSIZE(20), titleLabel.bottom+FITSIZE(10), FITSIZE(200), FITSIZE(15))];
- tipeLabel.textColor=[UIColor YHColorWithHex:0x000000];
- tipeLabel.font =[UIFont systemFontOfSize:FITSIZE(14)];
- [backView addSubview:tipeLabel];
-
-
-
-
-
- UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(0,textField.bottom+Fitsize(200), 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.text = @"没有邀请码?添加微信客服“ldyx2hao”获取";
- 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];
- }
- //监听
- //这里可以通过发送object消息获取注册时指定的UITextField对象
- - (void)textFieldDidChangeValue:(NSNotification *)notification
- {
- if (_codeField.text.length !=0) {
- NSString *url =[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/findInvitationCode",BaseURL];
- [LDHttp post:url params:@{@"code":_codeField.text} success:^(id json) {
- backView.hidden=YES;
- if ([json[@"isFindInvitationCode"] boolValue]) {
- backView.hidden=NO;
- [iconImg sd_setImageWithURL:[NSURL URLWithString:json[@"headimgurl"]]];
- titleLabel.text=json[@"nickname"];
- tipeLabel.text=json[@"text"];
- }
- } failure:^(NSError *error) {
- [MBProgressHUD showMessage:@"加载失败,请稍后重试"];
- }];
- }
- }
- -(void)requestCode
- {
-
- }
- /**
- 完成
- */
- - (void)nextAction:(UIButton *)sender {
- sender.enabled = NO;
- NSString *codeStr = _codeField.text;
- [SVProgressHUD show];
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/bindingInvitationCode",BaseURL];
- NSDictionary *para = @{@"code":codeStr,
- @"unionid":(self.wx_union_id==nil?@"":self.wx_union_id)
- };
- if (self.user_id.length > 0 ) {//手机号登录绑定邀请码
- url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/mbindingInvitationCode",BaseURL];
- para = @{@"code":codeStr,
- @"user_id":(self.user_id==nil?@"":self.user_id)
- };
-
- }
- [LDHttp post:url params:para success:^(id json) {
- sender.enabled = YES;
- [SVProgressHUD dismiss];
- 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:NO completion:^{
- LDPushToWeixViewController *vc = [[LDPushToWeixViewController alloc] init];
- vc.modalPresentationStyle = UIModalPresentationFullScreen;
- [[self currentViewController] presentViewController:vc animated:YES completion:nil];
- }];
-
-
-
- }
- [MBProgressHUD showMessage:dict[@"info"]];
-
-
- } failure:^(NSError *error) {
- [MBProgressHUD showMessage:@"加载失败,请稍后重试"];
- [SVProgressHUD dismiss];
- sender.enabled = YES;
- }];
- }
- /**
- 扫描
- */
- - (void)scanAction {
- SubLBXScanViewController *scan = [[SubLBXScanViewController alloc] init];
- scan.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:scan animated:YES completion:nil];
- }
- - (UIViewController *)currentViewController{
-
- UIViewController * currVC = nil;
- UIWindow *window = [UIApplication sharedApplication].delegate.window;
- UIViewController * Rootvc = window.rootViewController;
-
- do {
- if ([Rootvc isKindOfClass:[UINavigationController class]]) {
- UINavigationController * nav = (UINavigationController *)Rootvc;
- UIViewController * v = [nav.viewControllers lastObject];
- currVC = v;
- Rootvc = v.presentedViewController;
- continue;
- }else if([Rootvc isKindOfClass:[UITabBarController class]]){
- UITabBarController * tabVC = (UITabBarController *)Rootvc;
- currVC = tabVC;
- Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
- continue;
- }
- } while (Rootvc!=nil);
-
- return currVC;
- }
- - (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
|