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

DRPrivilegeReferralViewController.m 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. //
  2. // DRPrivilegeReferralViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by jcymac on 2018/5/21.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRPrivilegeReferralViewController.h"
  9. #import "DRPrivilegeReferralTableViewCell.h"
  10. #import "DRMyFansViewController.h"
  11. #import "DRInviteFansViewController.h"
  12. #import "DRPushToWeixViewController.h"
  13. #import "DRTopLevelView.h"
  14. #import "UIView+CCShadow.h"
  15. #import "DRMiddlePlanView.h"
  16. #import "DRBottomRuleView.h"
  17. #import "DRMyFansViewController.h"
  18. #import "DRChildAccountViewController.h"
  19. #import "DRAchievementViewController.h"
  20. @interface DRPrivilegeReferralViewController ()<UIScrollViewDelegate,TopLevelViewDelegate>
  21. {
  22. NSInteger _layoutCount;
  23. ActivityIndicatorView *_indicatorView;
  24. }
  25. @property (nonatomic, strong) UIScrollView *scrollView;
  26. @property (nonatomic, strong) DRTopLevelView *topLevelView;
  27. @property (nonatomic, strong) UIPageControl *pageCrontrol;
  28. @property (nonatomic, strong) DRMiddlePlanView *middlePlan;
  29. @property (nonatomic, strong) UIView *containerView;
  30. @property (nonatomic, strong) DRBottomRuleView *bottomRuleView;
  31. @property (nonatomic, strong) UIButton *bottomButton;
  32. @end
  33. @implementation DRPrivilegeReferralViewController
  34. #pragma mark -生命周期
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. self.view.backgroundColor=[UIColor whiteColor];
  38. [self configNavigationBar];
  39. [self initSubViews];
  40. [self loadPrivilegeData];
  41. [self initLoadingView];
  42. }
  43. -(void)viewDidAppear:(BOOL)animated{
  44. [super viewDidAppear:animated];
  45. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  46. }
  47. -(void)viewWillAppear:(BOOL)animated{
  48. [super viewWillAppear:animated];
  49. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  50. }
  51. -(void)viewDidDisappear:(BOOL)animated{
  52. [super viewDidDisappear:animated];
  53. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  54. }
  55. - (void)initLoadingView {
  56. ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
  57. _indicatorView = indicatorView;
  58. [_indicatorView startAnimating];
  59. }
  60. - (void)initSubViews {
  61. [self.view addSubview:self.scrollView];
  62. [self.scrollView addSubview:self.containerView];
  63. [self.containerView addSubview:self.topLevelView];
  64. [self.containerView addSubview:self.pageCrontrol];
  65. [self.containerView addSubview:self.middlePlan];
  66. [self.containerView addSubview:self.bottomRuleView];
  67. [self.containerView addSubview:self.bottomButton];
  68. [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.top.mas_equalTo(NavBarHeight);
  70. make.right.left.mas_equalTo(0);
  71. make.height.mas_equalTo(SCREEN_HEIGHT-NavBarHeight);
  72. }];
  73. [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.edges.equalTo(self.scrollView);
  75. make.width.equalTo(self.scrollView);
  76. }];
  77. [self.topLevelView mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.left.mas_equalTo(20);
  79. make.top.mas_equalTo(10);
  80. make.right.mas_equalTo(-20);
  81. make.height.mas_equalTo(360);
  82. }];
  83. [self.pageCrontrol mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.width.mas_equalTo(100);
  85. make.height.mas_equalTo(18);
  86. make.top.mas_equalTo(self.topLevelView.mas_bottom).mas_offset(3);
  87. make.centerX.mas_equalTo(self.topLevelView.mas_centerX);
  88. }];
  89. [self.middlePlan mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.mas_equalTo(20);
  91. make.top.mas_equalTo(self.pageCrontrol.mas_bottom).mas_offset(3);
  92. make.right.mas_equalTo(-20);
  93. make.height.mas_equalTo(120);
  94. }];
  95. [self.bottomRuleView mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.top.mas_equalTo(self.middlePlan.mas_bottom).mas_offset(20);
  97. make.left.mas_equalTo(20);
  98. make.right.mas_equalTo(-20);
  99. }];
  100. [self.bottomButton mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.top.mas_equalTo(self.bottomRuleView.mas_bottom).mas_offset(20);
  102. make.width.mas_equalTo(Fitsize(307));
  103. make.height.mas_equalTo(Fitsize(40));
  104. make.centerX.mas_equalTo(self.containerView.mas_centerX);
  105. }];
  106. [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.bottom.equalTo(self.bottomButton.mas_bottom).offset(60);// 这里放最后一个view的底部
  108. }];
  109. }
  110. - (void)loadPrivilegeData {
  111. NSDictionary *para = @{@"type":@(1)};
  112. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/getPrivilegeTop",BaseURL];
  113. [DRHttp post:url params:para success:^(id json) {
  114. NSArray *arr = [NSArray yy_modelArrayWithClass:[DRPrivilegeReferralModel class] json:json[@"data"]];
  115. CGFloat headerHeight = (SCREEN_WIDTH-40)*49/340;
  116. [self.topLevelView mas_updateConstraints:^(MASConstraintMaker *make) {
  117. make.height.mas_equalTo(arr.count*90+headerHeight);
  118. }];
  119. [self.topLevelView setScrollViewContentHeight:arr.count*90+headerHeight];
  120. [self.view layoutIfNeeded];
  121. [self subviewLayoutComplete];
  122. } failure:^(NSError *error) {
  123. }];
  124. }
  125. - (void)configNavigationBar {
  126. self.navigationBar.backgroundColor = [UIColor clearColor];
  127. [self.navigationBar setNavTitle:@""];
  128. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  129. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  130. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  131. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  132. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  133. UIImageView *imgTitle = [[UIImageView alloc] initWithFrame:CGRectMake(0, KStatusBarHeight+(44-18)/2, 75, 18)];
  134. imgTitle.image = [UIImage imageNamed:@"privilege_referral_top_title"];
  135. [self.navigationBar addSubview:imgTitle];
  136. imgTitle.centerX = SCREEN_WIDTH/2;
  137. UIImageView *imgBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, Fitsize(300))];
  138. imgBg.image = [UIImage imageNamed:@"privilege_bg_hei"];
  139. [self.view addSubview:imgBg];
  140. self.view.backgroundColor = [UIColor yhGrayColor];
  141. }
  142. - (void)backAction {
  143. [self.navigationController popViewControllerAnimated:YES];
  144. }
  145. - (void)subviewLayoutComplete {
  146. _layoutCount++;
  147. if (_layoutCount >= 3) {
  148. [self.view layoutIfNeeded];
  149. [self.topLevelView addShadowWithOpacity:.5 shadowRadius:5 andCornerRadius:9 andShadowColor:[UIColor YHColorWithHex:0x9D9D9B]];
  150. [self.middlePlan addShadowWithOpacity:.5 shadowRadius:5 andCornerRadius:9 andShadowColor:[UIColor YHColorWithHex:0x9D9D9B]];
  151. [self.bottomRuleView addShadowWithOpacity:.5 shadowRadius:5 andCornerRadius:9 andShadowColor:[UIColor YHColorWithHex:0x9D9D9B]];
  152. NSDictionary *userDic = [DRUserInfoManager shareManager].userInfoDic;
  153. DRUserInfo *userInfo = [DRUserInfo yy_modelWithJSON:userDic];
  154. [self.topLevelView setScollViewIndex:[userInfo.user_level integerValue]];
  155. [_indicatorView stopAnimating];
  156. }
  157. }
  158. - (void)jumpToPageWithType:(NSString *)type {
  159. switch ([type integerValue]) {
  160. case 1:
  161. //我的好友
  162. [self goToMyFansPage];
  163. break;
  164. case 2:
  165. //我的收益
  166. [self gotoMyIncomePage];
  167. break;
  168. case 3:
  169. //我的余额
  170. [self gotoMyBlancePage];
  171. break;
  172. default:
  173. break;
  174. }
  175. }
  176. /**
  177. 我的收益
  178. */
  179. - (void)gotoMyIncomePage {
  180. DRAchievementViewController *detail = [[DRAchievementViewController alloc] init];
  181. [self.navigationController pushViewController:detail animated:YES];
  182. }
  183. /**
  184. 我的粉丝
  185. */
  186. - (void)goToMyFansPage {
  187. DRMyFansViewController *myFans = [[DRMyFansViewController alloc] init];
  188. [self.navigationController pushViewController:myFans animated:YES];
  189. }
  190. /**
  191. 去我的余额界面
  192. */
  193. - (void)gotoMyBlancePage {
  194. DRChildAccountViewController *accountDetail = [[DRChildAccountViewController alloc] init];//提现
  195. [self.navigationController pushViewController:accountDetail animated:YES];
  196. }
  197. /**
  198. 专属客服
  199. */
  200. - (void)connectToUs {
  201. DRPushToWeixViewController *weixin = [[DRPushToWeixViewController alloc] init];
  202. NSDictionary *userDic = [DRUserInfoManager shareManager].userInfoDic;
  203. DRUserInfo *userInfo = [DRUserInfo yy_modelWithJSON:userDic];
  204. weixin.userInfo = userInfo;
  205. [self.navigationController pushViewController:weixin animated:YES];
  206. }
  207. #pragma mark ----- TopLevelViewDelegate -----
  208. - (void)TopLevelViewChangePage:(NSInteger)index {
  209. self.pageCrontrol.currentPage = index;
  210. }
  211. #pragma mark ---------
  212. - (UIScrollView *)scrollView {
  213. if (!_scrollView) {
  214. _scrollView = [[UIScrollView alloc] init];
  215. _scrollView.showsVerticalScrollIndicator = NO;
  216. _scrollView.backgroundColor = [UIColor clearColor];
  217. }
  218. return _scrollView;
  219. }
  220. - (UIView *)containerView {
  221. if (!_containerView) {
  222. _containerView = [[UIView alloc] init];
  223. }
  224. return _containerView;
  225. }
  226. - (DRTopLevelView *)topLevelView {
  227. if (!_topLevelView) {
  228. _topLevelView = [[DRTopLevelView alloc] initWithFrame:CGRectMake(20, NavBarHeight, SCREEN_WIDTH-40, 360)];
  229. _topLevelView.layer.cornerRadius = 9;
  230. _topLevelView.layer.masksToBounds = YES;
  231. _topLevelView.delegate = self;
  232. }
  233. return _topLevelView;
  234. }
  235. - (UIPageControl *)pageCrontrol {
  236. if (!_pageCrontrol) {
  237. _pageCrontrol = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
  238. _pageCrontrol.numberOfPages = 3;
  239. _pageCrontrol.currentPage = 0;
  240. _pageCrontrol.currentPageIndicatorTintColor = [UIColor YHColorWithHex:0xCCA062];
  241. _pageCrontrol.pageIndicatorTintColor = [UIColor whiteColor];
  242. }
  243. return _pageCrontrol;
  244. }
  245. - (DRMiddlePlanView *)middlePlan {
  246. if (!_middlePlan) {
  247. _middlePlan = [[DRMiddlePlanView alloc] initWithFrame:CGRectMake(20, 0, SCREEN_WIDTH-40, 120)];
  248. __weak typeof(self) weakSelf = self;
  249. _middlePlan.layer.cornerRadius = 9;
  250. _middlePlan.layer.masksToBounds = YES;
  251. _middlePlan.layoutComplete = ^{
  252. [weakSelf subviewLayoutComplete];
  253. };
  254. _middlePlan.selectedBlock = ^(DRMiddlePrvilegeModel * _Nonnull model) {
  255. [weakSelf jumpToPageWithType:model.type];
  256. };
  257. }
  258. return _middlePlan;
  259. }
  260. - (DRBottomRuleView *)bottomRuleView {
  261. if (!_bottomRuleView) {
  262. _bottomRuleView = [[DRBottomRuleView alloc] initWithFrame:CGRectMake(20, 0, SCREEN_WIDTH-40, 40)];
  263. __weak typeof(self) weakSelf = self;
  264. _bottomRuleView.layer.cornerRadius = 9;
  265. _bottomRuleView.layer.masksToBounds = YES;
  266. _bottomRuleView.backgroundColor = [UIColor whiteColor];
  267. _bottomRuleView.layoutComplete = ^{
  268. [weakSelf subviewLayoutComplete];
  269. };
  270. }
  271. return _bottomRuleView;
  272. }
  273. - (UIButton *)bottomButton {
  274. if (!_bottomButton) {
  275. _bottomButton = [UIButton buttonWithType:UIButtonTypeCustom];
  276. [_bottomButton setBackgroundImage:[UIImage imageNamed:@"pri_bottom_btn"] forState:UIControlStateNormal];
  277. [_bottomButton setTitle:@"联系专属客服" forState:UIControlStateNormal];
  278. _bottomButton.titleLabel.font = [UIFont systemFontOfSize:15];
  279. [_bottomButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  280. _bottomButton.layer.cornerRadius = Fitsize(20);
  281. _bottomButton.layer.masksToBounds = YES;
  282. [_bottomButton addTarget:self action:@selector(connectToUs) forControlEvents:UIControlEventTouchUpInside];
  283. }
  284. return _bottomButton;
  285. }
  286. @end