No Description

FKExploreTableViewCell.m 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // FKExploreTableCell.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/2/16.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKExploreTableViewCell.h"
  9. #import "FKExploreTopicListItem.h"
  10. #import "FKExploreNormalCell.h"
  11. #import "FKExploreMoreCell.h"
  12. #import "FKRecommendViewModel.h"
  13. @interface FKExploreTableViewCell ()
  14. <UICollectionViewDataSource, UICollectionViewDelegate>
  15. @property (nonatomic, strong) UIImageView *largeImageView;
  16. @property (nonatomic, strong) UIImageView *categoryImgIcon;
  17. @property (nonatomic, strong) UIImageView *triangleImgIcon;
  18. @property (nonatomic, strong) FKExploreTopicListItem *topicListItem;
  19. @end
  20. @implementation FKExploreTableViewCell
  21. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  22. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  23. self.selectionStyle = UITableViewCellSelectionStyleNone;
  24. self.contentView.backgroundColor = [UIColor whiteColor];
  25. [self addAllSubviews];
  26. }
  27. return self;
  28. }
  29. - (void)addAllSubviews {
  30. [self.contentView addSubview:self.largeImageView];
  31. [self.largeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.left.top.right.equalTo(self.contentView);
  33. make.height.mas_equalTo([FKExploreTableViewCell largeImageHeight:UISCREENWIDTH]);
  34. }];
  35. [self.largeImageView addSubview:self.categoryImgIcon];
  36. [self.categoryImgIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.equalTo(self.largeImageView).offset(10);
  38. make.left.equalTo(self.largeImageView);
  39. make.size.mas_equalTo(CGSizeMake(59, 16));
  40. }];
  41. [self.largeImageView addSubview:self.triangleImgIcon];
  42. [self.triangleImgIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.bottom.equalTo(self.largeImageView);
  44. make.left.equalTo(self.largeImageView).offset([FKExploreTableViewCell thumbImageBoardLength:UISCREENWIDTH]/2 + 15 - 10);
  45. }];
  46. [self.contentView addSubview:self.collectionView];
  47. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.bottom.right.equalTo(self.contentView);
  49. make.top.equalTo(self.largeImageView.mas_bottom);
  50. }];
  51. }
  52. - (void)configCell:(FKExploreTopicListItem *)item {
  53. [self.largeImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", item.photoURL,
  54. [FLStringHelper cdnParamaterString:UISCREENWIDTH
  55. height:[FKExploreTableViewCell largeImageHeight:UISCREENWIDTH]]]]];
  56. self.topicListItem = item;
  57. [self.collectionView reloadData];
  58. }
  59. - (void)fk_configWithViewModel:(FKRecommendViewModel *)viewModel indexPath:(NSIndexPath *)indexPath {
  60. if ([viewModel isKindOfClass:[FKRecommendViewModel class]]) {
  61. if ((indexPath.row - 1) < viewModel.operationActivityArea.dataArray.count) {
  62. FKActivityItem *activityItem = viewModel.operationActivityArea.dataArray[indexPath.row - 1];
  63. FKExploreTopicListItem *topicListItem = [FKExploreTopicListItem new];
  64. topicListItem.topicID = activityItem.itemID;
  65. topicListItem.photoURL = activityItem.picUrl;
  66. topicListItem.objectType = @"10";
  67. topicListItem.categoryURL = activityItem.categoryURL;
  68. NSMutableArray *array = [NSMutableArray array];
  69. FKExploreTopicListSubItem *subItem;
  70. for (FKActivityProductItem *productItem in activityItem.productArray) {
  71. subItem = [FKExploreTopicListSubItem new];
  72. subItem.itemID = productItem.itemID;
  73. subItem.name = productItem.title;
  74. subItem.indexPic = productItem.picURL;
  75. subItem.price = productItem.price;
  76. subItem.referPrice = productItem.originalPrice;
  77. [array addObject:subItem];
  78. }
  79. topicListItem.subItemArray = array;
  80. self.topicListItem = topicListItem;
  81. if (topicListItem.categoryURL.length > 0) {
  82. self.categoryImgIcon.hidden = NO;
  83. [self.categoryImgIcon sd_setImageWithURL:[NSURL URLWithString:topicListItem.categoryURL]];
  84. } else {
  85. self.categoryImgIcon.hidden = YES;
  86. }
  87. [self.largeImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", topicListItem.photoURL,
  88. [FLStringHelper cdnParamaterString:UISCREENWIDTH
  89. height:[FKExploreTableViewCell largeImageHeight:UISCREENWIDTH]]]]];
  90. [self.collectionView reloadData];
  91. self.collectionView.delegate = self;
  92. }
  93. }
  94. }
  95. #pragma mark - UICollectionViewDataSource
  96. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  97. return (self.topicListItem.subItemArray.count + 1);
  98. }
  99. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  100. UICollectionViewCell *cell;
  101. if (indexPath.row == self.topicListItem.subItemArray.count) {
  102. cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FKExploreMoreCell class])
  103. forIndexPath:indexPath];
  104. } else {
  105. FKExploreNormalCell *normalCell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FKExploreNormalCell class])
  106. forIndexPath:indexPath];
  107. [normalCell.imageView setImageWithURL:[self.topicListItem subItemImageURLStringAtIndex:indexPath.row] cdnWidth:[FKExploreTableViewCell thumbImageBoardLength:UISCREENWIDTH]];
  108. // normalCell.titleLabel.text = [self.topicListItem subItemTitleAtIndex:indexPath.row];
  109. normalCell.priceLabel.attributedText = [self.topicListItem priceAttributedStringAtIndex:indexPath.row];
  110. cell = normalCell;
  111. }
  112. return cell;
  113. }
  114. - (IBAction)clickLargeImageViewGesture:(UIGestureRecognizer *)gesture {
  115. if (self.delegate && [self.delegate respondsToSelector:@selector(recommendClickCell:atIndexPath:offset:)]) {
  116. [self.delegate recommendClickCell:self atIndexPath:self.indexPath offset:gesture.view.tag];
  117. }
  118. }
  119. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  120. // 更多Cell使用-1作为index
  121. NSInteger index = (indexPath.row == self.topicListItem.subItemArray.count ? -1 : indexPath.row);
  122. if (self.delegate && [self.delegate respondsToSelector:@selector(recommendClickCell:atIndexPath:offset:)]) {
  123. [self.delegate recommendClickCell:self atIndexPath:self.indexPath offset:index];
  124. }
  125. }
  126. #pragma mark - Height
  127. + (CGFloat)height {
  128. return ([FKExploreTableViewCell largeImageHeight:UISCREENWIDTH] + [FKExploreTableViewCell scrollViewHeight:UISCREENWIDTH]);
  129. }
  130. + (int)largeImageHeight: (CGFloat)screenWidth {
  131. return (int)(screenWidth * 185.0 / 375.0);
  132. }
  133. + (int)thumbImageBoardLength: (CGFloat)screenWidth {
  134. if (screenWidth <= 321) {
  135. return 100;
  136. }
  137. return 100;
  138. }
  139. + (int)scrollViewHeight:(CGFloat)screenWidth {
  140. return (10 + [FKExploreTableViewCell thumbImageBoardLength:screenWidth] + 36);
  141. }
  142. #pragma mark - Property
  143. - (UIImageView *)largeImageView {
  144. if (!_largeImageView) {
  145. _largeImageView = [UIImageView new];
  146. _largeImageView.tag = -1;
  147. _largeImageView.userInteractionEnabled = YES;
  148. [_largeImageView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickLargeImageViewGesture:)]];
  149. }
  150. return _largeImageView;
  151. }
  152. - (UIImageView *)categoryImgIcon {
  153. if (!_categoryImgIcon) {
  154. _categoryImgIcon = [UIImageView new];
  155. }
  156. return _categoryImgIcon;
  157. }
  158. - (UIImageView *)triangleImgIcon {
  159. if (!_triangleImgIcon) {
  160. _triangleImgIcon = [UIImageView new];
  161. _triangleImgIcon.image = [UIImage imageNamed:@"WhiteTriangleIcon"];
  162. }
  163. return _triangleImgIcon;
  164. }
  165. - (UICollectionView *)collectionView {
  166. if (!_collectionView) {
  167. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  168. layout.headerReferenceSize = CGSizeMake(15, 40);
  169. layout.footerReferenceSize = CGSizeMake(10, 40);
  170. layout.minimumInteritemSpacing = 0;
  171. layout.minimumLineSpacing = 10;
  172. layout.itemSize = CGSizeMake([FKExploreTableViewCell thumbImageBoardLength:UISCREENWIDTH], [FKExploreTableViewCell scrollViewHeight:UISCREENWIDTH]);
  173. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  174. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  175. _collectionView.dataSource = self;
  176. _collectionView.delegate = self;
  177. _collectionView.backgroundColor = [UIColor whiteColor];
  178. _collectionView.alwaysBounceVertical = NO;
  179. _collectionView.showsHorizontalScrollIndicator = NO;
  180. _collectionView.scrollsToTop = NO;
  181. [_collectionView registerClass:[FKExploreMoreCell class] forCellWithReuseIdentifier:NSStringFromClass([FKExploreMoreCell class])];
  182. [_collectionView registerClass:[FKExploreNormalCell class] forCellWithReuseIdentifier:NSStringFromClass([FKExploreNormalCell class])];
  183. }
  184. return _collectionView;
  185. }
  186. @end