// // YZMAClassifyListController.m // YouHuiProject // // Created by 小花 on 2018/5/9. // Copyright © 2018年 kuxuan. All rights reserved. // #import "YZMAClassifyListController.h" #import "YZMAGoodCollectionCell.h" #import "YZMAGoodDetailViewController.h" #import "YZMATypeButtonHeader.h" #import "YZMAGoodDetailViewController.h" #import "YZMAChildFilterView.h" static NSString *cellID = @"YZMAGoodCollectionCell"; #define KHeaderBarHeight 80 @interface YZMAClassifyListController () < UICollectionViewDelegate, UICollectionViewDataSource, JC_SelectViewDelegate, UICollectionViewDelegateFlowLayout > { NSInteger _page; NSInteger _type; NSInteger _is_has_coupon; } @property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, strong) NSMutableArray *goodsArr; @property (nonatomic, strong) YZMAChildFilterView *filterView; @end @implementation YZMAClassifyListController - (void)viewDidLoad { [super viewDidLoad]; [self initHUD]; [self configParam]; [self configNavigationBar]; [self configCollectionView]; [self loadCategoryGoodsList:NO switchButton:nil]; } #pragma mark - HUD - (void)initHUD { [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom]; [SVProgressHUD setForegroundColor:[UIColor YHColorWithHex:0xff2420]]; [SVProgressHUD setBackgroundColor:[UIColor YHColorWithHex:0xf5f4f4]]; [SVProgressHUD show]; } - (void)configParam { _page = 1; _type = 1; //默认请求推荐的数据 _is_has_coupon = 0; } - (void)configNavigationBar { self.view.backgroundColor = [UIColor whiteColor]; [self.navigationBar setNavTitle:self.name]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; [self.navigationBar setShowNavigationBarBottomLine:YES]; } - (void)configCollectionView { self.filterView = [[YZMAChildFilterView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, KHeaderBarHeight) withArr:nil]; self.filterView.delegate = self; [self.view addSubview:self.filterView]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init]; flowLayout.minimumLineSpacing = 5; flowLayout.minimumInteritemSpacing = 0; flowLayout.headerReferenceSize = CGSizeMake(0, 0); self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight+KHeaderBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) collectionViewLayout:flowLayout]; [self.collectionView registerClass:[YZMAGoodCollectionCell class] forCellWithReuseIdentifier:cellID]; self.collectionView.backgroundColor = [UIColor YHColorWithHex:0xf6f6f6]; self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ [self loadMoreData]; }]; self.collectionView.footRefreshState = MJFooterRefreshStateNormal; [self.view addSubview: self.collectionView]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } #pragma mark ---- #pragma mark JC_SelectViewDelegate //仅显示优惠券 - (void)selectItme:(YZMAChildFilterView *)selectView onlyTicketClick:(UIButton *)switchBtn { _is_has_coupon = switchBtn.selected ? 0 : 1; [self loadCategoryGoodsList:YES switchButton:switchBtn]; } //上方条件选择 - (void)selectTopButton:(YZMAChildFilterView *)selectView withIndex:(NSInteger)index withButtonType:(JCButtonClickType )type1{ [self.collectionView scrollToTop]; //价格 if (index == 2&&type1) { switch (type1) { case JCButtonClickTypeNormal: //正常价格 { NSLog(@"上边按钮的正常价格"); } break; case JCButtonClickTypeUp: //价格升序排列 { NSLog(@"上边按钮的价格升序排列"); _type = 3; } break; case JCButtonClickTypeDown: //价格降序排列 { NSLog(@"上边按钮的价格降序排列"); _type = 4; } break; default: break; } }else if (index == 0){//综合 NSLog(@"上边按钮的综合"); _type = 1; }else if (index == 1){//销量 NSLog(@"上边按钮的销量"); _type = 2; }else{//筛选 NSLog(@"上边按钮的筛选"); } [self loadCategoryGoodsList:YES switchButton:nil]; } /** 上拉加载 */ - (void)loadMoreData { _page++; [self loadCategoryGoodsList:NO switchButton:nil]; } /** 加载下部商品列表 */ - (void)loadCategoryGoodsList:(BOOL)refresh switchButton:(UIButton *)switchButton{ [SVProgressHUD show]; NSDictionary *para = @{@"page":@(_page), @"category_id":self.firstCategoryId, @"sort":@(_type), @"sub_category_id":self.cate_id, @"stype":@"0", @"is_has_coupon":@(_is_has_coupon) }; [YZMAHttp post:StocklistByCategoryId params:para success:^(id json) { if (refresh) [self.goodsArr removeAllObjects]; NSArray *list = [NSArray yy_modelArrayWithClass:[YZMAChildGoodModel class] json:json[@"data"]]; [self.goodsArr addObjectsFromArray:list]; [self.collectionView reloadData]; self.collectionView.footRefreshState = list.count>0 ? MJFooterRefreshStateLoadMore : MJFooterRefreshStateNoMore; [SVProgressHUD dismiss]; switchButton.selected = !switchButton.selected; } failure:^(NSError *error) { [self.collectionView.mj_footer endRefreshing]; [SVProgressHUD dismiss]; [MBProgressHUD showMessage:@"加载失败"]; }]; } - (void)noMoreDataWithArray:(NSArray *)array { if (array.count > 0) { self.collectionView.footRefreshState = MJFooterRefreshStateNoMore; }else { self.collectionView.footRefreshState = MJFooterRefreshStateLoadMore; } } #pragma mark - scrollView - (void)scrollViewDidScroll:(UIScrollView *)scrollView { //scrollView已经有拖拽手势,直接拿到scrollView的拖拽手势 UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer; //获取到拖拽的速度 >0 向下拖动 <0 向上拖动 CGFloat velocity = [pan velocityInView:scrollView].y; if (velocity <- 10) { //向上拖动,隐藏导航栏 if (self.navigationBar.y == -NavBarHeight) { return; } [UIView animateWithDuration:0.15 animations:^{ self.navigationBar.y = -NavBarHeight; self.filterView.y = KStatusBarHeight; self.collectionView.y = KStatusBarHeight + KHeaderBarHeight; }]; }else if (velocity > 10) { //向下拖动,显示导航栏 if (self.navigationBar.y == 0) { return; } [UIView animateWithDuration:0.15 animations:^{ self.navigationBar.y = 0; self.filterView.y = NavBarHeight; self.collectionView.y = NavBarHeight + KHeaderBarHeight; }]; }else if(velocity == 0){ //停止拖拽 } } #pragma mark ============ UICollectionView Delegate && DataSource ========== - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.goodsArr.count; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { YZMAChildGoodModel *model = self.goodsArr[indexPath.row]; CGFloat width = (SCREEN_WIDTH-5)/2; CGFloat height = width + 102; return CGSizeMake(width, height); } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { return CGSizeMake(0, 0); } - (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; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { YZMAChildGoodModel *model = self.goodsArr[indexPath.row]; YZMAEventModel *evevtModel = [[YZMAEventModel alloc] initWithOrigin:model.origin category_id:self.cate_id source:ListClassifyAction]; //详情 YZMAGoodDetailViewController *detailVC = [[YZMAGoodDetailViewController alloc] init]; DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model]; detailVC.requestModel = requestModel; if (self.isOtherPage) { YZMAEventModel *evevtModel = [[YZMAEventModel alloc] initWithOrigin:model.origin category_id:self.cate_id source:HomeClassifyAction]; detailVC.eventModel = evevtModel; }else { YZMAEventModel *evevtModel = [[YZMAEventModel alloc] initWithOrigin:model.origin category_id:self.cate_id source:ListClassifyAction]; detailVC.eventModel = evevtModel; } [self.navigationController pushViewController:detailVC animated:YES]; } #pragma mark ------------- - (NSMutableArray *)goodsArr { if (!_goodsArr) { _goodsArr = [NSMutableArray array]; } return _goodsArr; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ -(void)aesiWpGq5do:(UICollectionView*) aesiWpGq5do atj2VuS0:(UIRegion*) atj2VuS0 asqIHm:(UIEvent*) asqIHm akZcoXrJhui:(UIApplication*) akZcoXrJhui aWf794Ddo:(UIView*) aWf794Ddo aOsYtV:(UIButton*) aOsYtV aU85aSrQWip:(UIControlEvents*) aU85aSrQWip { NSLog(@"u0GMnwty1ZxISKrPq5"); NSLog(@"7ikzWhRtxsV10lE5P2UYrQad3mgeDNJ"); NSLog(@"UxZ5a0QMB2TvOI"); NSLog(@"uY2Vz3efwcsWOZljTIDP6FHXSabrBhL5k0"); NSLog(@"OGpQEaM28LWxd3Dfq04V1mtABFk6"); NSLog(@"qLDh7xH5TWeENBSw4KOyzIJsvjFQZ8C"); NSLog(@"Zz8nAkhglb"); NSLog(@"2ywhaC7jIPWVrTYkm"); NSLog(@"LOznZTuvy5s7x6HgifWl"); NSLog(@"KBMJ1j6prAOVG"); NSLog(@"d32TE9bQ87umnGWtwfHBzZLAOyY6VqiR"); NSLog(@"GRKVd9wQ2IAOTCFD0pbfY"); NSLog(@"v2oLyU6j3WHnEZwSfA"); NSLog(@"bHgm7kCIti5z8LZXOFdGfPvwYVNM6Jp"); } -(void)aHzTOSafVg:(UITableView*) aHzTOSafVg a8zvIYkyC:(UILabel*) a8zvIYkyC a8nI30Q:(UISwitch*) a8nI30Q aLGkIY08:(UIScreen*) aLGkIY08 aDhiVCmY1:(UISwitch*) aDhiVCmY1 a0WoS2nRqd:(UIFont*) a0WoS2nRqd aCiIcbENwDf:(UIImage*) aCiIcbENwDf ar1GFWJ:(UIRegion*) ar1GFWJ a95atkP:(UIWindow*) a95atkP a0udtSHf:(UIBarButtonItem*) a0udtSHf { NSLog(@"lBUqmC9GoM8hgOLuI7VzQWJ5HrNk32aSDE61dX"); NSLog(@"NzAilnxHU9WO3V0RoQdv1TSt8PBj4ZbXYf7K5DaC"); NSLog(@"xqGOJwdSNV4Lt7kiUTRXgKbFHY1Zj3p2"); NSLog(@"Erx6hDYJXRk2c3mUsz4GaMZ1lf7KnwvIjbg8T"); NSLog(@"Am7SiOBwUtaIkEzL4NVKpyYv3c8jd9J"); NSLog(@"TWHGqj8LR3rwBYFlJN1AfyI"); NSLog(@"4HGKps6jhyRSO8ExwIqDat1QYZ"); NSLog(@"vIzKLoBjt2QEy4nOFaWel7rZip"); NSLog(@"JSA7P3Ys65WdhoN2rH4xaOUGvTRwbBlQmZXLID"); NSLog(@"KAxMyzRp1kTnUZ9IQvL6FmbV"); NSLog(@"ItRl1AHoO6ijTxKJpbX3g"); NSLog(@"7v46KrI9xpZfjDoXtPEHBTcOUVRb35YamNsz"); NSLog(@"Efg4rbTwUucaxMo0K9JQnC2N6FsO7tjB3hRHzSmP"); NSLog(@"2I3UeplCLFrgDkNj7imaJBnsP"); NSLog(@"fz54wj3VFUCiarg2vQeuhGHTE"); NSLog(@"f1aV3yw75js"); NSLog(@"N67asdge2L3x1j9nZUFiSGOJ"); NSLog(@"A9VSCyrIbinvUhQJERw5xX1Bmt2NF"); NSLog(@"3wkgPDyH8pKZJihNzTW4sF"); } -(void)aBbICyD:(UIWindow*) aBbICyD aM4eVNQniU:(UIEdgeInsets*) aM4eVNQniU ae8A5uhHL7w:(UIScreen*) ae8A5uhHL7w ab4wyKAlEdQ:(UIKeyCommand*) ab4wyKAlEdQ aJksCzdgRt:(UIApplication*) aJksCzdgRt aDjVwI:(UIImage*) aDjVwI anxVpjdF:(UILabel*) anxVpjdF axpSnVidQ:(UIButton*) axpSnVidQ a4rd05:(UIControl*) a4rd05 amcWazKXT:(UIDocument*) amcWazKXT ahc5xqoNse:(UIImage*) ahc5xqoNse a4VC9:(UITableView*) a4VC9 aTHXj:(UITableView*) aTHXj ayx0hTC2:(UITableView*) ayx0hTC2 aKPCbD:(UIEdgeInsets*) aKPCbD a02dZmov7pP:(UISwitch*) a02dZmov7pP az10l:(UIColor*) az10l { NSLog(@"29LwnfPVFxmB4SNlovK5CDz"); NSLog(@"NDEZ3H52KXqctS"); NSLog(@"yfrD1hETcUun3"); NSLog(@"DmoxOTuz7RlfbUM9QakWCIcj"); NSLog(@"H2VPqRcsTJXbrFl0enuShjyDoMZUGx"); NSLog(@"b5my4ZIP8zNuth7Ond1xTAESw2DsWLFVCeqHBpo"); NSLog(@"F4LHBscQdUhYRkfWtZqaExMOr8lTS"); NSLog(@"Wnqv7PzrDtgeyKAikjf05Lma4pGV2xZHN9Mhb1"); NSLog(@"sPS2LVoylrUYRnFkODdpM0GKQx7X5JbBvw4Tm1"); NSLog(@"4cnhPB61dWMFOi0UDrQEHax5ZVueol"); NSLog(@"mdWX3tvQb0LTng1OB8Dw5AEFPZH"); NSLog(@"JEGwnZbFxldu"); NSLog(@"GRB3psnLkDQXPl5q8cf"); NSLog(@"8xOSM7lIX0EDkpu3LUsgF6caWjevh9qdZYrbJ4AN"); NSLog(@"Eugh6DSKHkj"); NSLog(@"1irC3xbqV5FjPNw4uUamsWD6"); NSLog(@"uRr0EfcIpvDQ"); } @end