123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- //
- // KBHistoryViewController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/6/11.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBHistoryViewController.h"
- #import "KBGoodHorzitolCollectionCell.h"
- #import "KBGoodDetailViewController.h"
- #import "KBChildGoodModel.h"
- #import "KBHistoryHeaderView.h"
- #import "KBNoDataView.h"
- #import "KBNoDataMsgView.h"
- static NSString *KHorizontalCellId = @"KHorizontalCellId";
- static NSString *KHeaderId = @"KHeaderId";
- @interface KBHistoryViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
- {
- NSInteger _page;
- ActivityIndicatorView *_indicatorView;
- }
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, strong) NSMutableArray *historyDataArr;
- @property (nonatomic, strong) KBNoDataMsgView *noDataView;
- @end
- @implementation KBHistoryViewController
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self configNavigationBar];
- [self configCollectionView];
- [self initHUD];
- [self requestData];
- }
- - (void)configNavigationBar {
- _page = 1;
- [self.navigationBar setNavTitle:@"浏览历史"];
- self.navigationBar.backgroundColor = [UIColor changeColor];
- self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
- UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
- [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
- [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- [self.navigationBar setCustomLeftButtons:@[leftBtn]];
- }
- - (void)backAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)initHUD {
-
- ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- _indicatorView = indicatorView;
- }
- - (void)configCollectionView {
-
- _page = 1;
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
- self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) collectionViewLayout:flowLayout];
-
- flowLayout.minimumInteritemSpacing = 2;
- [self.collectionView registerClass:[KBGoodHorzitolCollectionCell class] forCellWithReuseIdentifier:KHorizontalCellId];
- [self.collectionView registerClass:[KBHistoryHeaderView 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];
- [KBHttp post:url params:nil success:^(id json) {
-
- NSArray *array = json[@"data"];
-
- for (NSArray *childArr in array) {
- NSArray *list = [NSArray yy_modelArrayWithClass:[KBChildGoodModel class] json:childArr];
- [self.historyDataArr addObject:list];
- }
-
-
- [self setNoDataView];
- [self.collectionView reloadData];
- [_indicatorView stopAnimating];
- } failure:^(NSError *error) {
- [_indicatorView stopAnimating];
- }];
- }
- - (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
- {
- KBChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
- KBGoodHorzitolCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KHorizontalCellId forIndexPath:indexPath];
- cell.model = model;
- return cell;
-
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
-
- KBHistoryHeaderView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KHeaderId forIndexPath:indexPath];
- KBChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
- [header setDateWith:model.add_time];
- return header;
-
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
-
- KBGoodDetailViewController *detail = [[KBGoodDetailViewController alloc] init];
-
- KBChildGoodModel *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];
- detail.requestModel = requestModel;
-
- KBEventModel *evevtModel = [[KBEventModel 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;
- }
- - (KBNoDataMsgView *)noDataView {
- if (!_noDataView) {
- _noDataView = [[KBNoDataMsgView alloc] initWithFrame:self.collectionView.bounds title:@"您还没有浏览过商品"];
- _noDataView.hidden = YES;
- }
- 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
|