省钱达人

DRLinkFansController.m 5.8KB

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