Nenhuma Descrição

FKProRecommendListCell.m 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // FKProRecommendListCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/8/13.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKProRecommendListCell.h"
  9. #import "FKProRecCollectionCell.h"
  10. #import "FKProDetailViewModel.h"
  11. #import "FKProRecommendItem.h"
  12. @interface FKProRecommendListCell () <UICollectionViewDelegate, UICollectionViewDataSource>
  13. @property (nonatomic, strong) UICollectionView *collectionView;
  14. @property (nonatomic, strong) NSArray *recItemArray;
  15. @end
  16. @implementation FKProRecommendListCell
  17. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  18. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  19. [self addAllSubviews];
  20. self.contentView.backgroundColor = [UIColor whiteColor];
  21. self.selectionStyle = UITableViewCellSelectionStyleNone;
  22. }
  23. return self;
  24. }
  25. - (void)addAllSubviews{
  26. [self.contentView addSubview:self.collectionView];
  27. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.top.equalTo(self.contentView);
  29. make.left.equalTo(self.contentView).offset(10);
  30. make.right.equalTo(self.contentView).offset(-10);
  31. make.height.mas_equalTo(180);
  32. }];
  33. }
  34. + (CGFloat)cellHeight{
  35. return 185;
  36. }
  37. - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
  38. if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) {
  39. FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel;
  40. kProCellType cellType = [detailModel cellTypeForIndexPath:indexPath tableType:kProTableTypeUp];
  41. if (cellType == kProCellTypeBrandList) {
  42. self.recItemArray = detailModel.brandRecItem.brandRecList;
  43. [self.collectionView reloadData];
  44. } else if (cellType == kProCellTypeAllLook) {
  45. self.recItemArray = detailModel.allLookItem.productList;
  46. [self.collectionView reloadData];
  47. }
  48. }
  49. }
  50. - (FKProRecommendItem *)recItemAtIndex:(NSInteger)index{
  51. if (index >= 0 && index < self.recItemArray.count) {
  52. return self.recItemArray[index];
  53. }
  54. return nil;
  55. }
  56. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  57. return self.recItemArray.count;
  58. }
  59. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  60. FKProRecCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FKProRecCollectionCell class]) forIndexPath:indexPath];
  61. FKProRecommendItem *item = [self recItemAtIndex:indexPath.row];
  62. if (item) {
  63. [cell.imageView setImageWithURL:item.picUrl cdnWidth:130];;
  64. cell.titleLabel.text = item.title;
  65. cell.priceLabel.text = [FLStringHelper convertFenToRMBmoneyString:item.price];
  66. }
  67. return cell;
  68. }
  69. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  70. if ([self.delegate respondsToSelector:@selector(listCell:selectAtIndex:)]){
  71. [self.delegate listCell:self selectAtIndex:indexPath];
  72. }
  73. }
  74. - (UICollectionView *)collectionView {
  75. if (_collectionView == nil) {
  76. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  77. layout.minimumInteritemSpacing = 10;
  78. layout.minimumLineSpacing = 10;
  79. layout.itemSize = CGSizeMake(130, 180);
  80. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  81. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  82. _collectionView.dataSource = self;
  83. _collectionView.delegate = self;
  84. _collectionView.backgroundColor = [UIColor whiteColor];
  85. _collectionView.alwaysBounceVertical = NO;
  86. _collectionView.showsHorizontalScrollIndicator = NO;
  87. _collectionView.scrollsToTop = NO;
  88. [_collectionView registerClass:[FKProRecCollectionCell class] forCellWithReuseIdentifier:NSStringFromClass([FKProRecCollectionCell class])];
  89. }
  90. return _collectionView;
  91. }
  92. @end