// // FKVipFeatureCell.m // FirstLink // // Created by jack on 15/9/11. // Copyright (c) 2015年 FirstLink. All rights reserved. // #import "FKVipFeatureCell.h" #import "FKVipPrivilegeCollectionCell.h" #import "FUKit.h" #import "FLControllerHelper.h" #import "WebViewController.h" @interface FKVipFeatureCell () @property (nonatomic, strong) FKCardSegmentView *cardSegmentView; @property (nonatomic, strong) UICollectionView *collectionView; @end @implementation FKVipFeatureCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self addAllSubviews]; self.selectionStyle = UITableViewCellSelectionStyleNone; } return self; } - (void)addAllSubviews { [self.contentView addSubview:self.cardSegmentView]; [self.cardSegmentView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.right.equalTo(self.contentView); make.height.mas_equalTo(48); }]; [self.contentView addSubview:self.collectionView]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.contentView); make.top.equalTo(self.cardSegmentView.mas_bottom).offset(22); make.height.mas_equalTo(200); }]; [self.contentView addSubview:self.buyButton]; [self.buyButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(14); make.right.equalTo(self.contentView).offset(-14); make.top.equalTo(self.collectionView.mas_bottom).offset(20); make.height.mas_equalTo(40); }]; } #pragma mark - UICollectionViewDataSource, UICollectionViewDelegate - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 6; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 1 || indexPath.row == 4) { return CGSizeMake(136, 90); } return CGSizeMake((UISCREENWIDTH - 2*12 - 136) / 2, 90); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { FKVipPrivilegeCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FKVipPrivilegeCollectionCell class]) forIndexPath:indexPath]; cell.imgView.image = [self.viewModel imageAtIndex:indexPath.row]; cell.titleLabel.attributedText = [self.viewModel attributedTitleAtIndex:indexPath.row]; if (indexPath.row == 1) { cell.lockImgView.hidden = NO; cell.futureImgView.hidden = NO; } else { cell.lockImgView.hidden = YES; cell.futureImgView.hidden = YES; } return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 1) { return; } NSString *index = @[@"1", @"2", @"3", @"4", @"5", @"6"][indexPath.row]; NSString *urlString = nil; if ((self.viewModel.segmentType == kCardSegmentTypeVip)) { urlString = [NSString stringWithFormat:@"%@/vip-guide/member.html?isCommon=true&iconIndex=%@", [[FKServerUtil sharedInstance] webServer], index]; } else { urlString = [NSString stringWithFormat:@"%@/vip-guide/member.html?isCommon=false&iconIndex=%@", [[FKServerUtil sharedInstance] webServer], index]; } WebViewController *newViewController = [[WebViewController alloc] init]; newViewController.url = urlString; newViewController.hidesBottomBarWhenPushed = YES; [[FLControllerHelper currentController].navigationController pushViewController:newViewController animated:YES]; } #pragma mark - FKCardSegmentViewDelegate - (void)cardSegmentView:(FKCardSegmentView *)view didSelectWithVipIndex:(kCardSegmentIndex)vip { if (kCardSegmentIndexLeft == vip) { self.viewModel.segmentType = kCardSegmentTypeVip; self.buyButton.tag = 0; } else if (kCardSegmentIndexRight == vip) { self.viewModel.segmentType = kCardSegmentTypeSuperVip; self.buyButton.tag = 1; } [self.collectionView reloadData]; } #pragma mark - Property - (FKCardSegmentView *)cardSegmentView { if (!_cardSegmentView) { _cardSegmentView = [FKCardSegmentView new]; _cardSegmentView.delegate = self; } return _cardSegmentView; } - (UICollectionView *)collectionView { if (!_collectionView) { UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new]; layout.minimumLineSpacing = CGFLOAT_MIN; layout.minimumInteritemSpacing = CGFLOAT_MIN; _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _collectionView.showsVerticalScrollIndicator = NO; _collectionView.alwaysBounceVertical = YES; _collectionView.dataSource = self; _collectionView.delegate = self; _collectionView.backgroundColor = UIColorFromRGB(0xffffff); _collectionView.contentInset = UIEdgeInsetsMake(0, 12, 0, 12); _collectionView.scrollEnabled = NO; [_collectionView registerClass:[FKVipPrivilegeCollectionCell class] forCellWithReuseIdentifier:NSStringFromClass([FKVipPrivilegeCollectionCell class])]; } return _collectionView; } - (UIButton *)buyButton { if (!_buyButton) { _buyButton = [UIButton buttonWithType:UIButtonTypeCustom]; _buyButton.layer.cornerRadius = 4.0; _buyButton.backgroundColor = UIColorFromRGB(0xff5656); [_buyButton setTitle:@"立即购买" forState:UIControlStateNormal]; [_buyButton.titleLabel setFont:[UIFont systemFontOfSize:18]]; [_buyButton setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal]; _buyButton.tag = 0; } return _buyButton; } @end