123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- //
- // ASProductListViewController.m
- // Asteria
- //
- // Created by iOS on 2023/6/12.
- //
- #import "ASProductListViewController.h"
- #import "HomeFlashDealSubCollectCell.h"
- #import "ASProductListViewModel.h"
- #import "ASProductListMenuHeaderView.h"
- #import "ASProductListActiveHeaderView.h"
- @interface ASProductListViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
- @property (nonatomic, strong) NSArray <ASHomeBannerModel *>*topLinkArr;
- @property (nonatomic, strong) ASProductListViewModel *vm;
- @property (nonatomic, strong) UICollectionView *collectV;
- @property (nonatomic, strong) UIView *bottomV;
- @property (nonatomic, strong) UIButton *moreBt;
- @property (nonatomic, strong) UIButton *searchNavBt;
- @end
- @implementation ASProductListViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self loadSubVs];
- [self loasActiveDataAndV];
- self.vm = [ASProductListViewModel new];
- [self.collectV reloadData];
-
-
-
- }
- - (void)loadSubVs {
-
- [self.view addSubview:self.collectV];
- [self.customNavBar addSubview:self.searchNavBt];
-
- [self.searchNavBt mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.height.equalTo(@44);
- make.trailing.equalTo(self.customNavBar).offset(-10);
- make.centerY.equalTo(self.customNavBar);
- }];
-
- [self.collectV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.customNavBar.mas_bottom);
- make.leading.trailing.equalTo(self.view);
- make.bottom.equalTo(self.view);
- }];
-
- }
- - (void)loasActiveDataAndV {
- NSMutableArray *tempArr = [NSMutableArray array];
- for (int i=0;i < (arc4random()%6); i++) {
- ASHomeBannerModel *m = [ASHomeBannerModel demoModelWithType:i%3+1];
- [tempArr addObject:m];
- }
- self.topLinkArr = tempArr;
-
- [self.collectV reloadData];
- }
- // MARK: - delegate datasource
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
-
-
- }
- // MARK: - UICollectionViewDataSource
- - (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
-
- HomeFlashDealSubCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeFlashDealSubCollectCell" forIndexPath:indexPath];
- if (self.vm.productList.count <= indexPath.row)
- {
- return cell;
- }
-
- ASProductBaseModel *m = self.vm.productList[indexPath.row];
- cell.model = m;
- cell.contView.addCartBt.hidden = true;
- return cell;
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 3;
- }
- - (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- if (section == 0 || section == 1) {
- return 0;
- }
- return self.vm.productList.count;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- CGSize size = CGSizeZero;
- if (self.topLinkArr.count > 0) {
- size = CGSizeMake(KScreenWidth, 40);
- }
- return size;
- }
- if (section == 1) {
- return CGSizeMake(KScreenWidth, 60);
- }
- return CGSizeZero;
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0 && [kind isEqualToString:UICollectionElementKindSectionHeader]) {
- ASProductListActiveHeaderView *v = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ASProductListActiveHeaderView" forIndexPath:indexPath];
- [v setData:self.topLinkArr tapBlock:^(ASHomeBannerModel * _Nullable m) {
-
- }];
- return v;
- }
- if (indexPath.section == 1 && [kind isEqualToString:UICollectionElementKindSectionHeader]) {
- ASProductListMenuHeaderView *v = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ASProductListMenuHeaderView" forIndexPath:indexPath];
- [v setData:@"SORT BY" sortBlock:^{
-
- } menuBlock:^{
-
- }];
- return v;
- }
- return nil;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
-
- CGFloat marg = 10;
- CGFloat w = (KScreenWidth-3*marg)/2;
- CGFloat collH = (KScreenWidth-30)/2 + productHWithOutImg;
- return CGSizeMake(w, collH);
- }
- -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
- return 10;
- }
- -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
- return 10;
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
- if (section == 0 || section == 1) {
- return UIEdgeInsetsZero;
- }
- return UIEdgeInsetsMake(10, 10, 10, 10);
- }
- // MARK: - actions
- - (void)search_navAction {
- // TODO: to searchVC
- }
- // MARK: - subvs
- -(UICollectionView *)collectV {
- if (!_collectV) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
- layout.scrollDirection = UICollectionViewScrollDirectionVertical;
- CGFloat collH = (KScreenWidth-30)/2 + 126;
- layout.itemSize = CGSizeMake((KScreenWidth - 30)/2, collH);
- UICollectionView *collV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, collH) collectionViewLayout:layout];
- collV.backgroundColor = [UIColor whiteColor];
- collV.alwaysBounceVertical = true;
- collV.scrollEnabled = true;
- collV.delegate = self;
- collV.dataSource = self;
- collV.showsHorizontalScrollIndicator = false;
- collV.showsVerticalScrollIndicator = false;
- [collV registerClass:[HomeFlashDealSubCollectCell class] forCellWithReuseIdentifier:@"HomeFlashDealSubCollectCell"];
- [collV registerClass:[ASProductListActiveHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ASProductListActiveHeaderView"];
- [collV registerClass:[ASProductListMenuHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ASProductListMenuHeaderView"];
- _collectV = collV;
- }
- return _collectV;
- }
- -(UIView *)bottomV {
- if (!_bottomV) {
- UIView *v = [UIView baseV];
- v.backgroundColor = Col_FFF;
- v.clipsToBounds = true;
- _bottomV = v;
- }
- return _bottomV;
- }
- - (UIButton *)moreBt {
- if (!_moreBt) {
- UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
- [bt setTitle:@"VIEW MORE" forState:UIControlStateNormal];
- [bt setTitleColor:Col_000 forState:UIControlStateNormal];
- bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
- bt.layer.cornerRadius = 4;
- bt.layer.borderColor = Col_000.CGColor;
- bt.layer.borderWidth = 1;
- bt.layer.masksToBounds = true;
- _moreBt = bt;
- }
- return _moreBt;
- }
- - (UIButton *)searchNavBt {
- if (!_searchNavBt) {
- UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
- [bt setImage:[UIImage imageNamed:@"nav_search"] forState:UIControlStateNormal];
- [bt addTarget:self action:@selector(search_navAction) forControlEvents:UIControlEventTouchUpInside];
- _searchNavBt = bt;
- }
- return _searchNavBt;
- }
- @end
|