123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // FKProRecommendListCell.m
- // FirstLink
- //
- // Created by jack on 16/8/13.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKProRecommendListCell.h"
- #import "FKProRecCollectionCell.h"
- #import "FKProDetailViewModel.h"
- #import "FKProRecommendItem.h"
- @interface FKProRecommendListCell () <UICollectionViewDelegate, UICollectionViewDataSource>
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, strong) NSArray *recItemArray;
- @end
- @implementation FKProRecommendListCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
-
- [self addAllSubviews];
-
- self.contentView.backgroundColor = [UIColor whiteColor];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return self;
- }
- - (void)addAllSubviews{
-
- [self.contentView addSubview:self.collectionView];
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView);
- make.left.equalTo(self.contentView).offset(10);
- make.right.equalTo(self.contentView).offset(-10);
- make.height.mas_equalTo(180);
- }];
- }
- + (CGFloat)cellHeight{
- return 185;
- }
- - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
- if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) {
- FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel;
- kProCellType cellType = [detailModel cellTypeForIndexPath:indexPath tableType:kProTableTypeUp];
- if (cellType == kProCellTypeBrandList) {
- self.recItemArray = detailModel.brandRecItem.brandRecList;
- [self.collectionView reloadData];
- } else if (cellType == kProCellTypeAllLook) {
- self.recItemArray = detailModel.allLookItem.productList;
- [self.collectionView reloadData];
- }
- }
- }
- - (FKProRecommendItem *)recItemAtIndex:(NSInteger)index{
- if (index >= 0 && index < self.recItemArray.count) {
- return self.recItemArray[index];
- }
- return nil;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return self.recItemArray.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- FKProRecCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FKProRecCollectionCell class]) forIndexPath:indexPath];
-
- FKProRecommendItem *item = [self recItemAtIndex:indexPath.row];
-
- if (item) {
- [cell.imageView setImageWithURL:item.picUrl cdnWidth:130];;
- cell.titleLabel.text = item.title;
- cell.priceLabel.text = [FLStringHelper convertFenToRMBmoneyString:item.price];
- }
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- if ([self.delegate respondsToSelector:@selector(listCell:selectAtIndex:)]){
- [self.delegate listCell:self selectAtIndex:indexPath];
- }
- }
- - (UICollectionView *)collectionView {
- if (_collectionView == nil) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.minimumInteritemSpacing = 10;
- layout.minimumLineSpacing = 10;
- layout.itemSize = CGSizeMake(130, 180);
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
-
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
- _collectionView.backgroundColor = [UIColor whiteColor];
- _collectionView.alwaysBounceVertical = NO;
- _collectionView.showsHorizontalScrollIndicator = NO;
- _collectionView.scrollsToTop = NO;
-
- [_collectionView registerClass:[FKProRecCollectionCell class] forCellWithReuseIdentifier:NSStringFromClass([FKProRecCollectionCell class])];
- }
- return _collectionView;
- }
- @end
|