123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- //
- // KDPSupplyContentViewController.m
- // KuDianProject
- //
- // Created by admin on 2019/7/4.
- // Copyright © 2019 KDP. All rights reserved.
- //
- #import "KDPSupplyContentViewController.h"
- #import "KDPSupplyCommentViewCell.h"
- #import "KDPSupplyGoodCollectionViewCell.h"
- #import "KDPSupplyContentReusableView.h"
- #import "KDPScreenViewController.h"
- #import <UIViewController+CWLateralSlide.h>
- #import "KDPSupplyListViewController.h"
- #import "KDPNoticeViewController.h"
- @interface KDPSupplyContentViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,KDPSupplyCommentViewCellDelegate,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, assign) NSInteger page;
- @property (nonatomic, strong) NSMutableDictionary *mutabParams;
- @property (nonatomic, strong) NSMutableArray *dataSource;
- @property (nonatomic, strong) NSMutableArray *topGoodList;
- @property (nonatomic, assign) BOOL shouldHiddenScreen;
- @end
- @implementation KDPSupplyContentViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self setUpUI];
- self.shouldHiddenScreen = YES;
- if ([self.classModel.type isEqualToString:@"cate"]) {
- [self requestTopListWithGoodId:self.classModel.Id];
- }
- self.page = 1;
- [self requestGoodlistData];
- }
- - (void)setUpUI{
- self.navBar.hidden = YES;
- self.view.backgroundColor = [UIColor clearColor];
- [self.view addSubview:self.collectionView];
- }
- #pragma mark 网络请求
- - (void)requestGoodlistData{
- NSString *goodlistUrl = [NSString stringWithFormat:@"%@api/goods/listGoods",KDURL];
- [self.mutabParams setValue:@(self.page) forKey:@"page"];
- [KDPNetworkRequestHTTP postURL:goodlistUrl params:self.mutabParams success:^(id _Nonnull json) {
- [LoadingView dismiss];
- NSArray *array =[NSArray yy_modelArrayWithClass:[KDPGoodsModel class] json:json[@"data"]];
- [self.collectionView.mj_footer endRefreshing];
- [self.collectionView.mj_header endRefreshing];
- if (self.page == 1) {
- [self.dataSource removeAllObjects];
- }
- if (array.count > 0) {
- [self.dataSource addObjectsFromArray:array];
- }
- if (array.count == 0) {
- [self.collectionView.mj_footer endRefreshingWithNoMoreData];
- }
- [self.collectionView reloadData];
- } failure:^(NSError * _Nonnull error) {
- [self.collectionView.mj_footer endRefreshing];
- [self.collectionView.mj_header endRefreshing];
- [LoadingView dismiss];
- }];
- }
- - (void)requestTopListWithGoodId:(NSString *)Id{
- [LoadingView showInView:self.view];
- NSString *childListUrl = [NSString stringWithFormat:@"%@api/goods/childList",KDURL];
- [KDPNetworkRequestHTTP postURL:childListUrl params:@{@"pid":Id} success:^(id _Nonnull json) {
- [self.topGoodList removeAllObjects];
- NSArray *array =[NSArray yy_modelArrayWithClass:[KDPClassModel class] json:json[@"list"]];
- [self.topGoodList addObjectsFromArray:array];
- [LoadingView dismiss];
- [self.collectionView reloadData];
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- }];
- }
- #pragma mark - lazy load
- - (UICollectionView *)collectionView{
- if (!_collectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.minimumLineSpacing = 0;
- layout.sectionHeadersPinToVisibleBounds = YES;
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-KDTabBarHeight-KDStatusHeight-88) collectionViewLayout:layout];
- _collectionView.backgroundColor = [UIColor clearColor];
- _collectionView.showsHorizontalScrollIndicator = NO;
- _collectionView.showsVerticalScrollIndicator = NO;
- _collectionView.delegate = self;
- _collectionView.dataSource = self;
- _collectionView.emptyDataSetSource = self;
- _collectionView.emptyDataSetDelegate = self;
- [_collectionView registerClass:[KDPSupplyCommentViewCell class] forCellWithReuseIdentifier:NSStringFromClass([KDPSupplyCommentViewCell class])];
- [_collectionView registerClass:[KDPSupplyGoodCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([KDPSupplyGoodCollectionViewCell class])];
- [_collectionView registerClass:[KDPSupplyContentReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([KDPSupplyContentReusableView class])];
- _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- self.page = 1;
- [self requestGoodlistData];
- }];
- _collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- self.page ++;
- [self requestGoodlistData];
- }];
- }
- return _collectionView;
- }
- - (NSMutableDictionary *)mutabParams{
- if (!_mutabParams) {
- _mutabParams = [NSMutableDictionary dictionaryWithDictionary:@{@"page":@(self.page),@"id":self.classModel.Id,@"type":self.classModel.type,@"start_price":@"",@"end_price":@"",@"start_tk_rate":@""}];
- }
- return _mutabParams;
- }
- - (NSMutableArray *)dataSource{
- if (!_dataSource) {
- _dataSource = [NSMutableArray array];
- }
- return _dataSource;
- }
- - (NSMutableArray *)topGoodList{
- if (!_topGoodList) {
- _topGoodList = [NSMutableArray array];
- }
- return _topGoodList;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- if (indexPath.section == 0) {
- KDPSupplyCommentViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KDPSupplyCommentViewCell class]) forIndexPath:indexPath];
- cell.delegate = self;
- cell.dataArray = self.topGoodList;
- return cell;
- }
-
- if (indexPath.section == 1) {
- KDPSupplyGoodCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KDPSupplyGoodCollectionViewCell class]) forIndexPath:indexPath];
- [cell configCellWithModel:self.dataSource[indexPath.row] indexPath:indexPath];
- return cell;
- }
- return nil;
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
- return 2;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- KDPGoodDetailVC *detailVC = [[KDPGoodDetailVC alloc] init];
- detailVC.model = self.dataSource[indexPath.row];
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- if (section == 0) {
- if (!self.topGoodList.count) {
- return 0;
- }
- return 1;
- }
-
- if (section == 1) {
- return self.dataSource.count;
- }
-
- return 0;
-
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
- if (indexPath.section == 0) {
- if (self.topGoodList.count > 4) {
- return CGSizeMake(SCREEN_WIDTH-20, 200);
- } else if(self.topGoodList.count > 0 && self.topGoodList.count < 4) {
- return CGSizeMake(SCREEN_WIDTH-20, 110);
- } else{
- return CGSizeMake(SCREEN_WIDTH, 0.1f);
- }
- }
- if (indexPath.section == 1) {
- return CGSizeMake((SCREEN_WIDTH-25)/2, 284);
- }
- return CGSizeMake(SCREEN_WIDTH, 0.1f);
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
- if (section == 1) {
- return CGSizeMake(SCREEN_WIDTH, 33);
- }
- return CGSizeZero;
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
- if (section == 0) {
- if (!self.topGoodList.count) {
- return UIEdgeInsetsMake(0, 0, 5, 0);
- }
- return UIEdgeInsetsMake(10, 10, 10, 10);
- }
- if (section == 1) {
- return UIEdgeInsetsMake(7, 10, 0, 10);
- }
- return UIEdgeInsetsZero;
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
- if (section == 1) {
- return 5;
- }
- return 0;
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
- if (section == 1) {
- return 5;
- }
- return 0;
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
- KDPSupplyContentReusableView *reusAbleView;
- if (kind == UICollectionElementKindSectionHeader) {
- if (indexPath.section == 1) {
- reusAbleView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([KDPSupplyContentReusableView class]) forIndexPath:indexPath];
- WeakSelf(weakSelf);
- reusAbleView.hidden = NO;
- if (self.dataSource.count ==0 && self.shouldHiddenScreen == YES) {
- reusAbleView.hidden = YES;
- }
- __weak KDPSupplyContentReusableView *weakReusAbleView = reusAbleView;
- reusAbleView.changeBlock = ^(BOOL isPrice) {
- weakSelf.shouldHiddenScreen = NO;
- KDPScreenViewController *screenVC = [[KDPScreenViewController alloc] initWithPrice:isPrice];
- screenVC.params = weakSelf.mutabParams;
- screenVC.resetBlock = ^(BOOL isPrice) {
- if (isPrice == YES) {
- [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStylePrice Color:[UIColor colorWithHex:0x333333] text:@"价格筛选"];
- [self.mutabParams setValue:@"" forKey:@"start_price"];
- [self.mutabParams setValue:@"" forKey:@"end_price"];
- } else{
- [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStyleProfit Color:[UIColor colorWithHex:0x333333] text:@"利润筛选"];
- [self.mutabParams setValue:@"" forKey:@"start_tk_rate"];
- }
- [weakSelf.collectionView.mj_header beginRefreshing];
- };
- screenVC.profitBlock = ^(NSString *baseScale) {
- if (!baseScale.length) {
- [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStyleProfit Color:[UIColor colorWithHex:0x333333] text:[NSString stringWithFormat:@"利润筛选"]];
- [self.mutabParams setValue:@"" forKey:@"start_tk_rate"];
- } else{
- [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStyleProfit Color:[UIColor baseColor] text:[NSString stringWithFormat:@"佣金%@%%以上",baseScale]];
- [self.mutabParams setValue:baseScale forKey:@"start_tk_rate"];
- }
- [weakSelf.collectionView.mj_header beginRefreshing];
- };
- screenVC.priceBlock = ^(NSString *minPrice, NSString *maxPrice) {
- if (minPrice.length != 0 || maxPrice.length != 0) {
- if (minPrice.length == 0) {
- minPrice = @"0";
- }
- NSString *price=[NSString stringWithFormat:@"价格%@-%@元",minPrice,maxPrice];
- if (maxPrice.integerValue == 0 || [maxPrice intValue] <= [minPrice intValue]) {
- maxPrice = @"";
- price=[NSString stringWithFormat:@"价格%@元以上",minPrice];
- }
-
- [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStylePrice Color:[UIColor baseColor] text:price];
- } else{
- [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStylePrice Color:[UIColor colorWithHex:0x333333] text:@"价格筛选"];
- }
- [weakSelf.mutabParams setValue:minPrice forKey:@"start_price"];
- [weakSelf.mutabParams setValue:maxPrice forKey:@"end_price"];
- [weakSelf.collectionView.mj_header beginRefreshing];
- };
- CWLateralSlideConfiguration *conf = [CWLateralSlideConfiguration configurationWithDistance:0 maskAlpha:0.7 scaleY:1 direction:CWDrawerTransitionFromRight backImage:nil];
- conf.distance=SCREEN_WIDTH/3*2;
- [weakSelf cw_showDrawerViewController:screenVC animationType:0 configuration:conf];
- };
- return reusAbleView;
- }
- }
- return nil;
- }
- #pragma DZNEmptyDataSetSource and delegate
- - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
- return [UIImage imageNamed:@"no_order"];
- }
- - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
- return YES;
- }
- - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
- return 30;
- }
- - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
- return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
- }
- - (void)commentCollectionView:(UICollectionView *)collectionView didSelectIndex:(NSInteger )index{
- KDPSupplyListViewController *listVC = [[KDPSupplyListViewController alloc] init];
- listVC.mode = self.topGoodList[index];
- [self.navigationController pushViewController:listVC animated:YES];
- }
- @end
|