口袋优选

KBHistoryViewController.m 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. //
  2. // KBHistoryViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/6/11.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBHistoryViewController.h"
  9. #import "KBGoodHorzitolCollectionCell.h"
  10. #import "KBGoodDetailViewController.h"
  11. #import "KBChildGoodModel.h"
  12. #import "KBHistoryHeaderView.h"
  13. #import "KBNoDataView.h"
  14. #import "KBNoDataMsgView.h"
  15. static NSString *KHorizontalCellId = @"KHorizontalCellId";
  16. static NSString *KHeaderId = @"KHeaderId";
  17. @interface KBHistoryViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
  18. {
  19. NSInteger _page;
  20. ActivityIndicatorView *_indicatorView;
  21. }
  22. @property (nonatomic, strong) UICollectionView *collectionView;
  23. @property (nonatomic, strong) NSMutableArray *historyDataArr;
  24. @property (nonatomic, strong) KBNoDataMsgView *noDataView;
  25. @end
  26. @implementation KBHistoryViewController
  27. - (void)viewWillAppear:(BOOL)animated {
  28. [super viewWillAppear:animated];
  29. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  30. }
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. [self configNavigationBar];
  34. [self configCollectionView];
  35. [self initHUD];
  36. [self requestData];
  37. }
  38. - (void)configNavigationBar {
  39. _page = 1;
  40. [self.navigationBar setNavTitle:@"浏览历史"];
  41. self.navigationBar.backgroundColor = [UIColor changeColor];
  42. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  43. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  44. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  45. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  46. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  47. }
  48. - (void)backAction {
  49. [self.navigationController popViewControllerAnimated:YES];
  50. }
  51. - (void)initHUD {
  52. ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  53. _indicatorView = indicatorView;
  54. }
  55. - (void)configCollectionView {
  56. _page = 1;
  57. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  58. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) collectionViewLayout:flowLayout];
  59. flowLayout.minimumInteritemSpacing = 2;
  60. [self.collectionView registerClass:[KBGoodHorzitolCollectionCell class] forCellWithReuseIdentifier:KHorizontalCellId];
  61. [self.collectionView registerClass:[KBHistoryHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KHeaderId];
  62. self.collectionView.backgroundColor = [UIColor whiteColor];
  63. self.collectionView.showsVerticalScrollIndicator = NO;
  64. self.collectionView.delegate = self;
  65. self.collectionView.dataSource = self;
  66. self.collectionView.bounces = YES;
  67. // self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  68. //
  69. // }];
  70. [self.view addSubview:self.collectionView];
  71. [self.collectionView addSubview:self.noDataView];
  72. }
  73. - (void)requestData {
  74. NSString *url = [NSString stringWithFormat:@"%@/api/v2/brower/recordList",BaseURL];
  75. [KBHttp post:url params:nil success:^(id json) {
  76. NSArray *array = json[@"data"];
  77. for (NSArray *childArr in array) {
  78. NSArray *list = [NSArray yy_modelArrayWithClass:[KBChildGoodModel class] json:childArr];
  79. [self.historyDataArr addObject:list];
  80. }
  81. [self setNoDataView];
  82. [self.collectionView reloadData];
  83. [_indicatorView stopAnimating];
  84. } failure:^(NSError *error) {
  85. [_indicatorView stopAnimating];
  86. }];
  87. }
  88. - (void)setNoDataView {
  89. if (self.historyDataArr.count > 0) {
  90. NSArray *list = self.historyDataArr.firstObject;
  91. self.noDataView.hidden = list.count > 0;
  92. }else {
  93. self.noDataView.hidden = NO;
  94. }
  95. }
  96. #pragma mark ============ UICollectionView Delegate && DataSource ==========
  97. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  98. {
  99. NSArray *arr = self.historyDataArr[section];
  100. return arr.count;
  101. }
  102. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  103. return self.historyDataArr.count;
  104. }
  105. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  106. return CGSizeMake(SCREEN_WIDTH, 140);
  107. }
  108. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  109. return 1;
  110. }
  111. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  112. {
  113. return CGSizeMake(SCREEN_WIDTH, 40);
  114. }
  115. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  116. {
  117. return CGSizeMake(0, 0);
  118. }
  119. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  120. {
  121. KBChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
  122. KBGoodHorzitolCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KHorizontalCellId forIndexPath:indexPath];
  123. cell.model = model;
  124. return cell;
  125. }
  126. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  127. KBHistoryHeaderView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KHeaderId forIndexPath:indexPath];
  128. KBChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
  129. [header setDateWith:model.add_time];
  130. return header;
  131. }
  132. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  133. KBGoodDetailViewController *detail = [[KBGoodDetailViewController alloc] init];
  134. KBChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
  135. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id
  136. is_coupon:model.is_coupon
  137. coupon_price:model.coupon_price
  138. price:model.price
  139. discount_price:model.discount_price
  140. commission_rate:model.commission_rate
  141. coupon_start_time:model.coupon_start_time
  142. coupon_end_time:model.coupon_end_time];
  143. detail.requestModel = requestModel;
  144. KBEventModel *evevtModel = [[KBEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:collectAction];
  145. detail.eventModel = evevtModel;
  146. [self.navigationController pushViewController:detail animated:YES];
  147. }
  148. - (NSMutableArray *)historyDataArr {
  149. if (!_historyDataArr) {
  150. _historyDataArr = [NSMutableArray array];
  151. }
  152. return _historyDataArr;
  153. }
  154. - (KBNoDataMsgView *)noDataView {
  155. if (!_noDataView) {
  156. _noDataView = [[KBNoDataMsgView alloc] initWithFrame:self.collectionView.bounds title:@"您还没有浏览过商品"];
  157. _noDataView.hidden = YES;
  158. }
  159. return _noDataView;
  160. }
  161. - (void)didReceiveMemoryWarning {
  162. [super didReceiveMemoryWarning];
  163. // Dispose of any resources that can be recreated.
  164. }
  165. /*
  166. #pragma mark - Navigation
  167. // In a storyboard-based application, you will often want to do a little preparation before navigation
  168. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  169. // Get the new view controller using [segue destinationViewController].
  170. // Pass the selected object to the new view controller.
  171. }
  172. */
  173. @end