// // JXVIPDetailViewController.m // shiku_im // // Created by cindy on 2020/5/29. // Copyright © 2020 Reese. All rights reserved. // #import "JXVIPDetailViewController.h" #import "XFStepView.h" #import "JXVipCenterView.h" #import "JXMyModel.h" #import "JXVipDetailHeaderView.h" #import "JXVipDetailCenterView.h" #import "JXVipDetailBottomView.h" #import "LabelSize.h" #import "Common.h" @interface JXVIPDetailViewController () @property (nonatomic, strong) UIScrollView *mainScrollView; @property (nonatomic, strong) JXVipDetailHeaderView *headerView;//头部UI @property (nonatomic, strong)JXVipDetailCenterView *centerView; @property (nonatomic, strong)JXVipDetailBottomView *bottomView; @property (nonatomic,strong) NSMutableArray *dataArr; @property (nonatomic,assign) int page; @property (nonatomic,strong) NSDictionary *getUserDict; @end @implementation JXVIPDetailViewController - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:NO]; } - (void)viewDidLoad { [super viewDidLoad]; _getUserDict=[NSDictionary dictionary]; _dataArr=[NSMutableArray array]; //自定义导航栏 [self _createdNavigationBar]; //创建View [self _createdViews]; } //自定义导航栏 - (void)_createdNavigationBar { self.navigationItem.title=@"VIP特权"; long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; ///user/vip/info /user/vip/info //[g_server getact_act_userGradelistGrade:salt andToView:self]; [SVProgressHUD show]; [g_server getUserVipInformation:salt andToView:self]; [g_server getUser:g_server.myself.userId toView:self]; } #pragma mark --- 请求成功 -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{ //NSLog(@"dict: %@ --- arry: %@",dict ,array1 ); if([aDownload.action isEqualToString:act_UserGet]){ //头像 [g_server delHeadImage:g_server.myself.userId]; [g_server getHeadImageSmall:g_server.myself.userId userName:g_server.myself.userNickname imageView:self.headerView.headerImageView]; //昵称 self.headerView.nameLabel.text = [NSString stringWithFormat:@"%@",dict[@"membershipAccount"]]; if ([dict[@"gradeIndex"] isEqualToNumber:@0]) { self.headerView.myGradeBigBackView.image=[UIImage imageNamed:[NSString stringWithFormat:@"vip_icon_%@",@"1"]]; } self.headerView.myGradeBigBackView.image=[UIImage imageNamed:[NSString stringWithFormat:@"vip_icon_%@",dict[@"gradeIndex"]]]; if ([dict[@"gradeIndex"] intValue]>=2) { self.headerView.myGradeView.image = [UIImage imageNamed:[NSString stringWithFormat:@"组%d",[dict[@"gradeIndex"] intValue]+43]]; }else{ self.headerView.myGradeView.image = [UIImage imageNamed:[NSString stringWithFormat:@"组%d",[dict[@"gradeIndex"] intValue]+42]]; } //右边等级值 self.headerView.numberLabel.text = [NSString stringWithFormat:@"%@",dict[@"gradeIndex"]]; // rechargeMoney //进度条左右按钮 // dict[@"gradeIndex"] = @"10"; if ([dict[@"gradeIndex"] intValue]>=10) { [self.headerView.leftGradeButton setTitle:[NSString stringWithFormat:@"%d级",9] forState:UIControlStateNormal]; [self.headerView.nextGradeButton setTitle:[NSString stringWithFormat:@"%d级",10] forState:UIControlStateNormal]; }else { NSString *vipleftIMG=[NSString stringWithFormat:@"%d级",[dict[@"gradeIndex"] intValue]]; NSString *viprightIMG=[NSString stringWithFormat:@"%d级",[dict[@"gradeIndex"] intValue]+1]; [self.headerView.leftGradeButton setTitle:vipleftIMG forState:UIControlStateNormal]; [self.headerView.nextGradeButton setTitle:viprightIMG forState:UIControlStateNormal]; } _getUserDict=dict; long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; ///user/vip/info /user/vip/info [g_server getact_act_userGradelistGrade:salt andToView:self]; //累计存款值 self.headerView.currentPriceLabel.text =[NSString stringWithFormat:@"%@",dict[@"totalRecharge"]]; //中间View赋值 NSString *sss = [NSString stringWithFormat:@"%@",dict[@"gradeIndex"]]; int p = [sss intValue]; self.page = p; }if([aDownload.action isEqualToString:act_userGradelistGrade]){ [SVProgressHUD dismiss]; NSArray *array =[[array1 reverseObjectEnumerator] allObjects]; _dataArr=[vipDetailModel mj_objectArrayWithKeyValuesArray:array]; [self _createdCenterView:_dataArr]; [self _createdBottomView]; NSLog(@"page===%d",self.page); self.centerView.stepView.stepIndex =_page-1; NSDictionary *dictCurrent = _getUserDict[@"vipInfo"]; //当前用户的钱 CGFloat aaaaMoney= [_getUserDict[@"totalRecharge"] intValue]*1.0; //当前用户的等级 int aaaa= [dictCurrent[@"current"][@"gradeIndex"] intValue]; //int aaaaMoney= [dictCurrent[@"current"][@"rechargeMoney"] intValue]; // 进度 = (累计-当前级)/(下一级晋级-当前级) CGFloat aaaaxx=0.0; if (aaaa==0) { aaaa=1; } // 当前级 vipDetailModel *model1 = _dataArr[aaaa-1]; int chaMoney1= [model1.rechargeMoney intValue]; // 下一级 vipDetailModel *model2 = _dataArr[aaaa]; int chaMoney2= [model2.rechargeMoney intValue]; if (aaaa==10) { aaaaxx= 1; }else { aaaaxx = (aaaaMoney-chaMoney1)/(chaMoney2-chaMoney1)*1.0; } if (aaaaxx>1) { aaaaxx=1; } /* */ //进度值 self.headerView.progressLabel.text=[NSString stringWithFormat:@"%.f%%",floor(aaaaxx*100)]; if ( aaaaxx !=0) { //更新进度Label的x坐标 [self.headerView.progressLabel mas_updateConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.headerView.leftGradeButton.mas_right).offset(aaaaxx* self.headerView.progressImageView.frame.size.width); }]; //当前进度View [self.headerView.currentProgressImageView mas_updateConstraints:^(MASConstraintMaker *make) { make.width.offset(aaaaxx* self.headerView.progressImageView.frame.size.width); }]; } if (self.page*100 >kScreenWidth) { //判断是否超出屏幕 self.centerView.grapeScrollView.contentOffset = CGPointMake((self.page *100)-kScreenWidth, 0); }else { self.centerView.grapeScrollView.contentOffset = CGPointMake(0, 0); } self.centerView.currentPageLabel.text = [NSString stringWithFormat:@"%d",self.page]; //底部View赋值 self.bottomView.zunxiangLabel.text = [NSString stringWithFormat:@"VIP%d尊享",self.page]; self.centerView.pictureScrollView.contentOffset = CGPointMake(self.centerView.pictureScrollView.width*(self.page-1), 0); //int aaaa2222= [dictCurrent[@"current"][@"gradeIndex"] intValue]; // if (i == self.page) { if (aaaa<1) { return; } NSArray *images=@[@"sjlj",@"群聊等级VIp标识",@"meirhb",@"bqb",@"bqb"]; for (int i=0; i=8) { but.hidden=NO; } else{ but.hidden=YES; } }if (i==4) { titleLabel.text = [NSString stringWithFormat:@"视频服务"]; if ([model.grade intValue]>=8) { but.hidden=NO; } else{ but.hidden=YES; } } } } } -(CGSize)titleBtnWight:(NSString *)titBtnW and:(UILabel *)titBtn { CGSize titleSize = [titBtnW boundingRectWithSize:CGSizeMake(MAXFLOAT, 17) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:titBtn.font} context:nil].size; return titleSize; } -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{ [SVProgressHUD dismiss]; NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]]; if([errorCode isEqualToString:@"权限验证失败"]) { if ([aDownload.action isEqualToString:act_userViplist]) { }if([aDownload.action isEqualToString:actuservipinfo]){ } } return [errorCode intValue]; } - (void)goback{ [g_navigation dismissViewController:self animated:NO]; } - (void)_createdViews { _dataArr=[NSMutableArray array]; //顶部UI [self _createdTopView]; } - (void)gobackBtnClick{ [g_navigation dismissViewController:self animated:NO]; } - (void)_createdTopView { //顶部UI self.headerView = [[JXVipDetailHeaderView alloc] init]; [self.headerView.gobackBtn addTarget:self action:@selector(gobackBtnClick) forControlEvents:UIControlEventTouchUpInside]; self.headerView.headerImageView.image = [UIImage imageNamed:@"组1"]; self.headerView.nameLabel.text = self.name; self.headerView.numberLabel.text = self.dengji; [self.headerView.leftGradeButton setTitle:[NSString stringWithFormat:@"%@级",self.dengji] forState:UIControlStateNormal]; [self.headerView.nextGradeButton setTitle:[NSString stringWithFormat:@"%d级",[self.dengji intValue]+1] forState:UIControlStateNormal]; self.headerView.progressLabel.text = @"0%"; self.headerView.currentPriceLabel.text = @"0"; [self.mainScrollView addSubview:self.headerView]; [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(@0); make.top.equalTo(@0); make.centerX.offset(0); make.right.equalTo(@0); make.height.equalTo(@280); }]; } - (void)_createdCenterView:(NSMutableArray *)array { self.centerView = [[JXVipDetailCenterView alloc] initWithFrame:CGRectZero Titles:array]; self.centerView.delegate = self; [self.mainScrollView addSubview:self.centerView]; [self.centerView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(@0); make.top.equalTo(self.headerView.mas_bottom).offset(20); make.right.equalTo(@0); make.height.equalTo(@210); }]; } - (void)_createdBottomView { self.bottomView = [[JXVipDetailBottomView alloc] init]; [self.mainScrollView addSubview:self.bottomView]; _bottomView.userInteractionEnabled=YES; [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(@0); make.top.equalTo(self.centerView.mas_bottom).offset(10); make.right.equalTo(@0); make.height.equalTo(@200); }]; } #pragma mark -UIScrollView delegate - (void)scrollViewDidEndDeceleratingWithCenterView:(UIScrollView *)scrollView { int page = (scrollView.contentOffset.x /scrollView.width)+1; int p = scrollView.contentOffset.x /scrollView.width; self.centerView.currentPageLabel.text = [NSString stringWithFormat:@"%d",page]; //当前显示的图片数量 self.centerView.stepView.stepIndex = p; if (page*100 >kScreenWidth) { //判断是否超出屏幕 self.centerView.grapeScrollView.contentOffset = CGPointMake((page *100)-kScreenWidth, 0); }else { self.centerView.grapeScrollView.contentOffset = CGPointMake(0, 0); } NSArray *images=@[@"sjlj",@"群聊等级VIp标识",@"meirhb",@"bqb",@"bqb",@"bqb"]; for (int i=0; i<=p; i++) { self.bottomView.zunxiangLabel.text = [NSString stringWithFormat:@"VIP%d尊享",p+1]; for (int a=0; a=8) { but.hidden=NO; } else{ but.hidden=YES; } } if (a==4) { if ([stringModel.grade intValue]>=8) { but.hidden=NO; titleLabel.text = [NSString stringWithFormat:@"视频服务"]; } else{ but.hidden=YES; } } } } } - (UIScrollView *)mainScrollView { if (!_mainScrollView) { _mainScrollView = [[UIScrollView alloc] init]; // _mainScrollView.bounces = NO; _mainScrollView.backgroundColor = kWhiteColor; [self.view addSubview:_mainScrollView]; [_mainScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(@0); make.top.equalTo(@0); make.right.equalTo(@0); make.bottom.equalTo(@0); }]; if (JX_SCREEN_HEIGHT>=812) { }else{ UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(foundSwipe:)]; //设置识别滑动方向 recognizer.direction =UISwipeGestureRecognizerDirectionUp; //Swipe手势识别器关联到View [_mainScrollView addGestureRecognizer:recognizer]; UISwipeGestureRecognizer *recognizer2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(foundSwipe2:)]; recognizer2.direction =UISwipeGestureRecognizerDirectionDown; [_mainScrollView addGestureRecognizer:recognizer2]; } } return _mainScrollView; } - (void)foundSwipe2:(UISwipeGestureRecognizer *)sender { //设置识别滑动方向 sender.direction =UISwipeGestureRecognizerDirectionDown; //Swipe手势识别器关联到View [self.view addGestureRecognizer:sender]; [UIView animateWithDuration:0.2 animations:^{ CGRect bounds=self.view.bounds; bounds.origin.y=0; _mainScrollView.bounds=bounds; }]; } - (void)foundSwipe:(UISwipeGestureRecognizer *)sender { [UIView animateWithDuration:0.2 animations:^{ CGRect bounds=_mainScrollView.bounds; if (JX_SCREEN_WIDTH>=414) { bounds.origin.y=15; }else{ bounds.origin.y=80; } _mainScrollView.bounds=bounds; }]; } @end