《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRLinkFansController.m 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. #import "DRPushToWeixViewController.h"
  11. @interface DRLinkFansController (){
  12. UITextField *_codeField;
  13. UILabel *_desLabel;
  14. UIView *backView;
  15. UIImageView *iconImg;
  16. UILabel *titleLabel;
  17. UILabel *tipeLabel;
  18. }
  19. @end
  20. @implementation DRLinkFansController
  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. [DRHttp 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. [DRHttp 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. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/bindingInvitationCode",BaseURL];
  150. NSDictionary *para = @{@"code":codeStr,
  151. @"unionid":(self.wx_union_id==nil?@"":self.wx_union_id)
  152. };
  153. [SVProgressHUD show];
  154. [DRHttp post:url params:para success:^(id json) {
  155. sender.enabled = YES;
  156. [SVProgressHUD dismiss];
  157. NSDictionary *dict = json[@"data"];
  158. if ([dict[@"flag"] boolValue]) {
  159. AccountModel *model = [AccountModel yy_modelWithJSON:dict];
  160. model.unionid = self.wx_union_id;
  161. model.openId = self.wx_open_id;
  162. [AccountTool saveAccount:model];
  163. NSString *sex = [NSString stringWithFormat:@"%@",dict[@"sex"]];
  164. [[NSUserDefaults standardUserDefaults] setObject:sex forKey:UserSexKey];
  165. [[NSUserDefaults standardUserDefaults] synchronize];
  166. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil];
  167. if (self.linkFansBlock) {
  168. self.linkFansBlock();
  169. }
  170. [self dismissViewControllerAnimated:NO completion:^{
  171. DRPushToWeixViewController *vc = [[DRPushToWeixViewController alloc] init];
  172. [[self currentViewController] presentViewController:vc animated:YES completion:nil];
  173. }];
  174. }
  175. [MBProgressHUD showMessage:dict[@"info"]];
  176. } failure:^(NSError *error) {
  177. [MBProgressHUD showMessage:@"加载失败,请稍后重试"];
  178. [SVProgressHUD dismiss];
  179. sender.enabled = YES;
  180. }];
  181. }
  182. /**
  183. 扫描
  184. */
  185. - (void)scanAction {
  186. SubLBXScanViewController *scan = [[SubLBXScanViewController alloc] init];
  187. [self presentViewController:scan animated:YES completion:nil];
  188. }
  189. - (UIViewController *)currentViewController{
  190. UIViewController * currVC = nil;
  191. UIWindow *window = [UIApplication sharedApplication].delegate.window;
  192. UIViewController * Rootvc = window.rootViewController;
  193. do {
  194. if ([Rootvc isKindOfClass:[UINavigationController class]]) {
  195. UINavigationController * nav = (UINavigationController *)Rootvc;
  196. UIViewController * v = [nav.viewControllers lastObject];
  197. currVC = v;
  198. Rootvc = v.presentedViewController;
  199. continue;
  200. }else if([Rootvc isKindOfClass:[UITabBarController class]]){
  201. UITabBarController * tabVC = (UITabBarController *)Rootvc;
  202. currVC = tabVC;
  203. Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex];
  204. continue;
  205. }
  206. } while (Rootvc!=nil);
  207. return currVC;
  208. }
  209. - (void)didReceiveMemoryWarning {
  210. [super didReceiveMemoryWarning];
  211. // Dispose of any resources that can be recreated.
  212. }
  213. /*
  214. #pragma mark - Navigation
  215. // In a storyboard-based application, you will often want to do a little preparation before navigation
  216. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  217. // Get the new view controller using [segue destinationViewController].
  218. // Pass the selected object to the new view controller.
  219. }
  220. */
  221. @end