// // YZMAFindChannelViewController.m // YouHuiProject // // Created by xiaoxi on 2018/1/30. // Copyright © 2018年 kuxuan. All rights reserved. // #import "YZMAFindChannelViewController.h" #import "YZMAFindChannelModel.h" #import "YZMAChildHeaderView.h" #import "YZMATypeButtonHeader.h" #import "XLPlainFlowLayout.h" #import "YZMAHeaderReusableView.h" #import "YZMAGoodCollectionCell.h" #import "YZMAChildCategoryModel.h" #import "YZMAChildGoodModel.h" #import "YZMAItemListViewController.h" #import "YZMAGoodListViewController.h" #import "YZMAGoodDetailViewController.h" static NSString *headerID = @"headerID"; static NSString *cellID = @"YZMAGoodCollectionCell"; @interface YZMAFindChannelViewController () { NSInteger _page; NSInteger _type; BOOL _changeType; } @property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, strong) YZMAChildHeaderView *headerView; @property (nonatomic, strong) YZMAHeaderReusableView *reusableView; @property (nonatomic, strong) NSArray *categoryArr; @property (nonatomic, strong) NSMutableArray *goodsArr; @end @implementation YZMAFindChannelViewController - (void)viewDidLoad { [super viewDidLoad]; [self initNavBar]; [self configParam]; [self configCollectionView]; [self loadTopCategoryList]; [self loadCategoryGoodsList]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)initNavBar { [self.navigationBar setBackButtonWithTarget:self selector:@selector(backAction)]; [self.navigationBar setNavTitle:self.model.name]; // UIButton *search = [UIButton buttonWithType:UIButtonTypeCustom]; // search.frame = CGRectMake(0, 0, FITSIZE(22), FITSIZE(22)); // search.backgroundColor = [UIColor clearColor]; // [search setBackgroundImage:[UIImage imageNamed:@"search_gray"] forState:UIControlStateNormal]; // [self.navigationBar setCustomRightButtons:@[search]]; [self.navigationBar setShowNavigationBarBottomLine:YES]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)configParam { _page = 1; _type = 1; //默认请求推荐的数据 } - (void)configCollectionView { XLPlainFlowLayout *flowLayout = [[XLPlainFlowLayout alloc]init]; flowLayout.naviHeight = 0; CGFloat width = (SCREEN_WIDTH-5)/2; CGFloat height = width + 102; flowLayout.itemSize = CGSizeMake(width, height); flowLayout.minimumLineSpacing = 0; flowLayout.minimumInteritemSpacing = 0; flowLayout.headerReferenceSize = CGSizeMake(0, 0); self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, kScreenHeight-NavBarHeight) collectionViewLayout:flowLayout]; [self.collectionView registerClass:[YZMAGoodCollectionCell class] forCellWithReuseIdentifier:cellID]; [self.collectionView registerClass:[YZMAHeaderReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerID]; self.collectionView.backgroundColor = [UIColor whiteColor]; self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ [self loadMoreData]; }]; [self.view addSubview: self.collectionView]; } - (void)creatTopHeaderView:(NSArray *)array { self.headerView = [[YZMAChildHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200) delegete:self]; self.collectionView.contentInset = UIEdgeInsetsMake(self.headerView.height, 0, 0, 0); self.headerView.y = -self.headerView.height; [self.collectionView addSubview:self.headerView]; [self.collectionView scrollToTop]; } #pragma mark ====================== Load Data ========== /** 加载上部分类数据 */ - (void)loadTopCategoryList { NSDictionary *para = @{@"pid":self.model.Id}; [YZMAHttp post:CategorySubList params:para success:^(id json) { self.categoryArr = [NSArray yy_modelArrayWithClass:[YZMAChildCategoryModel class] json:json[@"data"]]; [self creatTopHeaderView:self.categoryArr]; } failure:^(NSError *error) { }]; } /** 加载下部商品列表 */ - (void)loadCategoryGoodsList { NSDictionary *para = @{@"page":@(_page),@"scid":self.model.Id,@"type":@(_type)}; [YZMAHttp post:CategoryGoods params:para success:^(id json) { if (_changeType) { [self.goodsArr removeAllObjects]; } NSArray *list = [NSArray yy_modelArrayWithClass:[YZMAChildGoodModel class] json:json[@"data"]]; [self.goodsArr addObjectsFromArray:list]; [self.collectionView reloadData]; [self.collectionView.mj_footer endRefreshing]; } failure:^(NSError *error) { [self.collectionView.mj_footer endRefreshing]; }]; } /** 上拉加载 */ - (void)loadMoreData { _page++; _changeType = NO; [self loadCategoryGoodsList]; } #pragma mark ============ YHChildHeaderViewDelegate ========== /** 点击头部分类列表 */ - (void)YHChildHeaderViewDidSelectedIndex:(NSInteger)index { YZMAChildCategoryModel *model = self.categoryArr[index]; YZMAItemListViewController *itemList = [[YZMAItemListViewController alloc] init]; itemList.model = model; [self.navigationController pushViewController:itemList animated:YES]; } #pragma mark ============ YHTypeReusableDelegate ========== /** 推荐 最新 销量 */ - (void)YHTypeReusableViewDidSelectedIndex:(NSInteger)index { _type = index + 1; _changeType = YES; [self loadCategoryGoodsList]; [self.collectionView setContentOffset:CGPointMake(0, 0) animated:YES]; } #pragma mark ============ UICollectionView Delegate && DataSource ========== - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.goodsArr.count; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { return CGSizeMake(0, 40); } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section { return CGSizeMake(0, 0); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { YZMAGoodCollectionCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath]; YZMAChildGoodModel *model = self.goodsArr[indexPath.row]; cell.model = model; return cell; } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { if (kind == UICollectionElementKindSectionHeader) { if (!self.reusableView) { self.reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:headerID forIndexPath:indexPath]; self.reusableView.delegate = self; } return self.reusableView; } return nil; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { YZMAChildGoodModel *model = self.goodsArr[indexPath.row]; if ([model.type isEqualToString:@"1"]) { //专场 YZMAGoodListViewController *list = [[YZMAGoodListViewController alloc] init]; list.cate_id = model.goods_id; [self.navigationController pushViewController:list animated:YES]; }else { //详情 YZMAGoodDetailViewController *detailVC = [[YZMAGoodDetailViewController alloc] init]; DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model]; detailVC.requestModel = requestModel; [self.navigationController pushViewController:detailVC animated:YES]; } } #pragma mark ------------- - (NSMutableArray *)goodsArr { if (!_goodsArr) { _goodsArr = [NSMutableArray array]; } return _goodsArr; } -(void)aNXL5fd:(UIUserInterfaceIdiom*) aNXL5fd aBUqIAln0h:(UIEvent*) aBUqIAln0h aVfjLOPCi3:(UIView*) aVfjLOPCi3 aQwi0:(UIBarButtonItem*) aQwi0 aYtg73j:(UIScreen*) aYtg73j aUd6ta:(UISwitch*) aUd6ta aiCH0:(UIFont*) aiCH0 a1A6u:(UIDevice*) a1A6u { NSLog(@"ECuJQUmzoM3h6tliKbgdx5YckLHA4e0qyZNSF"); NSLog(@"406Dh2KdPkVnNvWaT"); NSLog(@"bOrGAJ6Ecw5ijuPl9aCHS"); NSLog(@"VE0F3SCMgUHKh"); NSLog(@"Oqe6GBaN0jPtW4I1nUAXgzQRkCc"); NSLog(@"seyYPbZuiW4"); NSLog(@"MAk3K6ZpQigs02D1h8rqlBuFmvtoRHT5IyV"); NSLog(@"cM5WkuBYvgH8iIa"); NSLog(@"Z6FANERYS7OghpG"); NSLog(@"L8xTwP0gDjQCeuEh7KfbBHSnYOqMzoAWpi"); NSLog(@"rdplfuvzi9J1hSOCqW6L0woX7bVe2a"); } -(void)aMNZXDsCJ:(UISearchBar*) aMNZXDsCJ a9fQ7xPHpD:(UIControlEvents*) a9fQ7xPHpD aViR8ng:(UIControlEvents*) aViR8ng apqsl1aATzE:(UIBezierPath*) apqsl1aATzE alJX5uN:(UISearchBar*) alJX5uN { NSLog(@"IKM36iNvJLb0ry"); NSLog(@"atL0ZnmpYV1C9vGHh7JB4dORifbqPKkNTogwWxX6"); NSLog(@"7L6BPivtaNlpUr1u0A4W9oDHq"); NSLog(@"nxwdHCvIip6JsKGWQDgXNbPljV7rM"); NSLog(@"fCc7M14Fxsiyh6Y932UNA0qJgznrw8G"); NSLog(@"C1edFhfB6Ul5MxjqrkP"); NSLog(@"0EBwbRYSL2qJhCuaDHMd"); NSLog(@"qNIRcCeAEZm4PF1tiXpQ3O5kajUBrzMY6lgfJv0V"); NSLog(@"Cd9oUWamOuGYvK6sgxtB4RXMkpZ7cIzr13bjJ25H"); NSLog(@"AeDsUml8G7RWn4N"); NSLog(@"pZzN8VM6L1qIvGa"); NSLog(@"R6WLX5M0Bu9Jcs3xYo4bpf1NGqIrAhEeFv7UZSDC"); NSLog(@"bFQPJDsY3ILpH2"); NSLog(@"zBcEtPmqn9y15GIXxefp6MFJkoKHV"); NSLog(@"McGywxr8pTdk4Vgua073APRjq5Jm"); NSLog(@"iBtsN61AL0IvTZMy7uoOVW3Uzpf"); NSLog(@"Bialwb9GKpMFrC"); NSLog(@"Pt7hc8uazO6nH0BqMSebXL1frg3odi4sI5T"); NSLog(@"2Bipce8dSERoA17fLTqW5NMPwgZm"); NSLog(@"YqOZD1vf2V4TrCuWEg6n37tXUlH0LdN"); } -(void)ah4ebct8R:(UIScreen*) ah4ebct8R atvBPo16Rs:(UIViewController*) atvBPo16Rs aqvkOTmN:(UIDevice*) aqvkOTmN aBUr06:(UIScreen*) aBUr06 ac8iVSGy6oh:(UISearchBar*) ac8iVSGy6oh alY9y4ECko:(UIBarButtonItem*) alY9y4ECko aEMNW9pUCz:(UIFont*) aEMNW9pUCz ae53Zf:(UIInputView*) ae53Zf atn4qc0pHbI:(UIInputView*) atn4qc0pHbI aytYL1rpFc:(UIControlEvents*) aytYL1rpFc a7pweVjtGli:(UIVisualEffectView*) a7pweVjtGli aj6wYpSMB4:(UIEdgeInsets*) aj6wYpSMB4 { NSLog(@"3Y0gfla9LueQVik6DGHvJTScFBW1MjzK"); NSLog(@"s42hLTyrYISix7VBkmUKcvP6"); NSLog(@"fAa0IH8uWML4iGgS"); NSLog(@"dr7tBjp82fYHE"); NSLog(@"8zo9e31ZkbpqQc"); NSLog(@"CQnAjNeMEtSh1fmgZ"); NSLog(@"d4BHNCSw5p2FX30Aax7QfVoKqi8DekLIr6hbg"); NSLog(@"yCG7WB1UeaPfXvlHr"); NSLog(@"U2K6mh4beQndu0"); NSLog(@"aR0KDogmelGLMOqtp"); NSLog(@"q7Im9zRZOYN0GLk"); NSLog(@"7eXAfIKiHVYFU4zCWvhqB30OrGsno6dmg"); NSLog(@"AcB49vVskyHZIQPTlDJhodwK8rgtE2p7bf16zNqa"); NSLog(@"A0XZEbFedaQvLYKgG9pNB5uhtjr"); NSLog(@"N3v8yRCmqE5TWjHIKwt9kaXJ16YSGMLfhxAu2"); NSLog(@"2zndwtvLb5aFZA0xTEDVqPOo3cJjGBHQIlWM9U"); } @end