// // ASVipCenterViewController.m // Asteria // // Created by iOS on 2023/6/26. // #import "ASVipCenterViewController.h" #import "ASUserBaseInfoView.h" #import "ASVipCenterLineItemView.h" #import "ASVipCenterCollectCell.h" #import "ASVipCouponsViewController.h" #import "ASBirthdayTreatViewController.h" #import "ASInfomationSetController.h" @interface ASVipCenterViewController () @property (nonatomic, strong) UIScrollView *scrollV; @property (nonatomic, strong) UIView *contentV; @property (nonatomic, strong) ASUserBaseInfoView *userInfoV; @property (nonatomic, strong) UICollectionView *collectV; @property (nonatomic, strong) UIPageControl *control; @property (nonatomic, strong) NSMutableArray *bottomVArr; //@property (nonatomic, strong) NSMutableArray *bottomTitleArr; @property (nonatomic, strong) NSArray *vipImgArr; @property (nonatomic, strong) UIStackView *bottomStv; @end @implementation ASVipCenterViewController - (void)viewDidLoad { [super viewDidLoad]; [UIView viewAddHorColorBg:self.view colorArr:@[ (id)_E0FFF5.CGColor, (id)Col_FFF.CGColor ] startP:CGPointMake(0.5, 0.25) endP:CGPointMake(0.5, 1)]; // self.bottomTitleArr = [NSMutableArray arrayWithObjects:@"EXCLUSIVE $100 COUPON", @"BIRTHDAY TREAT", nil]; self.vipImgArr = @[@"vip_bg1",@"vip_bg2",@"vip_bg3",@"vip_bg4",@"vip_bg5"]; [self loadSubVs]; [self.view bringSubviewToFront:self.customNavBar]; [self configSubVs]; [self setData]; } - (void)setData { [self.userInfoV setData]; ASVipModel *curVipM = ASUserInfoManager.shared.curVipInfo; ASVipModel *nexVipM = ASUserInfoManager.shared.nextVipInfo; self.userInfoV.usefualLb.text = [NSString stringWithFormat:@"Growth Value %ld/%ld", ASUserInfoManager.shared.pointAmount.integerValue, nexVipM.exppoints.integerValue]; NSArray *arr = ASUserInfoManager.shared.vipInfoArr; self.control.numberOfPages = arr.count > 0 ? arr.count : 0; NSInteger curPage = curVipM.level.integerValue-1; self.control.currentPage = curPage >= 0 ? curPage : 0; } - (void)configSubVs { self.titleStr = @"VIP Center"; [self setNavRightSearch:^{ }]; self.statusBgV.backgroundColor = _E0FFF5; self.customNavBar.backgroundColor = _F0FFFA; } // MARK: - loadSubVs - (void)loadSubVs { [self.view addSubview:self.scrollV]; [self.scrollV addSubview:self.contentV]; [self.contentV addSubview:self.userInfoV]; [self.contentV addSubview:self.collectV]; [self.contentV addSubview:self.control]; self.bottomStv = [self getBottomV:ASUserInfoManager.shared.curVipInfo]; [self.contentV addSubview:self.bottomStv]; [self.scrollV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.customNavBar.mas_bottom); make.leading.trailing.bottom.equalTo(self.view); }]; [self.contentV mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.scrollV); make.width.equalTo(self.view); }]; [self.userInfoV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentV).offset(30); make.leading.equalTo(self.contentV).offset(20); make.trailing.equalTo(self.contentV).offset(-20); }]; [self.collectV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userInfoV.mas_bottom).offset(50); make.leading.trailing.equalTo(self.contentV); CGFloat collH = (KScreenWidth-40)/335*256; make.height.equalTo(@(collH)); }]; [self.control mas_makeConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@10); make.leading.equalTo(self.contentV).offset(20); make.trailing.equalTo(self.contentV).offset(-20); make.top.equalTo(self.collectV.mas_bottom).offset(20); }]; [self.bottomStv mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.control.mas_bottom).offset(20); make.leading.trailing.equalTo(self.contentV); make.bottom.equalTo(self.contentV.mas_bottom).offset(-80); }]; } // MARK: - subvs - (ASUserBaseInfoView *)userInfoV { if (!_userInfoV) { ASUserBaseInfoView *v = [[ASUserBaseInfoView alloc] initWithFrame:CGRectZero]; v.backgroundColor = UIColor.clearColor; v.usefualLb.font = [UIFont fontWithName:Rob_Regular size:14]; v.usefualLb.textColor = Col_666; v.avaterV.layer.cornerRadius = 8; v.avaterV.layer.masksToBounds = true; _userInfoV = v; } return _userInfoV; } - (UIScrollView *)scrollV { if (!_scrollV) { UIScrollView *v = [[UIScrollView alloc] init]; v.backgroundColor = UIColor.clearColor; v.showsVerticalScrollIndicator = false; v.alwaysBounceVertical = true; _scrollV = v; } return _scrollV; } - (UIView *)contentV { if (!_contentV) { UIView *v = [UIView baseV]; v.backgroundColor = UIColor.clearColor; _contentV = v; } return _contentV; } - (UICollectionView *)collectV { if (!_collectV) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); layout.minimumInteritemSpacing = 0; layout.minimumLineSpacing = 0; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; CGFloat collH = (KScreenWidth-40)/335*256; layout.itemSize = CGSizeMake(KScreenWidth, collH); UICollectionView *collV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, collH) collectionViewLayout:layout]; collV.backgroundColor = [UIColor clearColor]; collV.alwaysBounceHorizontal = true; collV.scrollEnabled = true; collV.pagingEnabled = true; collV.delegate = self; collV.dataSource = self; collV.showsHorizontalScrollIndicator = false; [collV registerClass:[ASVipCenterCollectCell class] forCellWithReuseIdentifier:@"ASVipCenterCollectCell"]; _collectV = collV; } return _collectV; } -(UIPageControl *)control { if (!_control) { _control = [[UIPageControl alloc] init]; [_control setTintColor:[UIColor colorWithHexString:@"#000000"]]; [_control setPageIndicatorTintColor:[[UIColor colorWithHexString:@"#000000"] colorWithAlphaComponent:0.3] ]; [_control setCurrentPageIndicatorTintColor:[UIColor colorWithHexString:@"#000000"] ]; _control.transform = CGAffineTransformScale(_control.transform, 1.15, 1.15); _control.userInteractionEnabled = false; } return _control; } - (UIStackView *)getBottomV:(ASVipModel *)vipM { UIStackView *stv = [UIStackView baseStackV:true]; stv.spacing = 0; stv.distribution = UIStackViewDistributionFillEqually; self.bottomVArr = [NSMutableArray array]; for (int i=0; i 0) { [cell setData:self.vipImgArr[indexPath.row%self.vipImgArr.count] desStr:[NSString stringWithFormat:@"INTEGRAL TO %@-%@", model.exppoints, model.nextExppoints]]; } else { [cell setData:self.vipImgArr[indexPath.row%self.vipImgArr.count] desStr:[NSString stringWithFormat:@"INTEGRAL TO %ld", model.exppoints.integerValue + 1]]; } cell.desLb.textColor = Col_000; if (indexPath.row == arr.count-1) { cell.desLb.textColor = _FFE797; } return cell; } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { NSInteger page = (NSInteger)scrollView.contentOffset.x/SCREEN_WIDTH; self.control.currentPage = page; [self reSetCurrentBottom]; } - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView { NSInteger page = (NSInteger)scrollView.contentOffset.x/SCREEN_WIDTH; self.control.currentPage = page; [self reSetCurrentBottom]; } - (void)reSetCurrentBottom { NSArray *arr = ASUserInfoManager.shared.vipInfoArr; if (arr.count <= self.control.currentPage) { return; } ASVipModel *model = arr[self.control.currentPage]; if (self.bottomStv && self.bottomStv.superview != nil) { for (UIView *item in self.bottomStv.arrangedSubviews) { [self.bottomStv removeArrangedSubview:item]; } [self.bottomStv removeFromSuperview]; } self.bottomStv = [self getBottomV:model]; [self.contentV addSubview:self.bottomStv]; [self.bottomStv mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.control.mas_bottom).offset(20); make.leading.trailing.equalTo(self.contentV); make.bottom.equalTo(self.contentV.mas_bottom).offset(-80); }]; } @end