酷店

KDPBindFastHandViewController.m 6.0KB

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