省钱达人

DRPrivilegeReferralViewController.m 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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. @interface DRPrivilegeReferralViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate>
  13. @property(nonatomic,strong)UIImageView *titleImageView;
  14. @property(nonatomic,strong)UIImageView *topImageView;
  15. @property(nonatomic,strong)UIButton *backBtn;
  16. @property(nonatomic,strong)UIScrollView *topScrollView;
  17. @property(nonatomic,strong)UILabel *leftLabel;
  18. @property(nonatomic,strong)NSMutableArray *leftStrArr;
  19. @property(nonatomic,strong)UIButton *rightBtn;
  20. @property(nonatomic,strong)UIView *centerLine;
  21. @property(nonatomic,strong)UITableView *tableView;
  22. @property(nonatomic,strong)NSMutableArray *dataArray;
  23. @property(nonatomic,strong)UIButton *becomeBtn;
  24. @property(nonatomic,strong)NSArray *detailArr;
  25. @property(nonatomic,strong)NSMutableArray *btnTitleArray;
  26. @end
  27. @implementation DRPrivilegeReferralViewController
  28. #pragma mark -生命周期
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. self.view.backgroundColor=[UIColor whiteColor];
  32. [self addUI];
  33. [self adjustUI];
  34. [self request];
  35. }
  36. -(void)viewDidAppear:(BOOL)animated{
  37. [super viewDidAppear:animated];
  38. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  39. }
  40. -(void)viewWillAppear:(BOOL)animated{
  41. [super viewWillAppear:animated];
  42. self.navigationBar.hidden=YES;
  43. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  44. }
  45. -(void)viewDidDisappear:(BOOL)animated{
  46. [super viewDidDisappear:animated];
  47. self.navigationBar.hidden=NO;
  48. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  49. }
  50. -(void)otherOP{
  51. [self.btnTitleArray removeAllObjects];
  52. switch ([self.flag integerValue]) {
  53. case 0://未绑定邀请码的会员
  54. {
  55. [self.btnTitleArray addObject:@"成为超级会员"];
  56. [self.btnTitleArray addObject:@""];
  57. }
  58. break;
  59. case 1://会员和超级会员
  60. {
  61. if ([self.isSuper integerValue]==1) {//超级会员
  62. [self.btnTitleArray addObject:@""];
  63. [self.btnTitleArray addObject:@"成为运营商"];
  64. }else{//会员
  65. [self.btnTitleArray addObject:@"成为超级会员"];
  66. [self.btnTitleArray addObject:@""];
  67. }
  68. }
  69. break;
  70. case 2://运营商
  71. {
  72. [self.btnTitleArray addObject:@""];
  73. [self.btnTitleArray addObject:@""];
  74. [self.topScrollView setContentOffset:CGPointMake(280*2+10*3-SCREEN_WIDTH, 0) animated:YES];
  75. }
  76. break;
  77. default:
  78. {
  79. [self.btnTitleArray addObject:@""];
  80. [self.btnTitleArray addObject:@""];
  81. }
  82. break;
  83. }
  84. if (self.btnTitleArray.count==2) {
  85. if ([self.flag integerValue]==2) {//运营商
  86. if (![@"" isEqualToString:self.btnTitleArray[1]]) {
  87. [self.becomeBtn setTitle:self.btnTitleArray[1] forState:UIControlStateNormal];
  88. self.becomeBtn.hidden=NO;
  89. }
  90. }else{//其余
  91. if (![@"" isEqualToString:self.btnTitleArray[0]]) {
  92. [self.becomeBtn setTitle:self.btnTitleArray[0] forState:UIControlStateNormal];
  93. self.becomeBtn.hidden=NO;
  94. }
  95. }
  96. }
  97. }
  98. -(void)request{
  99. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/introductionOfPrivilegesNew",BaseURL];
  100. [DRHttp post:url params:nil success:^(id json) {
  101. UIImageView *img1=(UIImageView *)[self.topScrollView viewWithTag:10001];
  102. [img1 sd_setImageWithURL:[NSURL URLWithString:json[@"data"][@"member"][@"img"]]];
  103. UIImageView *img2=(UIImageView *)[self.topScrollView viewWithTag:10002];
  104. [img2 sd_setImageWithURL:[NSURL URLWithString:json[@"data"][@"operate"][@"img"]]];
  105. //更改左边文本
  106. [self.leftStrArr removeAllObjects];
  107. [self.leftStrArr addObject:json[@"data"][@"member"][@"condition"]];
  108. [self.leftStrArr addObject:json[@"data"][@"operate"][@"condition"]];
  109. //更新tableview数据
  110. NSArray *arr=[NSArray yy_modelArrayWithClass:[DRPrivilegeReferralModel class] json:json[@"data"][@"member"][@"detail"]];
  111. NSMutableArray *memberArr=self.detailArr[0];
  112. [memberArr removeAllObjects];
  113. [memberArr addObjectsFromArray:arr];
  114. NSArray *arr2=[NSArray yy_modelArrayWithClass:[DRPrivilegeReferralModel class] json:json[@"data"][@"operate"][@"detail"]];
  115. NSMutableArray *operateArr=self.detailArr[1];
  116. [operateArr removeAllObjects];
  117. [operateArr addObjectsFromArray:arr2];
  118. if ([self.flag integerValue]==2) {//运营商
  119. self.leftLabel.text=self.leftStrArr[1];
  120. self.dataArray=operateArr;
  121. }else{
  122. self.leftLabel.text=self.leftStrArr[0];
  123. self.dataArray=memberArr;
  124. }
  125. [self.tableView reloadData];
  126. } failure:^(NSError *error) {
  127. }];
  128. NSString *url2=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/userIdentity",BaseURL];
  129. [DRHttp post:url2 params:nil success:^(id json) {
  130. if (json[@"data"]) {
  131. NSNumber *flag=json[@"data"][@"flag"];
  132. switch ([flag integerValue]) {
  133. case 0:
  134. {
  135. self.flag=0;
  136. }
  137. break;
  138. case 1:
  139. {
  140. self.flag=@(1);
  141. self.isSuper=@(0);
  142. }
  143. break;
  144. case 2:
  145. {
  146. self.flag=@(1);
  147. self.isSuper=@(1);
  148. }
  149. break;
  150. case 3:
  151. {
  152. self.flag=@(2);
  153. }
  154. break;
  155. default:
  156. self.flag=0;
  157. break;
  158. }
  159. }
  160. [self otherOP];
  161. } failure:^(NSError *error) {
  162. }];
  163. }
  164. -(void)addUI{
  165. [self.view addSubview:self.topImageView];
  166. [self.view addSubview:self.titleImageView];
  167. [self.view addSubview:self.backBtn];
  168. [self.view addSubview:self.topScrollView];
  169. [self.view addSubview:self.leftLabel];
  170. [self.view addSubview:self.rightBtn];
  171. [self.view addSubview:self.centerLine];
  172. [self.view addSubview:self.tableView];
  173. [self.view addSubview:self.becomeBtn];
  174. }
  175. -(void)adjustUI{
  176. [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  177. make.left.right.top.mas_equalTo(0);
  178. make.height.mas_equalTo(149);
  179. }];
  180. [self.titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  181. make.centerX.equalTo(self.view.mas_centerX);
  182. make.top.mas_equalTo((SafeTopHeight+32));
  183. make.width.mas_equalTo(75);
  184. make.height.mas_equalTo(18);
  185. }];
  186. [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  187. make.left.mas_equalTo(FITSIZE(10));
  188. make.top.mas_equalTo((SafeTopHeight+FITSIZE(32)));
  189. }];
  190. [self.topScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  191. make.left.right.mas_equalTo(0);
  192. make.top.mas_equalTo(SafeTopHeight+66);
  193. make.height.mas_equalTo(164);
  194. }];
  195. [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  196. make.left.mas_equalTo(FITSIZE(10));
  197. make.top.mas_equalTo(self.topScrollView.mas_bottom).offset(19);
  198. make.width.mas_equalTo(FITSIZE(240));
  199. }];
  200. [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  201. make.right.mas_equalTo(-FITSIZE(31));
  202. make.centerY.equalTo(self.leftLabel.mas_centerY);
  203. }];
  204. [self.centerLine mas_makeConstraints:^(MASConstraintMaker *make) {
  205. make.left.right.mas_equalTo(0);
  206. make.height.mas_equalTo(5);
  207. make.top.equalTo(self.leftLabel.mas_bottom).offset(10);
  208. }];
  209. [self.becomeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  210. make.bottom.equalTo(self.view.mas_bottom).offset(-48);
  211. make.centerX.equalTo(self.view.mas_centerX);
  212. make.height.mas_equalTo(42);
  213. make.width.mas_equalTo(FITSIZE(250));
  214. }];
  215. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  216. make.left.right.mas_equalTo(0);
  217. make.top.equalTo(self.centerLine.mas_bottom).offset(10);
  218. make.bottom.equalTo(self.view.mas_bottom);
  219. }];
  220. }
  221. #pragma mark -代理 UIScrollViewDelegate
  222. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  223. if(scrollView==self.topScrollView){
  224. if (scrollView.contentOffset.x<1) {
  225. self.leftLabel.text=self.leftStrArr[0];
  226. NSString *str=self.btnTitleArray[0];
  227. if (str!=nil&&![@"" isEqualToString:str]) {
  228. [self.becomeBtn setTitle:str forState:UIControlStateNormal];
  229. self.becomeBtn.hidden=NO;
  230. }else{
  231. self.becomeBtn.hidden=YES;
  232. }
  233. self.dataArray=self.detailArr[0];
  234. }else{
  235. self.leftLabel.text=self.leftStrArr[1];
  236. NSString *str=self.btnTitleArray[1];
  237. if (str!=nil&&![@"" isEqualToString:str]) {
  238. [self.becomeBtn setTitle:str forState:UIControlStateNormal];
  239. self.becomeBtn.hidden=NO;
  240. }else{
  241. self.becomeBtn.hidden=YES;
  242. }
  243. self.dataArray=self.detailArr[1];
  244. // if (self.dataArray.count!=4) {
  245. // [self.dataArray addObject:[DRPrivilegeReferralModel defaultWithRow:3]];
  246. // [self.tableView reloadData];
  247. // }
  248. }
  249. }
  250. [self.tableView reloadData];
  251. }
  252. #pragma mark -代理 UITableViewDataSource
  253. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  254. return self.dataArray.count;
  255. }
  256. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  257. DRPrivilegeReferralTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
  258. cell.model=self.dataArray[indexPath.row];
  259. cell.userInteractionEnabled = NO;
  260. return cell;
  261. }
  262. #pragma mark -代理 UITableViewDelegate
  263. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  264. return 80;
  265. }
  266. #pragma mark -点击事件
  267. -(void)backAction{
  268. [self.navigationController popViewControllerAnimated:YES];
  269. }
  270. -(void)becomeAction{
  271. if (self.topScrollView.contentOffset.x<1) {
  272. NSLog(@"进入成为超级会员");
  273. if ([self.flag integerValue]==0 ||([self.flag integerValue]==1 && [self.isSuper integerValue]==0)) {//会员
  274. UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"成为超级会员" message:[NSString stringWithFormat:@"\n联系你的邀请人,或者关注微信公众号\"liedouyouxuan\"升级"] preferredStyle:UIAlertControllerStyleAlert];
  275. UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"知道啦" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  276. }];
  277. [alert addAction:cancelAction];
  278. [self presentViewController:alert animated:YES completion:nil];
  279. }else{//超级会员
  280. }
  281. }else{
  282. NSLog(@"进入成为运营商");
  283. if(([self.flag integerValue]==1 && [self.isSuper integerValue]==1)){
  284. DRInviteFansViewController *vc=[[DRInviteFansViewController alloc]init];
  285. [self.navigationController pushViewController:vc animated:YES];
  286. }
  287. }
  288. }
  289. -(void)rightAction{
  290. DRMyFansViewController *vc=[[DRMyFansViewController alloc]init];
  291. [self.navigationController pushViewController:vc animated:YES];
  292. NSLog(@"我的粉丝");
  293. }
  294. #pragma mark -懒加载
  295. -(UIButton *)backBtn{
  296. if (!_backBtn) {
  297. _backBtn=[UIButton buttonWithType:UIButtonTypeCustom];
  298. [_backBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  299. [_backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  300. }
  301. return _backBtn;
  302. }
  303. -(UIImageView *)topImageView{
  304. if (!_topImageView) {
  305. _topImageView=[[UIImageView alloc]init];
  306. [_topImageView setImage:[UIImage imageNamed:@"privilege_referral_top_backgrand"]];
  307. }
  308. return _topImageView;
  309. }
  310. -(UIScrollView *)topScrollView{
  311. if (!_topScrollView) {
  312. _topScrollView=[[UIScrollView alloc]init];
  313. UIImageView *btn1=[[UIImageView alloc]init];
  314. btn1.frame=CGRectMake(10, 0, 280, 164);
  315. btn1.backgroundColor=[UIColor clearColor];
  316. [btn1 setImage:[UIImage imageNamed:@"privilege_referral_top_0"]];
  317. btn1.tag=10001;
  318. UIImageView *btn2=[[UIImageView alloc]init];
  319. btn2.frame=CGRectMake(20+280, 0, 280, 164);
  320. btn2.tag=10002;
  321. btn2.backgroundColor=[UIColor clearColor];
  322. [btn2 setImage:[UIImage imageNamed:@"privilege_referral_top_1"]];
  323. _topScrollView.contentSize=CGSizeMake(280*2+10*3, 164);
  324. _topScrollView.bounces=NO;
  325. _topScrollView.pagingEnabled=YES;
  326. _topScrollView.showsVerticalScrollIndicator = NO;
  327. _topScrollView.showsHorizontalScrollIndicator = NO;
  328. _topScrollView.delegate=self;
  329. [_topScrollView addSubview:btn1];
  330. [_topScrollView addSubview:btn2];
  331. }
  332. return _topScrollView;
  333. }
  334. -(UILabel *)leftLabel{
  335. if (!_leftLabel) {
  336. _leftLabel=[[UILabel alloc]init];
  337. _leftLabel.text=@"拥有5位粉丝";
  338. [_leftLabel sizeToFit];
  339. _leftLabel.numberOfLines=0;
  340. _leftLabel.textColor=[UIColor YHColorWithHex:0x333333];
  341. _leftLabel.font=[UIFont systemFontOfSize:14.0f];
  342. }
  343. return _leftLabel;
  344. }
  345. -(UIButton *)rightBtn{
  346. if (!_rightBtn) {
  347. _rightBtn=[[UIButton alloc]init];
  348. [_rightBtn setTitle:@"我的粉丝>" forState:UIControlStateNormal];
  349. [_rightBtn setTitleColor:[UIColor YHColorWithHex:0xFF6D33] forState:UIControlStateNormal];
  350. [_rightBtn addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside];
  351. _rightBtn.titleLabel.font=[UIFont systemFontOfSize:14.0f];
  352. }
  353. return _rightBtn;
  354. }
  355. -(UIView *)centerLine{
  356. if (!_centerLine) {
  357. _centerLine=[[UIView alloc]init];
  358. _centerLine.backgroundColor=[UIColor YHColorWithHex:0xF4F4F4];
  359. }
  360. return _centerLine;
  361. }
  362. -(UITableView *)tableView{
  363. if (!_tableView) {
  364. _tableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  365. _tableView.delegate=self;
  366. _tableView.dataSource=self;
  367. _tableView.showsVerticalScrollIndicator = NO;
  368. _tableView.showsHorizontalScrollIndicator = NO;
  369. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120)];
  370. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  371. [_tableView registerNib:[UINib nibWithNibName:@"DRPrivilegeReferralTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
  372. }
  373. return _tableView;
  374. }
  375. -(NSMutableArray *)dataArray{
  376. if (!_dataArray) {
  377. _dataArray=[NSMutableArray array];
  378. // for (int i=0; i<3; i++) {
  379. // [_dataArray addObject:[DRPrivilegeReferralModel defaultWithRow:i]];
  380. // }
  381. }
  382. return _dataArray;
  383. }
  384. -(UIButton *)becomeBtn{
  385. if (!_becomeBtn) {
  386. _becomeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
  387. CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  388. gradientLayer.frame = CGRectMake(0, 0,FITSIZE(250),42); // 设置显示的frame
  389. gradientLayer.colors = @[(id)[UIColor YHColorWithHex:0xF8DB63].CGColor,(id)[UIColor YHColorWithHex:0xD59C30].CGColor]; // 设置渐变颜色
  390. gradientLayer.startPoint = CGPointMake(0, 0); //
  391. gradientLayer.endPoint = CGPointMake(1, 0); //
  392. [_becomeBtn.layer addSublayer:gradientLayer];
  393. _becomeBtn.layer.cornerRadius=21;
  394. _becomeBtn.layer.masksToBounds=YES;
  395. _becomeBtn.hidden=YES;
  396. [_becomeBtn setTitle:@"" forState:UIControlStateNormal];
  397. _becomeBtn.titleLabel.font=[UIFont systemFontOfSize:17.0f];
  398. [_becomeBtn setTitleColor:[UIColor YHColorWithHex:0x777777] forState:UIControlStateNormal];
  399. [_becomeBtn addTarget:self action:@selector(becomeAction) forControlEvents:UIControlEventTouchUpInside];
  400. _becomeBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
  401. }
  402. return _becomeBtn;
  403. }
  404. -(UIImageView *)titleImageView{
  405. if (!_titleImageView) {
  406. _titleImageView=[[UIImageView alloc]init];
  407. [_titleImageView setImage:[UIImage imageNamed:@"privilege_referral_top_title"]];
  408. }
  409. return _titleImageView;
  410. }
  411. -(NSMutableArray *)leftStrArr{
  412. if (!_leftStrArr) {
  413. _leftStrArr=[[NSMutableArray alloc]initWithArray:@[@"",@""]];
  414. }
  415. return _leftStrArr;
  416. }
  417. -(NSMutableArray *)btnTitleArray{
  418. if (!_btnTitleArray) {
  419. _btnTitleArray=[[NSMutableArray alloc]initWithArray:@[@"",@""]];
  420. }
  421. return _btnTitleArray;
  422. }
  423. -(NSArray *)detailArr{
  424. if (!_detailArr) {
  425. _detailArr=@[[NSMutableArray array],[NSMutableArray array]];
  426. }
  427. return _detailArr;
  428. }
  429. @end