ASProductListViewController.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // ASProductListViewController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/12.
  6. //
  7. #import "ASProductListViewController.h"
  8. #import "HomeFlashDealSubCollectCell.h"
  9. #import "ASProductListViewModel.h"
  10. #import "ASProductListMenuHeaderView.h"
  11. #import "ASProductListActiveHeaderView.h"
  12. @interface ASProductListViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
  13. @property (nonatomic, strong) NSArray <ASHomeBannerModel *>*topLinkArr;
  14. @property (nonatomic, strong) ASProductListViewModel *vm;
  15. @property (nonatomic, strong) UICollectionView *collectV;
  16. @property (nonatomic, strong) UIView *bottomV;
  17. @property (nonatomic, strong) UIButton *moreBt;
  18. @property (nonatomic, strong) UIButton *searchNavBt;
  19. @end
  20. @implementation ASProductListViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self loadSubVs];
  24. [self loasActiveDataAndV];
  25. self.vm = [ASProductListViewModel new];
  26. [self.collectV reloadData];
  27. }
  28. - (void)loadSubVs {
  29. [self.view addSubview:self.collectV];
  30. [self.customNavBar addSubview:self.searchNavBt];
  31. [self.searchNavBt mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.width.height.equalTo(@44);
  33. make.trailing.equalTo(self.customNavBar).offset(-10);
  34. make.centerY.equalTo(self.customNavBar);
  35. }];
  36. [self.collectV mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.equalTo(self.customNavBar.mas_bottom);
  38. make.leading.trailing.equalTo(self.view);
  39. make.bottom.equalTo(self.view);
  40. }];
  41. }
  42. - (void)loasActiveDataAndV {
  43. NSMutableArray *tempArr = [NSMutableArray array];
  44. for (int i=0;i < (arc4random()%6); i++) {
  45. ASHomeBannerModel *m = [ASHomeBannerModel demoModelWithType:i%3+1];
  46. [tempArr addObject:m];
  47. }
  48. self.topLinkArr = tempArr;
  49. [self.collectV reloadData];
  50. }
  51. // MARK: - delegate datasource
  52. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  53. }
  54. // MARK: - UICollectionViewDataSource
  55. - (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
  56. HomeFlashDealSubCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeFlashDealSubCollectCell" forIndexPath:indexPath];
  57. if (self.vm.productList.count <= indexPath.row)
  58. {
  59. return cell;
  60. }
  61. ASProductBaseModel *m = self.vm.productList[indexPath.row];
  62. cell.model = m;
  63. cell.contView.addCartBt.hidden = true;
  64. return cell;
  65. }
  66. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  67. return 3;
  68. }
  69. - (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  70. if (section == 0 || section == 1) {
  71. return 0;
  72. }
  73. return self.vm.productList.count;
  74. }
  75. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  76. if (section == 0) {
  77. CGSize size = CGSizeZero;
  78. if (self.topLinkArr.count > 0) {
  79. size = CGSizeMake(KScreenWidth, 40);
  80. }
  81. return size;
  82. }
  83. if (section == 1) {
  84. return CGSizeMake(KScreenWidth, 60);
  85. }
  86. return CGSizeZero;
  87. }
  88. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  89. if (indexPath.section == 0 && [kind isEqualToString:UICollectionElementKindSectionHeader]) {
  90. ASProductListActiveHeaderView *v = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ASProductListActiveHeaderView" forIndexPath:indexPath];
  91. [v setData:self.topLinkArr tapBlock:^(ASHomeBannerModel * _Nullable m) {
  92. }];
  93. return v;
  94. }
  95. if (indexPath.section == 1 && [kind isEqualToString:UICollectionElementKindSectionHeader]) {
  96. ASProductListMenuHeaderView *v = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ASProductListMenuHeaderView" forIndexPath:indexPath];
  97. [v setData:@"SORT BY" sortBlock:^{
  98. } menuBlock:^{
  99. }];
  100. return v;
  101. }
  102. return nil;
  103. }
  104. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  105. CGFloat marg = 10;
  106. CGFloat w = (KScreenWidth-3*marg)/2;
  107. CGFloat collH = (KScreenWidth-30)/2 + productHWithOutImg;
  108. return CGSizeMake(w, collH);
  109. }
  110. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  111. return 10;
  112. }
  113. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  114. return 10;
  115. }
  116. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  117. if (section == 0 || section == 1) {
  118. return UIEdgeInsetsZero;
  119. }
  120. return UIEdgeInsetsMake(10, 10, 10, 10);
  121. }
  122. // MARK: - actions
  123. - (void)search_navAction {
  124. // TODO: to searchVC
  125. }
  126. // MARK: - subvs
  127. -(UICollectionView *)collectV {
  128. if (!_collectV) {
  129. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  130. layout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
  131. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  132. CGFloat collH = (KScreenWidth-30)/2 + 126;
  133. layout.itemSize = CGSizeMake((KScreenWidth - 30)/2, collH);
  134. UICollectionView *collV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, collH) collectionViewLayout:layout];
  135. collV.backgroundColor = [UIColor whiteColor];
  136. collV.alwaysBounceVertical = true;
  137. collV.scrollEnabled = true;
  138. collV.delegate = self;
  139. collV.dataSource = self;
  140. collV.showsHorizontalScrollIndicator = false;
  141. collV.showsVerticalScrollIndicator = false;
  142. [collV registerClass:[HomeFlashDealSubCollectCell class] forCellWithReuseIdentifier:@"HomeFlashDealSubCollectCell"];
  143. [collV registerClass:[ASProductListActiveHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ASProductListActiveHeaderView"];
  144. [collV registerClass:[ASProductListMenuHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ASProductListMenuHeaderView"];
  145. _collectV = collV;
  146. }
  147. return _collectV;
  148. }
  149. -(UIView *)bottomV {
  150. if (!_bottomV) {
  151. UIView *v = [UIView baseV];
  152. v.backgroundColor = Col_FFF;
  153. v.clipsToBounds = true;
  154. _bottomV = v;
  155. }
  156. return _bottomV;
  157. }
  158. - (UIButton *)moreBt {
  159. if (!_moreBt) {
  160. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  161. [bt setTitle:@"VIEW MORE" forState:UIControlStateNormal];
  162. [bt setTitleColor:Col_000 forState:UIControlStateNormal];
  163. bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
  164. bt.layer.cornerRadius = 4;
  165. bt.layer.borderColor = Col_000.CGColor;
  166. bt.layer.borderWidth = 1;
  167. bt.layer.masksToBounds = true;
  168. _moreBt = bt;
  169. }
  170. return _moreBt;
  171. }
  172. - (UIButton *)searchNavBt {
  173. if (!_searchNavBt) {
  174. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  175. [bt setImage:[UIImage imageNamed:@"nav_search"] forState:UIControlStateNormal];
  176. [bt addTarget:self action:@selector(search_navAction) forControlEvents:UIControlEventTouchUpInside];
  177. _searchNavBt = bt;
  178. }
  179. return _searchNavBt;
  180. }
  181. @end