口袋优选

KBLinkFansController.m 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // KBLinkFansController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/21.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBLinkFansController.h"
  9. #import "SubLBXScanViewController.h"
  10. @interface KBLinkFansController (){
  11. UITextField *_codeField;
  12. UILabel *_desLabel;
  13. }
  14. @end
  15. @implementation KBLinkFansController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self configNavigationBar];
  19. [self configUI];
  20. [self loadDesText];
  21. }
  22. - (void)configNavigationBar {
  23. [self.navigationBar setNavTitle:@"输入邀请码"];
  24. self.navigationBar.backgroundColor = [UIColor changeColor];
  25. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  26. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  27. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  28. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  29. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  30. }
  31. - (void)backAction {
  32. [self dismissViewControllerAnimated:YES completion:nil];
  33. }
  34. - (void)loadDesText{
  35. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/serviceWechat",BaseURL];
  36. [KBHttp post:url params:nil success:^(id json) {
  37. _desLabel.text = json[@"wechat"];
  38. } failure:^(NSError *error) {
  39. }];
  40. }
  41. - (void)configUI {
  42. self.view.backgroundColor = [UIColor whiteColor];
  43. UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(Fitsize(35), Fitsize(176), 18, 14)];
  44. icon.image = [UIImage imageNamed:@"invite_left"];
  45. [self.view addSubview:icon];
  46. UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(icon.right+Fitsize(16), 0, Fitsize(205), 40)];
  47. textField.centerY = icon.centerY;
  48. textField.placeholder = @"输入邀请码";
  49. textField.font = [UIFont systemFontOfSize:14];
  50. textField.textColor = [UIColor YHColorWithHex:0x999999];
  51. _codeField = textField;
  52. [self.view addSubview:textField];
  53. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(Fitsize(35), icon.bottom+14, SCREEN_WIDTH-Fitsize(70), 1)];
  54. line.backgroundColor = [UIColor YHColorWithHex:0xD8D8D8];
  55. [self.view addSubview:line];
  56. UIButton *scanBtn = [[UIButton alloc] initWithFrame:CGRectMake(textField.right+Fitsize(16), 0, 30, 30)];
  57. [scanBtn addTarget:self action:@selector(scanAction) forControlEvents:UIControlEventTouchUpInside];
  58. [scanBtn setImage:[UIImage imageNamed:@"scan_icon"] forState:UIControlStateNormal];
  59. scanBtn.centerY = textField.centerY;
  60. scanBtn.hidden = YES;
  61. [self.view addSubview:scanBtn];
  62. UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(0,textField.bottom+Fitsize(97), Fitsize(257), Fitsize(37))];
  63. nextBtn.backgroundColor = [UIColor YHColorWithHex:0xd8d8d8];
  64. [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  65. [nextBtn setTitle:@"开始优选之旅" forState:UIControlStateNormal];
  66. nextBtn.centerX = SCREEN_WIDTH/2;
  67. nextBtn.layer.cornerRadius = nextBtn.height/2;
  68. nextBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  69. [nextBtn addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
  70. nextBtn.enabled = NO;
  71. [self.view addSubview:nextBtn];
  72. UILabel *des = [[UILabel alloc] initWithFrame:CGRectMake(10, nextBtn.bottom+10, SCREEN_WIDTH-20, 40)];
  73. des.textColor = [UIColor YHColorWithHex:0x999999];
  74. des.font = [UIFont systemFontOfSize:13];
  75. des.textAlignment = NSTextAlignmentCenter;
  76. des.numberOfLines = 0;
  77. _desLabel = des;
  78. [self.view addSubview:des];
  79. RACSignal *textSingal = [textField.rac_textSignal map:^id(NSString * value) {
  80. return @(value.length > 0);
  81. }];
  82. [textSingal subscribeNext:^(NSNumber *textActionSignal) {
  83. nextBtn.enabled = [textActionSignal boolValue];
  84. nextBtn.backgroundColor = [textActionSignal boolValue] ? [UIColor changeColor] : [UIColor YHColorWithHex:0xd8d8d8];
  85. }];
  86. }
  87. - (void)closeAction {
  88. [self.navigationController popViewControllerAnimated:YES];
  89. }
  90. /**
  91. 完成
  92. */
  93. - (void)nextAction:(UIButton *)sender {
  94. NSString *codeStr = _codeField.text;
  95. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/bindingInvitationCode",BaseURL];
  96. NSDictionary *para = @{@"code":codeStr,
  97. @"unionid":(self.wx_union_id==nil?@"":self.wx_union_id)
  98. };
  99. [KBHttp post:url params:para success:^(id json) {
  100. NSDictionary *dict = json[@"data"];
  101. if ([dict[@"flag"] boolValue]) {
  102. AccountModel *model = [AccountModel yy_modelWithJSON:dict];
  103. [AccountTool saveAccount:model];
  104. NSString *sex = [NSString stringWithFormat:@"%@",dict[@"sex"]];
  105. [[NSUserDefaults standardUserDefaults] setObject:sex forKey:UserSexKey];
  106. [[NSUserDefaults standardUserDefaults] synchronize];
  107. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil];
  108. if (self.linkFansBlock) {
  109. self.linkFansBlock();
  110. }
  111. [self dismissViewControllerAnimated:YES completion:nil];
  112. }
  113. [MBProgressHUD showMessage:dict[@"info"]];
  114. } failure:^(NSError *error) {
  115. [MBProgressHUD showMessage:@"加载失败,请稍后重试"];
  116. }];
  117. }
  118. /**
  119. 扫描
  120. */
  121. - (void)scanAction {
  122. SubLBXScanViewController *scan = [[SubLBXScanViewController alloc] init];
  123. [self presentViewController:scan animated:YES completion:nil];
  124. }
  125. - (void)didReceiveMemoryWarning {
  126. [super didReceiveMemoryWarning];
  127. // Dispose of any resources that can be recreated.
  128. }
  129. /*
  130. #pragma mark - Navigation
  131. // In a storyboard-based application, you will often want to do a little preparation before navigation
  132. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  133. // Get the new view controller using [segue destinationViewController].
  134. // Pass the selected object to the new view controller.
  135. }
  136. */
  137. @end