// // KDPBindFastHandViewController.m // KuDianProject // // Created by admin on 2019/7/9. // Copyright © 2019 KDP. All rights reserved. // #import "KDPBindFastHandViewController.h" @interface KDPBindFastHandViewController () @property (nonatomic, strong) UITextField *textfield; @end @implementation KDPBindFastHandViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self setSubviews]; } - (void)setSubviews{ self.view.backgroundColor = [UIColor whiteColor]; self.navBar.hidden = YES; UILabel *kdtitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, Fitsize(83)+KDStatusHeight, SCREEN_WIDTH-32, 42)]; kdtitleLabel.font = [UIFont fontWithName:@"PingFangSC-Semibold" size: 30]; kdtitleLabel.textColor = [UIColor colorWithHex:0x333333]; kdtitleLabel.text = @"请输入您的快手号"; [self.view addSubview:kdtitleLabel]; UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, kdtitleLabel.bottom+Fitsize(10), SCREEN_WIDTH-32, 18)]; tipLabel.font = FONT_SYS(12); tipLabel.textColor = [UIColor colorWithHex:0x5d5d5d]; tipLabel.text = @"方便我们了解您,并为您精准推荐商品"; [self.view addSubview:tipLabel]; self.textfield = [[UITextField alloc] initWithFrame:CGRectMake(32, tipLabel.bottom+Fitsize(72), 150, 25)]; self.textfield.keyboardType = UIKeyboardTypeAlphabet; self.textfield.textColor = [UIColor colorWithHex:0x333333]; self.textfield.placeholder = @"请输入快手号"; self.textfield.font = FONT_SYS(16); [self.view addSubview:self.textfield]; UIButton *pastBtn = [UIButton buttonWithType:UIButtonTypeCustom]; pastBtn.frame = CGRectMake(SCREEN_WIDTH-25-32, self.textfield.top, 25, 17); pastBtn.centerY = self.textfield.centerY; [pastBtn setTitleColor:[UIColor baseColor] forState:UIControlStateNormal]; [pastBtn setTitle:@"粘贴" forState:UIControlStateNormal]; pastBtn.titleLabel.font = FONT_SYS(12); [pastBtn addTarget:self action:@selector(pastAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:pastBtn]; UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(32,self.textfield.bottom+Fitsize(12) , SCREEN_WIDTH-64, 1)]; lineView.backgroundColor = [UIColor colorWithHex:0xD1D1D1]; [self.view addSubview:lineView]; // UIButton *getfastHandBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // getfastHandBtn.frame = CGRectMake(SCREEN_WIDTH-32-100, lineView.bottom+Fitsize(17), 100, 18); // [getfastHandBtn setTitleColor:[UIColor colorWithHex:0x5D5D5D] forState:UIControlStateNormal]; // [getfastHandBtn setTitle:@"怎样获取快手号?" forState:UIControlStateNormal]; // getfastHandBtn.titleLabel.font = FONT_SYS(12); // [getfastHandBtn addTarget:self action:@selector(getFastHandAction) forControlEvents:UIControlEventTouchUpInside]; // [self.view addSubview:getfastHandBtn]; UIButton *finishBtn = [UIButton buttonWithType:UIButtonTypeCustom]; finishBtn.frame = CGRectMake(32, lineView.bottom+Fitsize(174), SCREEN_WIDTH-64, 48); [finishBtn setTitle:@"完成" forState:UIControlStateNormal]; finishBtn.layer.cornerRadius = 24; finishBtn.layer.masksToBounds = YES; [finishBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; finishBtn.titleLabel.font = FONT_SYS(17); [finishBtn setGradientBackgroundWithColors:@[[UIColor colorWithHex:0xFF7676],[UIColor colorWithHex:0xFF235F]] locations:@[@0,@1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)]; [finishBtn addTarget:self action:@selector(finishAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:finishBtn]; } - (void)pastAction:(UIButton *)sender{ UIPasteboard *defaultBoard = [UIPasteboard generalPasteboard]; NSString *boardString = defaultBoard.string; if (boardString.length > 0) { self.textfield.text = boardString; } } - (void)getFastHandInfo{ if ([KDPAccountTool isLogin]) { [LoadingView show]; NSString *fastHandUrl = [NSString stringWithFormat:@"%@api/users/getKuaiShouInfo",KDURL]; [KDPNetworkRequestHTTP postURL:fastHandUrl params:nil success:^(id _Nonnull json) { UIViewController *vc = self; while (vc.presentingViewController) { vc = vc.presentingViewController; } [vc dismissViewControllerAnimated:YES completion:nil]; [LoadingView dismiss]; KDPUserInfo * infoModel =[[KDPUserInfo alloc]init]; [infoModel setValuesForKeysWithDictionary:json[@"data"]]; KDPAccountModel *oldM =[KDPAccountTool account]; oldM.name = infoModel.kwai_username; oldM.img = infoModel.kwai_headurl; [KDPAccountTool saveAccount:oldM]; } failure:^(NSError * _Nonnull error) { [LoadingView dismiss]; }]; } } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; } - (void)finishAction:(UIButton *)sender{ if (self.textfield.text.length > 0) { NSString *url = [NSString stringWithFormat:@"%@api/users/updateKuaiShouNum",KDURL]; [LoadingView showInView:self.view]; [KDPNetworkRequestHTTP postURL:url params:@{@"kuaiShouNum":self.textfield.text} success:^(id _Nonnull json) { [LoadingView dismiss]; KDPAccountModel *model = [KDPAccountTool account]; model.has_kwai = @"1"; [KDPAccountTool saveAccount:model]; [self getFastHandInfo]; } failure:^(NSError * _Nonnull error) { }]; } else{ [LoadingView dismiss]; [MBProgressHUD showMessage:@"请填写快手号"]; } } @end