酷店

KDPBindFastHandViewController.m 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // KDPBindFastHandViewController.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/9.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPBindFastHandViewController.h"
  9. @interface KDPBindFastHandViewController ()
  10. @property (nonatomic, strong) UITextField *textfield;
  11. @end
  12. @implementation KDPBindFastHandViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. // Do any additional setup after loading the view.
  16. [self setSubviews];
  17. }
  18. - (void)setSubviews{
  19. self.navBar.hidden = YES;
  20. UILabel *kdtitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, Fitsize(83)+KDStatusHeight, SCREEN_WIDTH-32, 42)];
  21. kdtitleLabel.font = [UIFont fontWithName:@"PingFangSC-Semibold" size: 30];
  22. kdtitleLabel.textColor = [UIColor colorWithHex:0x333333];
  23. kdtitleLabel.text = @"请输入您的快手号";
  24. [self.view addSubview:kdtitleLabel];
  25. UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, kdtitleLabel.bottom+Fitsize(10), SCREEN_WIDTH-32, 18)];
  26. tipLabel.font = FONT_SYS(12);
  27. tipLabel.textColor = [UIColor colorWithHex:0x5d5d5d];
  28. tipLabel.text = @"方便我们了解您,并为您精准推荐商品";
  29. [self.view addSubview:tipLabel];
  30. self.textfield = [[UITextField alloc] initWithFrame:CGRectMake(32, tipLabel.bottom+Fitsize(72), 150, 25)];
  31. self.textfield.keyboardType = UIKeyboardTypeAlphabet;
  32. self.textfield.textColor = [UIColor colorWithHex:0x333333];
  33. self.textfield.placeholder = @"请输入快手号";
  34. self.textfield.font = FONT_SYS(16);
  35. [self.view addSubview:self.textfield];
  36. UIButton *pastBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  37. pastBtn.frame = CGRectMake(SCREEN_WIDTH-25-32, self.textfield.top, 25, 17);
  38. pastBtn.centerY = self.textfield.centerY;
  39. [pastBtn setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
  40. [pastBtn setTitle:@"粘贴" forState:UIControlStateNormal];
  41. pastBtn.titleLabel.font = FONT_SYS(12);
  42. [pastBtn addTarget:self action:@selector(pastAction:) forControlEvents:UIControlEventTouchUpInside];
  43. [self.view addSubview:pastBtn];
  44. UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(32,self.textfield.bottom+Fitsize(12) , SCREEN_WIDTH-64, 1)];
  45. lineView.backgroundColor = [UIColor colorWithHex:0xD1D1D1];
  46. [self.view addSubview:lineView];
  47. // UIButton *getfastHandBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  48. // getfastHandBtn.frame = CGRectMake(SCREEN_WIDTH-32-100, lineView.bottom+Fitsize(17), 100, 18);
  49. // [getfastHandBtn setTitleColor:[UIColor colorWithHex:0x5D5D5D] forState:UIControlStateNormal];
  50. // [getfastHandBtn setTitle:@"怎样获取快手号?" forState:UIControlStateNormal];
  51. // getfastHandBtn.titleLabel.font = FONT_SYS(12);
  52. // [getfastHandBtn addTarget:self action:@selector(getFastHandAction) forControlEvents:UIControlEventTouchUpInside];
  53. // [self.view addSubview:getfastHandBtn];
  54. UIButton *finishBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  55. finishBtn.frame = CGRectMake(32, lineView.bottom+Fitsize(174), SCREEN_WIDTH-64, 48);
  56. [finishBtn setTitle:@"完成" forState:UIControlStateNormal];
  57. finishBtn.layer.cornerRadius = 24;
  58. finishBtn.layer.masksToBounds = YES;
  59. [finishBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  60. finishBtn.titleLabel.font = FONT_SYS(17);
  61. [finishBtn setGradientBackgroundWithColors:@[[UIColor colorWithHex:0xFF7676],[UIColor colorWithHex:0xFF235F]] locations:@[@0,@1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
  62. [finishBtn addTarget:self action:@selector(finishAction:) forControlEvents:UIControlEventTouchUpInside];
  63. [self.view addSubview:finishBtn];
  64. }
  65. - (void)pastAction:(UIButton *)sender{
  66. UIPasteboard *defaultBoard = [UIPasteboard generalPasteboard];
  67. NSString *boardString = defaultBoard.string;
  68. if (boardString.length > 0) {
  69. self.textfield.text = boardString;
  70. }
  71. }
  72. - (void)getFastHandInfo{
  73. if ([KDPAccountTool isLogin]) {
  74. [LoadingView show];
  75. NSString *fastHandUrl = [NSString stringWithFormat:@"%@api/users/getKuaiShouInfo",KDURL];
  76. [KDPNetworkRequestHTTP postURL:fastHandUrl params:nil success:^(id _Nonnull json) {
  77. UIViewController *vc = self;
  78. while (vc.presentingViewController) {
  79. vc = vc.presentingViewController;
  80. }
  81. [vc dismissViewControllerAnimated:YES completion:nil];
  82. [LoadingView dismiss];
  83. KDPUserInfo * infoModel =[[KDPUserInfo alloc]init];
  84. [infoModel setValuesForKeysWithDictionary:json[@"data"]];
  85. KDPAccountModel *oldM =[KDPAccountTool account];
  86. oldM.name = infoModel.kwai_username;
  87. oldM.img = infoModel.kwai_headurl;
  88. [KDPAccountTool saveAccount:oldM];
  89. } failure:^(NSError * _Nonnull error) {
  90. [LoadingView dismiss];
  91. }];
  92. }
  93. }
  94. - (void)viewWillAppear:(BOOL)animated{
  95. [super viewWillAppear:animated];
  96. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
  97. }
  98. - (void)viewWillDisappear:(BOOL)animated{
  99. [super viewWillDisappear:animated];
  100. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  101. }
  102. - (void)finishAction:(UIButton *)sender{
  103. if (self.textfield.text.length > 0) {
  104. NSString *url = [NSString stringWithFormat:@"%@api/users/updateKuaiShouNum",KDURL];
  105. [LoadingView showInView:self.view];
  106. [KDPNetworkRequestHTTP postURL:url params:@{@"kuaiShouNum":self.textfield.text} success:^(id _Nonnull json) {
  107. [LoadingView dismiss];
  108. KDPAccountModel *model = [KDPAccountTool account];
  109. model.has_kwai = @"1";
  110. [KDPAccountTool saveAccount:model];
  111. [self getFastHandInfo];
  112. } failure:^(NSError * _Nonnull error) {
  113. }];
  114. } else{
  115. [LoadingView dismiss];
  116. [MBProgressHUD showMessage:@"请填写快手号"];
  117. }
  118. }
  119. @end