酷店

KDPSupplyListViewController.m 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //
  2. // KDPSupplyListViewController.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/11.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPSupplyListViewController.h"
  9. #import "KDPSupplyContentReusableView.h"
  10. #import "KDPRecommendGoodCell.h"
  11. #import "KDPScreenViewController.h"
  12. @interface KDPSupplyListViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
  13. @property (nonatomic, strong) UICollectionView *collectionView;
  14. @property (nonatomic, strong) NSMutableArray *dataSource;
  15. @property (nonatomic, assign) NSInteger page;
  16. @property (nonatomic, strong) NSMutableDictionary *params;
  17. @end
  18. @implementation KDPSupplyListViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. [self setupNav];
  23. [self.view addSubview:self.collectionView];
  24. [self requestGoodData];
  25. }
  26. - (void)setupNav{
  27. self.navBar.backgroundColor = [UIColor whiteColor];
  28. UIButton *returnBtn =[[UIButton alloc]initWithFrame:CGRectMake(15, KDNavBarHeight - 13-18, 11, 18)];
  29. [returnBtn addTarget:self action:@selector(returnClickBtn) forControlEvents:UIControlEventTouchUpInside];
  30. [returnBtn setImage:[UIImage imageNamed:@"return_black"] forState:UIControlStateNormal];
  31. returnBtn.adjustsImageWhenHighlighted = NO;
  32. [self.navBar addSubview:returnBtn];
  33. self.navBar.navTitleLabel.textColor = [UIColor colorWithHex:0x333333];
  34. self.navBar.navTitleLabel.text = self.mode.name;
  35. }
  36. - (void)requestGoodData{
  37. if (![KDPAccountTool isLogin]) {
  38. return;
  39. }
  40. [self.params setValue:[NSString stringWithFormat:@"%ld",(long)self.page] forKey:@"page"];
  41. [LoadingView showInView:self.view];
  42. NSString *getGoodUrl = [NSString stringWithFormat:@"%@api/goods/search",KDURL];
  43. [KDPNetworkRequestHTTP postURL:getGoodUrl params:self.params success:^(id _Nonnull json) {
  44. [LoadingView dismiss];
  45. NSArray *dataArr = [NSArray yy_modelArrayWithClass:[KDPGoodsModel class] json:json[@"data"]];
  46. if (self.page == 1) {
  47. [self.dataSource removeAllObjects];
  48. }
  49. if (dataArr.count > 0) {
  50. [self.dataSource addObjectsFromArray:dataArr];
  51. } else{
  52. [self.collectionView.mj_footer endRefreshingWithNoMoreData];
  53. }
  54. [self.collectionView.mj_footer endRefreshing];
  55. [self.collectionView.mj_header endRefreshing];
  56. [self.collectionView reloadData];
  57. } failure:^(NSError * _Nonnull error) {
  58. [LoadingView dismiss];
  59. }];
  60. }
  61. - (void)returnClickBtn{
  62. [self.navigationController popViewControllerAnimated:YES];
  63. }
  64. - (void)viewWillAppear:(BOOL)animated{
  65. [super viewWillAppear:animated];
  66. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
  67. }
  68. - (void)viewWillDisappear:(BOOL)animated{
  69. [super viewWillDisappear:animated];
  70. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  71. }
  72. - (UICollectionView *)collectionView{
  73. if (!_collectionView) {
  74. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  75. flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH, 130);
  76. flowLayout.minimumLineSpacing = 0;
  77. flowLayout.minimumInteritemSpacing = 0;
  78. flowLayout.sectionHeadersPinToVisibleBounds = YES;
  79. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, KDNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight) collectionViewLayout:flowLayout];
  80. _collectionView.showsVerticalScrollIndicator = NO;
  81. _collectionView.showsHorizontalScrollIndicator = NO;
  82. [_collectionView registerClass:[KDPRecommendGoodCell class] forCellWithReuseIdentifier:NSStringFromClass([KDPRecommendGoodCell class])];
  83. [_collectionView registerClass:[KDPSupplyContentReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([KDPSupplyContentReusableView class])];
  84. _collectionView.backgroundColor = [UIColor whiteColor];
  85. _collectionView.delegate = self;
  86. _collectionView.dataSource = self;
  87. _collectionView.emptyDataSetDelegate = self;
  88. _collectionView.emptyDataSetSource = self;
  89. _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  90. self.page = 1;
  91. [self requestGoodData];
  92. }];
  93. _collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  94. self.page ++;
  95. [self requestGoodData];
  96. }];
  97. }
  98. return _collectionView;
  99. }
  100. - (NSMutableArray *)dataSource{
  101. if (!_dataSource) {
  102. _dataSource = [NSMutableArray array];
  103. }
  104. return _dataSource;
  105. }
  106. - (NSMutableDictionary *)params{
  107. if (!_params) {
  108. _params = [NSMutableDictionary dictionaryWithDictionary:@{@"page":@(self.page),@"id":self.mode.Id,@"type":self.mode.type,@"start_price":@"",@"end_price":@"",@"start_tk_rate":@""}];
  109. }
  110. return _params;
  111. }
  112. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  113. KDPSupplyContentReusableView *reusAbleView;
  114. if (kind == UICollectionElementKindSectionHeader) {
  115. reusAbleView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([KDPSupplyContentReusableView class]) forIndexPath:indexPath];
  116. WeakSelf(weakSelf);
  117. __weak KDPSupplyContentReusableView *weakReusAbleView = reusAbleView;
  118. reusAbleView.changeBlock = ^(BOOL isPrice) {
  119. KDPScreenViewController *screenVC = [[KDPScreenViewController alloc] initWithPrice:isPrice];
  120. screenVC.params = weakSelf.params;
  121. screenVC.view.frame = CGRectMake(91, 0, SCREEN_WIDTH-91, SCREEN_HEIGHT);
  122. screenVC.resetBlock = ^(BOOL isPrice) {
  123. if (isPrice == YES) {
  124. [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStylePrice Color:[UIColor colorWithHex:0x333333] text:@"价格筛选"];
  125. [self.params setValue:@"" forKey:@"start_price"];
  126. [self.params setValue:@"" forKey:@"end_price"];
  127. } else{
  128. [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStyleProfit Color:[UIColor colorWithHex:0x333333] text:@"利润筛选"];
  129. [self.params setValue:@"" forKey:@"start_tk_rate"];
  130. }
  131. [weakSelf.collectionView.mj_header beginRefreshing];
  132. };
  133. screenVC.profitBlock = ^(NSString *baseScale) {
  134. if (!baseScale.length) {
  135. [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStyleProfit Color:[UIColor colorWithHex:0x333333] text:[NSString stringWithFormat:@"利润筛选"]];
  136. [self.params setValue:@"" forKey:@"start_tk_rate"];
  137. } else{
  138. [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStyleProfit Color:[UIColor baseColor] text:[NSString stringWithFormat:@"佣金%@%%以上",baseScale]];
  139. [self.params setValue:baseScale forKey:@"start_tk_rate"];
  140. }
  141. [weakSelf.collectionView.mj_header beginRefreshing];
  142. };
  143. screenVC.priceBlock = ^(NSString *minPrice, NSString *maxPrice) {
  144. if (minPrice.length != 0 || maxPrice.length != 0) {
  145. if (minPrice.length == 0) {
  146. minPrice = @"0";
  147. }
  148. NSString *price=[NSString stringWithFormat:@"价格%@-%@元",minPrice,maxPrice];
  149. if (maxPrice.integerValue == 0 || [maxPrice intValue] <= [minPrice intValue]) {
  150. price=[NSString stringWithFormat:@"价格%@元以上",minPrice];
  151. maxPrice = @"";
  152. }
  153. [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStylePrice Color:[UIColor baseColor] text:price];
  154. } else{
  155. [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStylePrice Color:[UIColor colorWithHex:0x333333] text:@"价格筛选"];
  156. }
  157. [weakSelf.params setValue:minPrice forKey:@"start_price"];
  158. [weakSelf.params setValue:maxPrice forKey:@"end_price"];
  159. [weakSelf.collectionView.mj_header beginRefreshing];
  160. };
  161. CWLateralSlideConfiguration *conf = [CWLateralSlideConfiguration configurationWithDistance:0 maskAlpha:0.7 scaleY:1 direction:CWDrawerTransitionFromRight backImage:nil];
  162. [weakSelf cw_showDrawerViewController:screenVC animationType:0 configuration:conf];
  163. };
  164. return reusAbleView;
  165. }
  166. return reusAbleView;
  167. }
  168. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  169. if (section == 0) {
  170. return CGSizeMake(SCREEN_WIDTH, 33);
  171. }
  172. return CGSizeZero;
  173. }
  174. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  175. return 1;
  176. }
  177. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  178. return self.dataSource.count;
  179. }
  180. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  181. KDPRecommendGoodCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KDPRecommendGoodCell class]) forIndexPath:indexPath];
  182. cell.model = self.dataSource[indexPath.row];
  183. return cell;
  184. }
  185. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
  186. return [UIImage imageNamed:@"no_order"];
  187. }
  188. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  189. return YES;
  190. }
  191. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
  192. return 50;
  193. }
  194. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  195. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  196. }
  197. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  198. KDPGoodDetailVC *detailVC = [[KDPGoodDetailVC alloc] init];
  199. detailVC.model = self.dataSource[indexPath.row];
  200. [self.navigationController pushViewController:detailVC animated:YES];
  201. }
  202. @end