酷店

KDPSupplyGoodViewController.m 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // KDPSupplyGoodViewController.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/4.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPSupplyGoodViewController.h"
  9. #import "XLPageViewController.h"
  10. #import "XLPageViewControllerConfig.h"
  11. #import "KDPSupplyContentViewController.h"
  12. #import "KDPSearchViewController.h"
  13. #import "KDPClassModel.h"
  14. @interface KDPSupplyGoodViewController ()<XLPageViewControllerDelegate,XLPageViewControllerDataSrouce>
  15. @property (nonatomic, strong) XLPageViewController *pageVC;
  16. @property (nonatomic, strong) NSMutableArray *classArray;
  17. @property (nonatomic, strong) UIImageView *topBackImageView;
  18. @end
  19. @implementation KDPSupplyGoodViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. [self setUpTopView];
  24. self.view.backgroundColor = [UIColor colorWithRGB:0xf4f4f4];
  25. [self requestTopListData];
  26. }
  27. #pragma event handle
  28. - (void)requestTopListData{
  29. NSString *classUrl = [NSString stringWithFormat:@"%@api/goods/listTopBar",KDURL];
  30. [LoadingView showInView:self.view];
  31. [self.classArray removeAllObjects];
  32. [KDPNetworkRequestHTTP postURL:classUrl params:nil success:^(id _Nonnull json) {
  33. [LoadingView dismiss];
  34. NSArray *classArr = [NSArray yy_modelArrayWithClass:[KDPClassModel class] json:json[@"list"]];
  35. [self.classArray addObjectsFromArray:classArr];
  36. [self setUpPageVc];
  37. } failure:^(NSError * _Nonnull error) {
  38. [LoadingView dismiss];
  39. }];
  40. }
  41. - (void)setUpPageVc{
  42. XLPageViewControllerConfig *config = [[XLPageViewControllerConfig alloc] init];
  43. //标题间距
  44. config.titleSpace = 25;
  45. config.titleViewStyle = XLPageTitleViewStyleBasic;
  46. //标题高度
  47. config.titleViewHeight = 40;
  48. //标题选中颜色
  49. config.titleSelectedColor = [UIColor whiteColor];
  50. //标题选中字体
  51. config.titleSelectedFont = [UIFont fontWithName:@"PingFang-SC-Medium" size: 17];
  52. //标题正常颜色
  53. config.titleNormalColor = [UIColor whiteColor];
  54. //标题正常字体
  55. config.titleNormalFont = [UIFont fontWithName:@"PingFang-SC-Medium" size: 14];
  56. config.titleViewInset = UIEdgeInsetsMake(0, 10, 0, 10);
  57. //阴影颜色
  58. config.shadowLineColor = [UIColor whiteColor];
  59. //阴影宽度
  60. config.shadowLineWidth = 24;
  61. //阴影末端是直角
  62. config.shadowLineCap = XLPageShadowLineCapSquare;
  63. //分割线颜色
  64. config.separatorLineHidden = YES;
  65. config.shadowLineHeight = 3;
  66. config.shadowLineAnimationType = XLPageShadowLineAnimationTypeZoom;
  67. self.pageVC = [[XLPageViewController alloc] initWithConfig:config];
  68. self.pageVC.view.bounds = CGRectMake(0, KDStatusHeight + 58, SCREEN_WIDTH, SCREEN_HEIGHT-KDTabBarHeight-KDStatusHeight-58);
  69. self.pageVC.delegate = self;
  70. self.pageVC.dataSource = self;
  71. [self addChildViewController:self.pageVC];
  72. [self.view addSubview:self.pageVC.view];
  73. }
  74. - (void)searchBtnClick:(UIButton *)sender{
  75. KDPSearchViewController *searchVC = [[KDPSearchViewController alloc] init];
  76. [self.navigationController pushViewController:searchVC animated:NO];
  77. }
  78. - (void)setUpTopView{
  79. self.navBar.hidden = YES;
  80. NSInteger height = KDNavBarHeight == 64 ? 135 : 163;
  81. UIView *topBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, height)];
  82. [topBackView setGradientBackgroundWithColors:@[[UIColor colorWithRGB:0xFF235F],[UIColor colorWithRGB:0xFF7676]] locations:@[@0,@1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
  83. [self.view addSubview:topBackView];
  84. UIImageView *imageView = [[UIImageView alloc] initWithFrame:topBackView.bounds];
  85. [self.view addSubview:imageView];
  86. imageView.hidden = YES;
  87. self.topBackImageView = imageView;
  88. // search
  89. UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  90. searchBtn.frame = CGRectMake(15, KDStatusHeight + 7, SCREEN_WIDTH - 30, 31);
  91. searchBtn.backgroundColor = [UIColor whiteColor];
  92. [searchBtn setImage:[UIImage imageNamed:@"search_icon"] forState:UIControlStateNormal];
  93. [searchBtn setTitle:@"搜索你想要的商品" forState:UIControlStateNormal];
  94. [searchBtn setTitleColor:[UIColor colorWithRGB:0x8E8D8D] forState:UIControlStateNormal];
  95. searchBtn.titleLabel.font = FONT_SYS(14);
  96. searchBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
  97. searchBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
  98. searchBtn.layer.cornerRadius = 15.5;
  99. searchBtn.layer.masksToBounds = YES;
  100. searchBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  101. [searchBtn addTarget:self action:@selector(searchBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  102. [self.view addSubview:searchBtn];
  103. }
  104. - (NSMutableArray *)classArray{
  105. if (!_classArray) {
  106. _classArray = [NSMutableArray array];
  107. }
  108. return _classArray;
  109. }
  110. #pragma mark - XLPageViewController datasource and delegate
  111. - (NSInteger)pageViewControllerNumberOfPage{
  112. return self.classArray.count;
  113. }
  114. - (NSString *)pageViewController:(XLPageViewController *)pageViewController titleForIndex:(NSInteger)index{
  115. KDPClassModel *model = self.classArray[index];
  116. return model.name;
  117. }
  118. - (void)pageViewController:(XLPageViewController *)pageViewController didSelectedAtIndex:(NSInteger)index{
  119. KDPClassModel *classModel = self.classArray[index];
  120. if (classModel.backimg.length) {
  121. self.topBackImageView.hidden = NO;
  122. [self.topBackImageView sd_setImageWithURL:[NSURL URLWithString:classModel.backimg]placeholderImage:[UIImage imageNamed:placholderImg]];
  123. } else{
  124. self.topBackImageView.hidden = YES;
  125. }
  126. NSLog(@"%ld",index);
  127. }
  128. - (UIViewController *)pageViewController:(XLPageViewController *)pageViewController viewControllerForIndex:(NSInteger)index{
  129. KDPSupplyContentViewController *contentVC = [[KDPSupplyContentViewController alloc] init];
  130. contentVC.classModel = self.classArray[index];
  131. return contentVC;
  132. }
  133. @end