123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- //
- // LDHistoryViewController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/6/11.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDHistoryViewController.h"
- #import "LDGoodHorzitolCollectionCell.h"
- #import "LDChildGoodModel.h"
- #import "LDHistoryHeaderView.h"
- #import "LDNoDataView.h"
- static NSString *KHorizontalCellId = @"KHorizontalCellId";
- static NSString *KHeaderId = @"KHeaderId";
- @interface LDHistoryViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
- {
- NSInteger _page;
- }
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, strong) NSMutableArray *historyDataArr;
- @property (nonatomic, strong) LDNoDataView *noDataView;
- @end
- @implementation LDHistoryViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self configCollectionView];
- [self requestData];
- }
- - (void)configCollectionView {
-
- _page = 1;
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
- self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-40) collectionViewLayout:flowLayout];
-
- flowLayout.minimumInteritemSpacing = 2;
- [self.collectionView registerClass:[LDGoodHorzitolCollectionCell class] forCellWithReuseIdentifier:KHorizontalCellId];
- [self.collectionView registerClass:[LDHistoryHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KHeaderId];
-
- self.collectionView.backgroundColor = [UIColor whiteColor];
- self.collectionView.showsVerticalScrollIndicator = NO;
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- self.collectionView.bounces = YES;
- // self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- //
- // }];
- [self.view addSubview:self.collectionView];
-
- [self.collectionView addSubview:self.noDataView];
- }
- - (void)requestData {
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/brower/recordList",BaseURL];
- [LDHttp post:url params:nil success:^(id json) {
-
- NSArray *array = json[@"data"];
-
- for (NSArray *childArr in array) {
- NSArray *list = [NSArray yy_modelArrayWithClass:[LDChildGoodModel class] json:childArr];
- [self.historyDataArr addObject:list];
- }
-
-
- [self setNoDataView];
- [self.collectionView reloadData];
-
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)setNoDataView {
- if (self.historyDataArr.count > 0) {
- NSArray *list = self.historyDataArr.firstObject;
- self.noDataView.hidden = list.count > 0;
- }else {
- self.noDataView.hidden = NO;
- }
-
- }
- #pragma mark ============ UICollectionView Delegate && DataSource ==========
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- NSArray *arr = self.historyDataArr[section];
- return arr.count;
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return self.historyDataArr.count;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
-
- return CGSizeMake(SCREEN_WIDTH, 140);
-
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
- return 1;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
- {
- return CGSizeMake(SCREEN_WIDTH, 40);
-
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
- {
- return CGSizeMake(0, 0);
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- LDChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
- LDGoodHorzitolCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KHorizontalCellId forIndexPath:indexPath];
- cell.model = model;
- return cell;
-
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
-
- LDHistoryHeaderView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KHeaderId forIndexPath:indexPath];
- LDChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
- [header setDateWith:model.add_time];
- return header;
-
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
-
- LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
-
- LDChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
- DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id
- is_coupon:model.is_coupon
- coupon_price:model.coupon_price
- price:model.price
- discount_price:model.discount_price
- commission_rate:model.commission_rate
- coupon_start_time:model.coupon_start_time
- coupon_end_time:model.coupon_end_time
- coupon_id:model.coupon_id];
- detail.requestModel = requestModel;
-
- LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:collectAction];
- detail.eventModel = evevtModel;
-
- [self.navigationController pushViewController:detail animated:YES];
-
- }
- - (NSMutableArray *)historyDataArr {
- if (!_historyDataArr) {
- _historyDataArr = [NSMutableArray array];
- }
- return _historyDataArr;
- }
- - (LDNoDataView *)noDataView {
- if (!_noDataView) {
- _noDataView = [[LDNoDataView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 264)];
- _noDataView.hidden = YES;
- _noDataView.center = self.collectionView.center;
- }
- return _noDataView;
- }
- - (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.
- }
- */
- @end
|