123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- //
- // ZBProductListViewController.m
- // ZBProject
- //
- // Created by 学丽 on 2019/4/9.
- // Copyright © 2019 ZB. All rights reserved.
- //
- #import "ZBProductListViewController.h"
- #import "ZBProductListCell.h"
- @interface ZBProductListViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
- {
- CGFloat _lastContentOffset;
- CGFloat _oldY;
- }
- @property(nonatomic,strong)UICollectionView *collectionV;
- @property(nonatomic,strong)NSMutableArray *dataArray;
- @property(nonatomic,assign)NSInteger Page;
- @property(nonatomic,strong)NSMutableArray *listArray;
- //侧滑筛选
- @property(nonatomic,strong)ZBFilterView *filterView;
- @property(nonatomic,copy)NSString *lowestPrice;//最低价
- @property(nonatomic,copy)NSString *highPrice;//最低价
- @property(nonatomic,copy)NSString *start_rate;//佣金比例下限
- @property(nonatomic,assign)NSInteger counts;//判断是不是首次打开
- @end
- @implementation ZBProductListViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self initNav];
- self.counts = 1;
-
- [self getProductData];
- if ([self.model.type isEqualToString:@"cate"]) {
- [self requestWithId:self.model.Id];
- }else{
- self.collectionV.backgroundColor=[UIColor lineColor];
- }
-
- }
- -(void)requestWithId:(NSString *)Id
- {
- if (![AccountTool isLogin]) {
- return;
- }
- [LoadingView showInView:self.view];
- [ZBHTTP post:[NSString stringWithFormat:@"%@api/goods/childList",BASEURL] params:@{@"pid":Id} success:^(id _Nonnull json) {
-
- [self.listArray removeAllObjects];
- NSArray *array =[NSArray yy_modelArrayWithClass:[ClassModel class] json:json[@"list"]];
- [self.listArray addObjectsFromArray:array];
- [LoadingView dismiss];
- if (self.listArray.count ==0) {
- self.collectionV.backgroundColor=[UIColor lineColor];
- }else{
- self.collectionV.backgroundColor=[UIColor clearColor];
- }
- [self.collectionV reloadData];
-
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- }];
-
- }
- -(void)getProductData
- {
- if (![AccountTool isLogin]) {
- return;
- }
- [LoadingView showInView:self.view];
- //type为cate有
- NSDictionary *dics =@{@"page":@(self.Page),@"id":self.model.Id,@"type":self.model.type,@"start_price":self.lowestPrice,@"end_price":self.highPrice,@"start_tk_rate":self.start_rate};
- [ZBHTTP post:[NSString stringWithFormat:@"%@api/goods/listGoods",BASEURL] params:dics success:^(id _Nonnull json) {
- [LoadingView dismiss];
- NSArray *array =[NSArray yy_modelArrayWithClass:[ZBGoodModel class] json:json[@"data"]];
- [self.collectionV.mj_footer endRefreshing];
- [self.collectionV.mj_header endRefreshing];
- if (self.Page == 1) {
- self.dataArray=[NSMutableArray array];
- [self.dataArray removeAllObjects];
-
- }
- self.counts++;
- if (array.count > 0) {
- [self.dataArray addObjectsFromArray:array];
- }
- if (array.count == 0) {
- [self.collectionV.mj_footer endRefreshingWithNoMoreData];
- }
-
-
- [self.collectionV reloadData];
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- }];
- }
- -(void)initNav
- {
- self.Page = 1;
- self.lowestPrice=@"";
- self.start_rate=@"";
- self.highPrice=@"";
- [self.view addSubview:self.collectionV];
- [self.collectionV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(0);
-
- make.top.mas_equalTo(10);
- make.bottom.mas_equalTo(self.view.mas_bottom);
- }];
-
- [[UIApplication sharedApplication].keyWindow addSubview:self.filterView];
- self.filterView.frame=CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
- }
- #pragma mark---CollectionDelegate&&DataSource
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == 1) {
- if (self.dataArray.count == 0 && self.counts!=1) {
- NoDataCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"nodata" forIndexPath:indexPath];
- return cell;
- }
- ZBProductGoodListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"list" forIndexPath:indexPath];
-
- cell.model=self.dataArray[indexPath.row];
- return cell;
- }else{
- ZBProductClassCell *classC=[collectionView dequeueReusableCellWithReuseIdentifier:@"class" forIndexPath:indexPath];
- classC.listArray=self.listArray;
- classC.clickListBlock = ^(ClassModel * _Nonnull model) {//列表跳转
- ZBSecondListVC *listV =[[ZBSecondListVC alloc]init];
- listV.Id = model.Id;
- if (model.type.length == 0) {
- listV.type = @"module";
- }else{
- listV.type = model.type;
- }
- listV.click_type=@"1";
- listV.navigationItem.title=model.name;
- [self.navigationController pushViewController:listV animated:YES];
- } ;
- return classC;
- }
-
-
- }
- -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- {
- return 2;
-
- }
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- if (section == 0) {
- return 1;
- }else{
- if (self.dataArray.count == 0 && self.counts!=1) {
- return 1;
- }
- return self.dataArray.count;
- }
-
- }
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
- {
- if (section == 0) {
- return CGSizeMake(0, 0);
- }else{
- return CGSizeMake(SCREEN_WIDTH, 40);
- }
-
-
- }
- -(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == 1 && kind==UICollectionElementKindSectionHeader ) {
- ZBProductHeadView *head=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head" forIndexPath:indexPath];
- head.backgroundColor=[UIColor lineColor];
- if (self.lowestPrice.length!=0 || self.highPrice.length !=0) {
- NSString *price=[NSString stringWithFormat:@"价格%ld-%ld元",self.lowestPrice.integerValue,self.highPrice.integerValue];
- if (self.highPrice.integerValue == 0) {
- price=[NSString stringWithFormat:@"价格%ld元以上",self.lowestPrice.integerValue];
- }
- [head.priceBtn setTitle:price forState:UIControlStateNormal];
- [head.priceBtn setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
- [head.priceBtn setImage:nil forState:UIControlStateNormal];
- [head.priceBtn setButtonImageTitleStyle:ButtonImageTitleStyleDefault padding:0];
- }else{
- [head.priceBtn setTitle:@"价格筛选" forState:UIControlStateNormal];
- [head.priceBtn setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
-
- [head.priceBtn setImage:[UIImage imageNamed:@"shaixuan_icon"] forState:UIControlStateNormal];
- [head.priceBtn setButtonImageTitleStyle:ButtonImageTitleStyleRight padding:5];
- }
-
- if (self.start_rate.length!=0) {//佣金比例搜索
- [head.profitsBtn setTitle:[NSString stringWithFormat:@"佣金%@%%以上",self.start_rate] forState:UIControlStateNormal];
- [head.profitsBtn setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
- [head.profitsBtn setImage:nil forState:UIControlStateNormal];
- [head.profitsBtn setButtonImageTitleStyle:ButtonImageTitleStyleDefault padding:0];
- }else{
- [head.profitsBtn setTitle:@"利润筛选" forState:UIControlStateNormal];
- [head.profitsBtn setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
-
- [head.profitsBtn setImage:[UIImage imageNamed:@"shaixuan_icon"] forState:UIControlStateNormal];
- [head.profitsBtn setButtonImageTitleStyle:ButtonImageTitleStyleRight padding:5];
- }
-
-
-
- head.choiceBlock = ^(UIButton * _Nonnull btn) {
-
- [UIView animateWithDuration:0.5 animations:^{
- self.filterView.frame=CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
- [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleDefault;
-
- }];
- if (btn.tag == 1111) {//价格筛选
- [self.filterView settitle:@"价格区间(元)" LeftPlachoder:@"最低价" rightISHidden:NO RightPlacholder:@"最高价" Array:@[@"10元以下",@"10-50元",@"50-100元",@"100元以上"]rate:self.start_rate lowPrice:self.lowestPrice highprice:self.highPrice];
- }else{
- [self.filterView settitle:@"利润区间" LeftPlachoder:@"最低利润" rightISHidden:YES RightPlacholder:@"" Array:@[@"20%以上",@"30%以上",@"40%以上",@"50%以上"]rate:self.start_rate lowPrice:self.lowestPrice highprice:self.highPrice];
- }
-
- };
- return head;
- }else{
- UICollectionReusableView *head=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"view" forIndexPath:indexPath];
- return head;
- }
-
-
- }
- -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
- {
- if (self.listArray.count >0) {
- return UIEdgeInsetsMake(10, 10, 0, 10);
- }else{
- return UIEdgeInsetsMake(0.1, 10, 0, 9.5);
- }
-
-
-
- }
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section==1) {
- if (self.dataArray.count == 0 && self.counts !=1) {
- return CGSizeMake(SCREEN_WIDTH, 200);
- }
- return CGSizeMake((SCREEN_WIDTH-30)/2, 277);
- }else{
- if (self.listArray.count==0) {
- return CGSizeMake(0, 0.1);
- }else if (self.listArray.count>4 ) {
- return CGSizeMake(SCREEN_WIDTH-20, 180);
- }else{
- return CGSizeMake(SCREEN_WIDTH-20, 90);
- }
-
- }
-
-
- }
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
-
- if (indexPath.section == 0 || self.dataArray.count == 0) {
-
- return;
- }
- ZBGoodDetailVC *detilV =[[ZBGoodDetailVC alloc]init];
- detilV.model=self.dataArray[indexPath.row];
- detilV.detailModel=self.dataArray[indexPath.section];
- [self.navigationController pushViewController:detilV animated:YES];
- }
- -(UICollectionView *)collectionV
- {
- if (!_collectionV) {
- XLPlainFlowLayout *flowLayout =[[XLPlainFlowLayout alloc]init];
- flowLayout.naviHeight = 0;
- flowLayout.minimumLineSpacing = 10;
- flowLayout.minimumInteritemSpacing = 0;
- flowLayout.headerReferenceSize = CGSizeMake(0, 0);
- _collectionV =[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:flowLayout];
- _collectionV.delegate=self;
- _collectionV.dataSource=self;
- _collectionV.showsVerticalScrollIndicator=NO;
- _collectionV.showsHorizontalScrollIndicator=NO;
- _collectionV.backgroundColor=[UIColor clearColor];
- [_collectionV registerClass:[ZBProductGoodListCell class] forCellWithReuseIdentifier:@"list"];
- [_collectionV registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"view"];
- [_collectionV registerClass:[ZBProductHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"];
- [_collectionV registerClass:[NoDataCell class] forCellWithReuseIdentifier:@"nodata"];
- [_collectionV registerClass:[ZBProductClassCell class] forCellWithReuseIdentifier:@"class"];
- self.collectionV.mj_header =[MJRefreshNormalHeader headerWithRefreshingBlock:^{
- self.Page = 1;
- [self getProductData];
- }];
- self.collectionV.mj_footer=[MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- self.Page ++;
- [self getProductData];
- }];
-
- }
- return _collectionV;
- }
- -(void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
- if (scrollView.contentOffset.y < 0 || [self.collectionV.mj_footer isRefreshing]) {
- return;
- }
- //scrollView已经有拖拽手势,直接拿到scrollView的拖拽手势
- UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer;
- //获取到拖拽的速度 >0 向下拖动 <0 向上拖动
- CGFloat velocity = [pan velocityInView:scrollView].y;
-
-
- // CGFloat offY = scrollView.contentOffset.y - _lastContentOffset;
- // NSNotification *noti = [[NSNotification alloc] initWithName:@"scrollDirectorNoti" object:nil userInfo:@{@"director":@(velocity),@"offY":@(offY)}];
- // [[NSNotificationCenter defaultCenter] postNotification:noti];
- _lastContentOffset = scrollView.contentOffset.y;
-
- if(self.listArray.count>0 )
- {
- if ([scrollView isEqual: self.collectionV]) {
- if (self.collectionV.contentOffset.y > _oldY) {
- // 上滑
- [UIView animateWithDuration:0.1 animations:^{
- self.collectionV.backgroundColor=[UIColor lineColor];
- }];
- }
- else if(self.collectionV.contentOffset.y<=50 ){
- // 下滑
- [UIView animateWithDuration:0.1 animations:^{
- self.collectionV.backgroundColor=[UIColor clearColor];
- }];
- }
- }
- }
-
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
- // 获取开始拖拽时tableview偏移量
- _oldY = self.collectionV.contentOffset.y;
- }
- -(NSMutableArray *)dataArray
- {
- if (!_dataArray) {
- _dataArray =[NSMutableArray array];
- }
- return _dataArray;
- }
- -(NSMutableArray *)listArray
- {
- if (!_listArray) {
- _listArray=[NSMutableArray array];
- }
- return _listArray;
- }
- -(ZBFilterView *)filterView
- {
- if (!_filterView) {
- _filterView=[[ZBFilterView alloc]init];
- __weak typeof(self) weakself = self;
- _filterView.changeruleBlock = ^(NSString * _Nonnull rate, NSString * _Nonnull lowStr, NSString * _Nonnull highStr, BOOL isshow) {
- //isshow为true时是佣金显示
- //需要判断价格筛选还是佣金筛选
- if (isshow) {
- weakself.start_rate=rate;
- }else{
- weakself.lowestPrice = lowStr;
- weakself.highPrice=highStr;
- }
-
- weakself.Page = 1;
- [weakself getProductData];
- [weakself.collectionV reloadData];
- };
- }
- return _filterView;
- }
- @end
|