123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- #import "LDRankListViewController.h"
- #import "LDBuyLimitGoodModel.h"
- #import "LDRankGoodCollectionCell.h"
- static NSString *cellID = @"LDGoodCollectionCell";
- @interface LDRankListViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
- {
- NSInteger _page;
- ActivityIndicatorView *_indicatorView;
- }
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, strong) NSMutableArray *goodsArr;
- @end
- @implementation LDRankListViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self configParam];
- [self configNavigationBar];
- [self configCollectionView];
- [self initHUD];
- [self loadCategoryGoodsList];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
- self.navigationController.navigationBar.hidden = YES;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [_indicatorView stopAnimating];
- }
- #pragma mark - HUD
- - (void)initHUD {
- ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
- _indicatorView = indicatorView;
- [_indicatorView startAnimating];
-
- }
- - (void)configParam {
- _page = 1;
- }
- - (void)configNavigationBar {
- self.view.backgroundColor = [UIColor whiteColor];
- if (self.name.length > 0) {
- [self.navigationBar setNavTitle:self.name];
- }else {
- [self.navigationBar setNavTitle:@"今日热卖榜"];
- }
-
- self.navigationBar.showNavigationBarBottomLine = YES;
- 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 {
-
-
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
- flowLayout.minimumLineSpacing = 5;
- flowLayout.minimumInteritemSpacing = 0;
- flowLayout.headerReferenceSize = CGSizeMake(0, 0);
- self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) collectionViewLayout:flowLayout];
- [self.collectionView registerClass:[LDRankGoodCollectionCell 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 = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- [self loadMoreData];
- }];
- [self.view addSubview: self.collectionView];
-
- }
- - (void)backAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)loadMoreData {
- _page++;
- [self loadCategoryGoodsList];
- }
- - (void)loadCategoryGoodsList {
-
- NSDictionary *para = @{@"platform":@"2",
- @"page":@(_page),
- @"page_size":@"20",
- };
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/hotSaleList",BaseURL];
- [LDHttp post:url params:para success:^(id json) {
-
- NSArray *list = [NSArray yy_modelArrayWithClass:[LDBuyLimitGoodModel class] json:json[@"data"][@"list"]];
- if (list.count > 0) {
- [self.collectionView.mj_footer endRefreshing];
- }else {
- [self.collectionView.mj_footer endRefreshingWithNoMoreData];
- }
- [self.goodsArr addObjectsFromArray:list];
- [self.collectionView reloadData];
-
- [_indicatorView stopAnimating];
-
- } failure:^(NSError *error) {
- [self.collectionView.mj_footer endRefreshing];
- [_indicatorView stopAnimating];
- [MBProgressHUD showMessage:@"加载失败"];
- }];
- }
- #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 {
-
- LDBuyLimitGoodModel *model = self.goodsArr[indexPath.row];
- CGFloat width = (SCREEN_WIDTH-5)/2;
- CGFloat height = width + 112;
- if (model.commission_price.length > 0) {
-
- }
- 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
- {
- LDRankGoodCollectionCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
- LDBuyLimitGoodModel *model = self.goodsArr[indexPath.row];
- cell.model = model;
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
-
-
- LDBuyLimitGoodModel *model = self.goodsArr[indexPath.row];
- LDGoodDetailViewController *detailVC = [[LDGoodDetailViewController alloc] init];
- DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithBuyLimitModel:model];
- detailVC.requestModel = requestModel;
-
- LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:HotSaleAction];
- detailVC.eventModel = evevtModel;
-
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- #pragma mark -------------
- - (NSMutableArray *)goodsArr {
- if (!_goodsArr) {
- _goodsArr = [NSMutableArray array];
- }
- return _goodsArr;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
-
- }
- @end
|