// // DRPrivilegeReferralViewController.m // YouHuiProject // // Created by jcymac on 2018/5/21. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRPrivilegeReferralViewController.h" #import "DRPrivilegeReferralTableViewCell.h" #import "DRMyFansViewController.h" #import "DRInviteFansViewController.h" @interface DRPrivilegeReferralViewController () @property(nonatomic,strong)UIImageView *titleImageView; @property(nonatomic,strong)UIImageView *topImageView; @property(nonatomic,strong)UIButton *backBtn; @property(nonatomic,strong)UIScrollView *topScrollView; @property(nonatomic,strong)UILabel *leftLabel; @property(nonatomic,strong)NSMutableArray *leftStrArr; @property(nonatomic,strong)UIButton *rightBtn; @property(nonatomic,strong)UIView *centerLine; @property(nonatomic,strong)UITableView *tableView; @property(nonatomic,strong)NSMutableArray *dataArray; @property(nonatomic,strong)UIButton *becomeBtn; @property(nonatomic,strong)NSArray *detailArr; @property(nonatomic,strong)NSMutableArray *btnTitleArray; @end @implementation DRPrivilegeReferralViewController #pragma mark -生命周期 - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[UIColor whiteColor]; [self addUI]; [self adjustUI]; [self request]; } -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.navigationBar.hidden=YES; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } -(void)viewDidDisappear:(BOOL)animated{ [super viewDidDisappear:animated]; self.navigationBar.hidden=NO; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; } -(void)otherOP{ [self.btnTitleArray removeAllObjects]; switch ([self.flag integerValue]) { case 0://未绑定邀请码的会员 { [self.btnTitleArray addObject:@"成为超级会员"]; [self.btnTitleArray addObject:@""]; } break; case 1://会员和超级会员 { if ([self.isSuper integerValue]==1) {//超级会员 [self.btnTitleArray addObject:@""]; [self.btnTitleArray addObject:@"成为运营商"]; }else{//会员 [self.btnTitleArray addObject:@"成为超级会员"]; [self.btnTitleArray addObject:@""]; } } break; case 2://运营商 { [self.btnTitleArray addObject:@""]; [self.btnTitleArray addObject:@""]; [self.topScrollView setContentOffset:CGPointMake(280*2+10*3-SCREEN_WIDTH, 0) animated:YES]; } break; default: { [self.btnTitleArray addObject:@""]; [self.btnTitleArray addObject:@""]; } break; } if (self.btnTitleArray.count==2) { if ([self.flag integerValue]==2) {//运营商 if (![@"" isEqualToString:self.btnTitleArray[1]]) { [self.becomeBtn setTitle:self.btnTitleArray[1] forState:UIControlStateNormal]; self.becomeBtn.hidden=NO; } }else{//其余 if (![@"" isEqualToString:self.btnTitleArray[0]]) { [self.becomeBtn setTitle:self.btnTitleArray[0] forState:UIControlStateNormal]; self.becomeBtn.hidden=NO; } } } } -(void)request{ NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/introductionOfPrivilegesNew",BaseURL]; [DRHttp post:url params:nil success:^(id json) { UIImageView *img1=(UIImageView *)[self.topScrollView viewWithTag:10001]; [img1 sd_setImageWithURL:[NSURL URLWithString:json[@"data"][@"member"][@"img"]]]; UIImageView *img2=(UIImageView *)[self.topScrollView viewWithTag:10002]; [img2 sd_setImageWithURL:[NSURL URLWithString:json[@"data"][@"operate"][@"img"]]]; //更改左边文本 [self.leftStrArr removeAllObjects]; [self.leftStrArr addObject:json[@"data"][@"member"][@"condition"]]; [self.leftStrArr addObject:json[@"data"][@"operate"][@"condition"]]; //更新tableview数据 NSArray *arr=[NSArray yy_modelArrayWithClass:[DRPrivilegeReferralModel class] json:json[@"data"][@"member"][@"detail"]]; NSMutableArray *memberArr=self.detailArr[0]; [memberArr removeAllObjects]; [memberArr addObjectsFromArray:arr]; NSArray *arr2=[NSArray yy_modelArrayWithClass:[DRPrivilegeReferralModel class] json:json[@"data"][@"operate"][@"detail"]]; NSMutableArray *operateArr=self.detailArr[1]; [operateArr removeAllObjects]; [operateArr addObjectsFromArray:arr2]; if ([self.flag integerValue]==2) {//运营商 self.leftLabel.text=self.leftStrArr[1]; self.dataArray=operateArr; }else{ self.leftLabel.text=self.leftStrArr[0]; self.dataArray=memberArr; } [self.tableView reloadData]; } failure:^(NSError *error) { }]; NSString *url2=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/userIdentity",BaseURL]; [DRHttp post:url2 params:nil success:^(id json) { if (json[@"data"]) { NSNumber *flag=json[@"data"][@"flag"]; switch ([flag integerValue]) { case 0: { self.flag=0; } break; case 1: { self.flag=@(1); self.isSuper=@(0); } break; case 2: { self.flag=@(1); self.isSuper=@(1); } break; case 3: { self.flag=@(2); } break; default: self.flag=0; break; } } [self otherOP]; } failure:^(NSError *error) { }]; } -(void)addUI{ [self.view addSubview:self.topImageView]; [self.view addSubview:self.titleImageView]; [self.view addSubview:self.backBtn]; [self.view addSubview:self.topScrollView]; [self.view addSubview:self.leftLabel]; [self.view addSubview:self.rightBtn]; [self.view addSubview:self.centerLine]; [self.view addSubview:self.tableView]; [self.view addSubview:self.becomeBtn]; } -(void)adjustUI{ [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.mas_equalTo(0); make.height.mas_equalTo(149); }]; [self.titleImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.view.mas_centerX); make.top.mas_equalTo((SafeTopHeight+32)); make.width.mas_equalTo(75); make.height.mas_equalTo(18); }]; [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(FITSIZE(10)); make.top.mas_equalTo((SafeTopHeight+FITSIZE(32))); }]; [self.topScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(0); make.top.mas_equalTo(SafeTopHeight+66); make.height.mas_equalTo(164); }]; [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(FITSIZE(10)); make.top.mas_equalTo(self.topScrollView.mas_bottom).offset(19); make.width.mas_equalTo(FITSIZE(240)); }]; [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-FITSIZE(31)); make.centerY.equalTo(self.leftLabel.mas_centerY); }]; [self.centerLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(0); make.height.mas_equalTo(5); make.top.equalTo(self.leftLabel.mas_bottom).offset(10); }]; [self.becomeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.view.mas_bottom).offset(-48); make.centerX.equalTo(self.view.mas_centerX); make.height.mas_equalTo(42); make.width.mas_equalTo(FITSIZE(250)); }]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(0); make.top.equalTo(self.centerLine.mas_bottom).offset(10); make.bottom.equalTo(self.view.mas_bottom); }]; } #pragma mark -代理 UIScrollViewDelegate - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ if(scrollView==self.topScrollView){ if (scrollView.contentOffset.x<1) { self.leftLabel.text=self.leftStrArr[0]; NSString *str=self.btnTitleArray[0]; if (str!=nil&&![@"" isEqualToString:str]) { [self.becomeBtn setTitle:str forState:UIControlStateNormal]; self.becomeBtn.hidden=NO; }else{ self.becomeBtn.hidden=YES; } self.dataArray=self.detailArr[0]; }else{ self.leftLabel.text=self.leftStrArr[1]; NSString *str=self.btnTitleArray[1]; if (str!=nil&&![@"" isEqualToString:str]) { [self.becomeBtn setTitle:str forState:UIControlStateNormal]; self.becomeBtn.hidden=NO; }else{ self.becomeBtn.hidden=YES; } self.dataArray=self.detailArr[1]; // if (self.dataArray.count!=4) { // [self.dataArray addObject:[DRPrivilegeReferralModel defaultWithRow:3]]; // [self.tableView reloadData]; // } } } [self.tableView reloadData]; } #pragma mark -代理 UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ DRPrivilegeReferralTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"]; cell.model=self.dataArray[indexPath.row]; cell.userInteractionEnabled = NO; return cell; } #pragma mark -代理 UITableViewDelegate -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 80; } #pragma mark -点击事件 -(void)backAction{ [self.navigationController popViewControllerAnimated:YES]; } -(void)becomeAction{ if (self.topScrollView.contentOffset.x<1) { NSLog(@"进入成为超级会员"); if ([self.flag integerValue]==0 ||([self.flag integerValue]==1 && [self.isSuper integerValue]==0)) {//会员 UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"成为超级会员" message:[NSString stringWithFormat:@"\n联系你的邀请人,或者关注微信公众号\"liedouyouxuan\"升级"] preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"知道啦" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { }]; [alert addAction:cancelAction]; [self presentViewController:alert animated:YES completion:nil]; }else{//超级会员 } }else{ NSLog(@"进入成为运营商"); if(([self.flag integerValue]==1 && [self.isSuper integerValue]==1)){ DRInviteFansViewController *vc=[[DRInviteFansViewController alloc]init]; [self.navigationController pushViewController:vc animated:YES]; } } } -(void)rightAction{ DRMyFansViewController *vc=[[DRMyFansViewController alloc]init]; [self.navigationController pushViewController:vc animated:YES]; NSLog(@"我的粉丝"); } #pragma mark -懒加载 -(UIButton *)backBtn{ if (!_backBtn) { _backBtn=[UIButton buttonWithType:UIButtonTypeCustom]; [_backBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal]; [_backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; } return _backBtn; } -(UIImageView *)topImageView{ if (!_topImageView) { _topImageView=[[UIImageView alloc]init]; [_topImageView setImage:[UIImage imageNamed:@"privilege_referral_top_backgrand"]]; } return _topImageView; } -(UIScrollView *)topScrollView{ if (!_topScrollView) { _topScrollView=[[UIScrollView alloc]init]; UIImageView *btn1=[[UIImageView alloc]init]; btn1.frame=CGRectMake(10, 0, 280, 164); btn1.backgroundColor=[UIColor clearColor]; [btn1 setImage:[UIImage imageNamed:@"privilege_referral_top_0"]]; btn1.tag=10001; UIImageView *btn2=[[UIImageView alloc]init]; btn2.frame=CGRectMake(20+280, 0, 280, 164); btn2.tag=10002; btn2.backgroundColor=[UIColor clearColor]; [btn2 setImage:[UIImage imageNamed:@"privilege_referral_top_1"]]; _topScrollView.contentSize=CGSizeMake(280*2+10*3, 164); _topScrollView.bounces=NO; _topScrollView.pagingEnabled=YES; _topScrollView.showsVerticalScrollIndicator = NO; _topScrollView.showsHorizontalScrollIndicator = NO; _topScrollView.delegate=self; [_topScrollView addSubview:btn1]; [_topScrollView addSubview:btn2]; } return _topScrollView; } -(UILabel *)leftLabel{ if (!_leftLabel) { _leftLabel=[[UILabel alloc]init]; _leftLabel.text=@"拥有5位粉丝"; [_leftLabel sizeToFit]; _leftLabel.numberOfLines=0; _leftLabel.textColor=[UIColor YHColorWithHex:0x333333]; _leftLabel.font=[UIFont systemFontOfSize:14.0f]; } return _leftLabel; } -(UIButton *)rightBtn{ if (!_rightBtn) { _rightBtn=[[UIButton alloc]init]; [_rightBtn setTitle:@"我的粉丝>" forState:UIControlStateNormal]; [_rightBtn setTitleColor:[UIColor YHColorWithHex:0xFF6D33] forState:UIControlStateNormal]; [_rightBtn addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside]; _rightBtn.titleLabel.font=[UIFont systemFontOfSize:14.0f]; } return _rightBtn; } -(UIView *)centerLine{ if (!_centerLine) { _centerLine=[[UIView alloc]init]; _centerLine.backgroundColor=[UIColor YHColorWithHex:0xF4F4F4]; } return _centerLine; } -(UITableView *)tableView{ if (!_tableView) { _tableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; _tableView.delegate=self; _tableView.dataSource=self; _tableView.showsVerticalScrollIndicator = NO; _tableView.showsHorizontalScrollIndicator = NO; _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120)]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [_tableView registerNib:[UINib nibWithNibName:@"DRPrivilegeReferralTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"]; } return _tableView; } -(NSMutableArray *)dataArray{ if (!_dataArray) { _dataArray=[NSMutableArray array]; // for (int i=0; i<3; i++) { // [_dataArray addObject:[DRPrivilegeReferralModel defaultWithRow:i]]; // } } return _dataArray; } -(UIButton *)becomeBtn{ if (!_becomeBtn) { _becomeBtn=[UIButton buttonWithType:UIButtonTypeCustom]; CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.frame = CGRectMake(0, 0,FITSIZE(250),42); // 设置显示的frame gradientLayer.colors = @[(id)[UIColor YHColorWithHex:0xF8DB63].CGColor,(id)[UIColor YHColorWithHex:0xD59C30].CGColor]; // 设置渐变颜色 gradientLayer.startPoint = CGPointMake(0, 0); // gradientLayer.endPoint = CGPointMake(1, 0); // [_becomeBtn.layer addSublayer:gradientLayer]; _becomeBtn.layer.cornerRadius=21; _becomeBtn.layer.masksToBounds=YES; _becomeBtn.hidden=YES; [_becomeBtn setTitle:@"" forState:UIControlStateNormal]; _becomeBtn.titleLabel.font=[UIFont systemFontOfSize:17.0f]; [_becomeBtn setTitleColor:[UIColor YHColorWithHex:0x777777] forState:UIControlStateNormal]; [_becomeBtn addTarget:self action:@selector(becomeAction) forControlEvents:UIControlEventTouchUpInside]; _becomeBtn.titleLabel.textAlignment=NSTextAlignmentCenter; } return _becomeBtn; } -(UIImageView *)titleImageView{ if (!_titleImageView) { _titleImageView=[[UIImageView alloc]init]; [_titleImageView setImage:[UIImage imageNamed:@"privilege_referral_top_title"]]; } return _titleImageView; } -(NSMutableArray *)leftStrArr{ if (!_leftStrArr) { _leftStrArr=[[NSMutableArray alloc]initWithArray:@[@"",@""]]; } return _leftStrArr; } -(NSMutableArray *)btnTitleArray{ if (!_btnTitleArray) { _btnTitleArray=[[NSMutableArray alloc]initWithArray:@[@"",@""]]; } return _btnTitleArray; } -(NSArray *)detailArr{ if (!_detailArr) { _detailArr=@[[NSMutableArray array],[NSMutableArray array]]; } return _detailArr; } @end