// // YYVipVC.m // SweetParty // // Created by bj_szd on 2023/12/18. // #import "YYVipVC.h" #import "YYVipItemCell.h" #import "YYVipChangeVC.h" @interface YYVipVC () @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; @property (weak, nonatomic) IBOutlet UIButton *confirmBtn; @property (weak, nonatomic) IBOutlet UILabel *timeLab; @property (nonatomic, strong) NSArray *dataArray; @property (nonatomic, assign) NSInteger selectIndex; @end @implementation YYVipVC - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; //默认都是黑色的,只有需要浅色的才需要额外写 LightContentStatusBar; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; //默认都是黑色的,只有需要浅色的才需要额外写 BlackContentStatusBar; } - (void)viewDidLoad { [super viewDidLoad]; [self showNaviBarWithTitle:@""]; [self.naviView.backBtn setImage:ImageNamed(@"whiteBack") forState:UIControlStateNormal]; self.selectIndex = -1; [self createUI]; [self fetchData]; } - (void)fetchData { NSDictionary *params = @{}; [AFNetworkRequset.shared postRequestWithParams:params Path:@"/api/Vip/get_vip_list" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) { NSArray *arr = [YYVipItemModel mj_objectArrayWithKeyValuesArray:responseDic[@"data"][@"vip_list"]]; self.dataArray = arr; [self.collectionView reloadData]; NSInteger is_vip = [responseDic[@"data"] safeIntForKey:@"is_vip"]; if (is_vip == 1) { NSString *timeStr = [NSString timestampToDateString:[responseDic[@"data"] safeStringForKey:@"vip_end_time"]]; self.timeLab.hidden = NO; self.timeLab.text = [NSString stringWithFormat:@"会员到期时间:%@", timeStr]; [self.confirmBtn setTitle:@"续费会员" forState:UIControlStateNormal]; }else { self.timeLab.hidden = YES; [self.confirmBtn setTitle:@"立即开通" forState:UIControlStateNormal]; } } Failure:^(id _Nonnull errorData) { }]; } - (void)createUI { self.confirmBtn.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(ScreenWidth-15*2, 45) direction:FXGradientChangeDirectionHorizontal startColor:HEXCOLOR(0xF6D2D0) endColor:HEXCOLOR(0xFFBB99)]; UIButton *rightBtn = [ControlCreator createButton:self.view rect:CGRectMake(ScreenWidth-75-15, yb_StatusBar_H+7, 75, 30) text:@"更换邀请人" font:YBMediumFont(13) color:HEXCOLOR(0xFFFFFF) backguoundColor:nil imageName:nil target:self action:@selector(onChangeInvite)]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; CGFloat itemW = (ScreenWidth-27*2-10*2)/3-10; layout.itemSize = CGSizeMake(itemW, 83); layout.minimumInteritemSpacing = 0; layout.minimumLineSpacing = 10; layout.sectionInset = UIEdgeInsetsMake(0, 12, 0, 12); layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; _collectionView.collectionViewLayout = layout; _collectionView.delegate = self; _collectionView.dataSource = self; [_collectionView registerNib:[UINib nibWithNibName:@"YYVipItemCell" bundle:nil] forCellWithReuseIdentifier:@"YYVipItemCell"]; } - (void)onChangeInvite { YYVipChangeVC *vc = [[YYVipChangeVC alloc] init]; [self.navigationController pushViewController:vc animated:YES]; } - (IBAction)onConfirm:(id)sender { if (self.selectIndex == -1) { [HelpPageDefine showMessage:@"请选择开通时长"]; return; } YYVipItemModel *model = self.dataArray[self.selectIndex]; NSDictionary *params = @{@"vid":model.vid}; [[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/pay/pay_vip_order" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) { [self fetchData]; } Failure:^(id _Nonnull errorData) { }]; } #pragma mark - UICollectionViewDelegate && UICollectionViewDataSource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.dataArray.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ YYVipItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YYVipItemCell" forIndexPath:indexPath]; YYVipItemModel *model = self.dataArray[indexPath.row]; cell.dayLab.text = [NSString stringWithFormat:@"%@天", model.day]; cell.priceLab.text = [NSString stringWithFormat:@"%@金币", model.price]; if (self.selectIndex == indexPath.row) { cell.bgImgV.image = ImageNamed(@"vip_item_sel"); cell.dayLab.textColor = HEXCOLOR(0x512A12); cell.priceLab.textColor = HEXCOLOR(0x785139); }else { cell.bgImgV.image = ImageNamed(@"vip_item_nor"); cell.dayLab.textColor = HEXCOLORA(0xFFFFFF, 0.6); cell.priceLab.textColor = HEXCOLORA(0xFFFFFF, 0.6); } return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { self.selectIndex = indexPath.row; [self.collectionView reloadData]; } @end