猎豆优选

LDLinkFansController.m 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. //
  2. // LDLinkFansController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/21.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDLinkFansController.h"
  9. #import "SubLBXScanViewController.h"
  10. #import "LDPushToWeixViewController.h"
  11. @interface LDLinkFansController (){
  12. UITextField *_codeField;
  13. UILabel *_desLabel;
  14. UIView *backView;
  15. UIImageView *iconImg;
  16. UILabel *titleLabel;
  17. UILabel *tipeLabel;
  18. }
  19. @end
  20. @implementation LDLinkFansController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self configNavigationBar];
  24. [self configUI];
  25. [self loadDesText];
  26. }
  27. - (void)configNavigationBar {
  28. [self.navigationBar setNavTitle:@"输入邀请码"];
  29. self.navigationBar.backgroundColor = [UIColor changeColor];
  30. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  31. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  32. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  33. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  34. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  35. }
  36. - (void)backAction {
  37. [self dismissViewControllerAnimated:YES completion:nil];
  38. }
  39. - (void)loadDesText{
  40. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/serviceWechat",BaseURL];
  41. [LDHttp post:url params:nil success:^(id json) {
  42. _desLabel.text = json[@"wechat"];
  43. } failure:^(NSError *error) {
  44. }];
  45. }
  46. - (void)configUI {
  47. self.view.backgroundColor = [UIColor whiteColor];
  48. UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(Fitsize(35), Fitsize(176), 18, 14)];
  49. icon.image = [UIImage imageNamed:@"invite_left"];
  50. [self.view addSubview:icon];
  51. UITextField * textField = [[UITextField alloc] initWithFrame:CGRectMake(icon.right+Fitsize(16), 0, Fitsize(205), 40)];
  52. textField.centerY = icon.centerY;
  53. textField.placeholder = @"请输入邀请码或邀请人手机号";
  54. textField.font = [UIFont systemFontOfSize:14];
  55. textField.textColor = [UIColor YHColorWithHex:0x999999];
  56. //监听textfield的输入状态
  57. [[NSNotificationCenter defaultCenter] addObserver:self
  58. selector:@selector(textFieldDidChangeValue:)
  59. name:UITextFieldTextDidChangeNotification
  60. object:textField];
  61. _codeField = textField;
  62. [self.view addSubview:textField];
  63. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(Fitsize(35), icon.bottom+14, SCREEN_WIDTH-Fitsize(70), 1)];
  64. line.backgroundColor = [UIColor YHColorWithHex:0xD8D8D8];
  65. [self.view addSubview:line];
  66. UIButton *scanBtn = [[UIButton alloc] initWithFrame:CGRectMake(textField.right+Fitsize(16), 0, 30, 30)];
  67. [scanBtn addTarget:self action:@selector(scanAction) forControlEvents:UIControlEventTouchUpInside];
  68. [scanBtn setImage:[UIImage imageNamed:@"scan_icon"] forState:UIControlStateNormal];
  69. scanBtn.centerY = textField.centerY;
  70. scanBtn.hidden = YES;
  71. [self.view addSubview:scanBtn];
  72. backView =[[UIView alloc]initWithFrame:CGRectMake(FITSIZE(35), textField.bottom+FITSIZE(30), SCREEN_WIDTH-FITSIZE(70), FITSIZE(82))];
  73. [self.view addSubview:backView];
  74. backView.layer.cornerRadius=5;
  75. backView.layer.masksToBounds=YES;
  76. backView.layer.borderWidth=0.5;
  77. backView.layer.borderColor=[UIColor YHColorWithHex:0xF76B6E].CGColor;
  78. backView.hidden=YES;
  79. iconImg =[[UIImageView alloc]initWithFrame:CGRectMake(FITSIZE(37), FITSIZE(16), FITSIZE(50), FITSIZE(50))];
  80. iconImg.layer.cornerRadius=FITSIZE(25);
  81. iconImg.layer.masksToBounds=YES;
  82. iconImg.backgroundColor =[UIColor yhGrayColor];
  83. [backView addSubview:iconImg];
  84. titleLabel =[[UILabel alloc]initWithFrame:CGRectMake(iconImg.right+FITSIZE(20), FITSIZE(20), FITSIZE(200), FITSIZE(15))];
  85. titleLabel.textColor=[UIColor YHColorWithHex:0x000000];
  86. titleLabel.font =[UIFont systemFontOfSize:FITSIZE(16)];
  87. [backView addSubview:titleLabel];
  88. tipeLabel =[[UILabel alloc]initWithFrame:CGRectMake(iconImg.right+FITSIZE(20), titleLabel.bottom+FITSIZE(10), FITSIZE(200), FITSIZE(15))];
  89. tipeLabel.textColor=[UIColor YHColorWithHex:0x000000];
  90. tipeLabel.font =[UIFont systemFontOfSize:FITSIZE(14)];
  91. [backView addSubview:tipeLabel];
  92. UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(0,textField.bottom+Fitsize(200), Fitsize(257), Fitsize(37))];
  93. nextBtn.backgroundColor = [UIColor YHColorWithHex:0xd8d8d8];
  94. [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  95. [nextBtn setTitle:@"开始优选之旅" forState:UIControlStateNormal];
  96. nextBtn.centerX = SCREEN_WIDTH/2;
  97. nextBtn.layer.cornerRadius = nextBtn.height/2;
  98. nextBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  99. [nextBtn addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
  100. nextBtn.enabled = NO;
  101. [self.view addSubview:nextBtn];
  102. UILabel *des = [[UILabel alloc] initWithFrame:CGRectMake(10, nextBtn.bottom+10, SCREEN_WIDTH-20, 40)];
  103. des.textColor = [UIColor YHColorWithHex:0x999999];
  104. des.font = [UIFont systemFontOfSize:13];
  105. // des.text = @"没有邀请码?添加微信客服“ldyx2hao”获取";
  106. des.textAlignment = NSTextAlignmentCenter;
  107. des.numberOfLines = 0;
  108. _desLabel = des;
  109. [self.view addSubview:des];
  110. RACSignal *textSingal = [textField.rac_textSignal map:^id(NSString * value) {
  111. return @(value.length > 0);
  112. }];
  113. [textSingal subscribeNext:^(NSNumber *textActionSignal) {
  114. nextBtn.enabled = [textActionSignal boolValue];
  115. nextBtn.backgroundColor = [textActionSignal boolValue] ? [UIColor changeColor] : [UIColor YHColorWithHex:0xd8d8d8];
  116. }];
  117. }
  118. - (void)closeAction {
  119. [self.navigationController popViewControllerAnimated:YES];
  120. }
  121. //监听
  122. //这里可以通过发送object消息获取注册时指定的UITextField对象
  123. - (void)textFieldDidChangeValue:(NSNotification *)notification
  124. {
  125. if (_codeField.text.length !=0) {
  126. NSString *url =[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/findInvitationCode",BaseURL];
  127. [LDHttp post:url params:@{@"code":_codeField.text} success:^(id json) {
  128. backView.hidden=YES;
  129. if ([json[@"isFindInvitationCode"] boolValue]) {
  130. backView.hidden=NO;
  131. [iconImg sd_setImageWithURL:[NSURL URLWithString:json[@"headimgurl"]]];
  132. titleLabel.text=json[@"nickname"];
  133. tipeLabel.text=json[@"text"];
  134. }
  135. } failure:^(NSError *error) {
  136. [MBProgressHUD showMessage:@"加载失败,请稍后重试"];
  137. }];
  138. }
  139. }
  140. -(void)requestCode
  141. {
  142. }
  143. /**
  144. 完成
  145. */
  146. - (void)nextAction:(UIButton *)sender {
  147. sender.enabled = NO;
  148. NSString *codeStr = _codeField.text;
  149. [SVProgressHUD show];
  150. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/bindingInvitationCode",BaseURL];
  151. NSDictionary *para = @{@"code":codeStr,
  152. @"unionid":(self.wx_union_id==nil?@"":self.wx_union_id)
  153. };
  154. if (self.user_id.length > 0 ) {//手机号登录绑定邀请码
  155. url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/mbindingInvitationCode",BaseURL];
  156. para = @{@"code":codeStr,
  157. @"user_id":(self.user_id==nil?@"":self.user_id)
  158. };
  159. }
  160. [LDHttp post:url params:para success:^(id json) {
  161. sender.enabled = YES;
  162. [SVProgressHUD dismiss];
  163. NSDictionary *dict = json[@"data"];
  164. if ([dict[@"flag"] boolValue]) {
  165. AccountModel *model = [AccountModel yy_modelWithJSON:dict];
  166. [AccountTool saveAccount:model];
  167. NSString *sex = [NSString stringWithFormat:@"%@",dict[@"sex"]];
  168. [[NSUserDefaults standardUserDefaults] setObject:sex forKey:UserSexKey];
  169. [[NSUserDefaults standardUserDefaults] synchronize];
  170. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil];
  171. if (self.linkFansBlock) {
  172. self.linkFansBlock();
  173. }
  174. [self dismissViewControllerAnimated:NO completion:^{
  175. LDPushToWeixViewController *vc = [[LDPushToWeixViewController alloc] init];
  176. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  177. [[self currentViewController] presentViewController:vc animated:YES completion:nil];
  178. }];
  179. }
  180. [MBProgressHUD showMessage:dict[@"info"]];
  181. } failure:^(NSError *error) {
  182. [MBProgressHUD showMessage:@"加载失败,请稍后重试"];
  183. [SVProgressHUD dismiss];
  184. sender.enabled = YES;
  185. }];
  186. }
  187. /**
  188. 扫描
  189. */
  190. - (void)scanAction {
  191. SubLBXScanViewController *scan = [[SubLBXScanViewController alloc] init];
  192. scan.modalPresentationStyle = UIModalPresentationFullScreen;
  193. [self presentViewController:scan animated:YES completion:nil];
  194. }
  195. - (UIViewController *)currentViewController{
  196. UIViewController * currVC = nil;
  197. UIWindow *window = [UIApplication sharedApplication].delegate.window;
  198. UIViewController * Rootvc = window.rootViewController;
  199. do {
  200. if ([Rootvc isKindOfClass:[UINavigationController class]]) {
  201. UINavigationController * nav = (UINavigationController *)Rootvc;
  202. UIViewController * v = [nav.viewControllers lastObject];
  203. currVC = v;
  204. Rootvc = v.presentedViewController;
  205. continue;
  206. }else if([Rootvc isKindOfClass:[UITabBarController class]]){
  207. UITabBarController * tabVC = (UITabBarController *)Rootvc;
  208. currVC = tabVC;
  209. Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
  210. continue;
  211. }
  212. } while (Rootvc!=nil);
  213. return currVC;
  214. }
  215. - (void)didReceiveMemoryWarning {
  216. [super didReceiveMemoryWarning];
  217. // Dispose of any resources that can be recreated.
  218. }
  219. /*
  220. #pragma mark - Navigation
  221. // In a storyboard-based application, you will often want to do a little preparation before navigation
  222. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  223. // Get the new view controller using [segue destinationViewController].
  224. // Pass the selected object to the new view controller.
  225. }
  226. */
  227. @end