// // YXFindViewController.m // Temperature // // Created by TC on 2025/2/9. // #import "YXFindViewController.h" #import #import #import "YXFindCollectionViewCell.h" #import #import "SDCycleScrollView.h" #import "YXFindItemView.h" #import "YXGoodsModel.h" #import "YXBannerModel.h" #import "RDSControlWebVC.h" @interface YXFindViewController () @property (nonatomic, weak) UICollectionView *collectionView; @property (nonatomic, strong) UICollectionReusableView *headerView; //@property (weak, nonatomic) UIButton *familyBtn; @property (nonatomic, strong) NSMutableArray *bannerArray; @property (nonatomic, strong) NSMutableArray *dataArray; @end @implementation YXFindViewController - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.view.backgroundColor = [UIColor whiteColor]; self.dataArray = [[NSMutableArray alloc]initWithCapacity:5]; [self createCollectionView]; [self getBanner]; [self getGoods]; } -(void)getBanner { RDS_WEAKSELF(weakSelf) [RDSDemoApiHelper rds_getBannerSuccess:^(id responseObject) { if ([responseObject[@"code"] intValue] == 0) { NSDictionary *dataDic = responseObject[@"data"]; NSArray *listArray = dataDic[@"list"]; self.bannerArray = [YXBannerModel mj_objectArrayWithKeyValuesArray:listArray]; [weakSelf.collectionView reloadData]; } else{ [RDSHudShower showErrorWithStatus:responseObject[@"message"]]; } } failure:^(NSError *error) { }]; } -(void)getGoods { RDS_WEAKSELF(weakSelf) [RDSDemoApiHelper rds_getGoodsSuccess:^(id responseObject) { if ([responseObject[@"code"] intValue] == 0) { NSDictionary *dataDic = responseObject[@"data"]; NSArray *listArray = dataDic[@"list"]; weakSelf.dataArray = [YXGoodsModel mj_objectArrayWithKeyValuesArray:listArray]; [weakSelf.collectionView reloadData]; } else{ [RDSHudShower showErrorWithStatus:responseObject[@"message"]]; } } failure:^(NSError *error) { }]; } - (void)createCollectionView { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 10; layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15); layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.sectionHeadersPinToVisibleBounds = false; UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; collectionView.showsHorizontalScrollIndicator = NO; collectionView.showsVerticalScrollIndicator = NO; collectionView.backgroundColor = RDSViewBgColor; [collectionView registerNib:[UINib nibWithNibName:@"YXFindCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"findCellID"]; collectionView.delegate = self; collectionView.dataSource = self; collectionView.pagingEnabled = NO; [self.view addSubview:collectionView]; self.collectionView = collectionView; [collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(@0); make.right.equalTo(@0); make.bottom.equalTo(@0); make.top.equalTo(@0); }]; collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"findHeader"]; // MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(p_getCurrentUserInfo)]; // header.automaticallyChangeAlpha = YES; // header.lastUpdatedTimeLabel.hidden = YES; // self.collectionView.mj_header = header; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGFloat width = SCREEN_WIDTH / 2 - 20; CGSize size = CGSizeMake(width, 255); return size; } #pragma mark - UICollectionViewDelegate - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { YXGoodsModel *model = self.dataArray[indexPath.row]; RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init]; webVc.requestURL = model.detail_url; webVc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:webVc animated:YES]; } #pragma mark - UICollectionViewDataSource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.dataArray.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { YXFindCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"findCellID" forIndexPath:indexPath]; YXGoodsModel *model = self.dataArray[indexPath.row]; NSString *urlStr = [NSString stringWithFormat:@"%@%@",kBaseUrlHeadImg,model.image]; [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:urlStr]]; cell.titleLabel.text = model.name; cell.priceLabel.text = [NSString stringWithFormat:@"¥%@",model.price]; return cell; } // 不允许高亮 - (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{ YXFindCollectionViewCell *cell = (YXFindCollectionViewCell*)[self.collectionView cellForItemAtIndexPath:indexPath]; cell.highlighted = NO; } // 设置header尺寸 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { return CGSizeMake(SCREEN_WIDTH, 430); } // 设置footer尺寸 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{ return CGSizeZero; } //sectionheader - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { if (kind == UICollectionElementKindSectionHeader) { UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"findHeader" forIndexPath:indexPath]; headerView.backgroundColor = RDSViewBgColor; self.headerView = headerView; [self creatHeaderView]; return headerView; } return nil; } -(void)creatHeaderView { UIView *headerBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 430)]; [self.headerView addSubview:headerBgView]; UIImageView *bgImgView = [[UIImageView alloc]init]; bgImgView.image = [UIImage imageNamed:@"my_top_bg"]; [headerBgView addSubview:bgImgView]; [bgImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.left.right.equalTo(@0); }]; // // UIButton *familyBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // [familyBtn setTitle:TheDataManager.current_home_name forState:UIControlStateNormal]; // familyBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18]; // [familyBtn setTitleColor:[UIColor colorWithHexString:@"#1E1E1E"] forState:UIControlStateNormal]; // [familyBtn addTarget:self action:@selector(familyBtnAction:) forControlEvents:UIControlEventTouchUpInside]; // [headerBgView addSubview:familyBtn]; // [familyBtn mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(@15); // make.top.equalTo(@60); // // make.width.equalTo(@150); // make.height.equalTo(@30); // }]; // self.familyBtn = familyBtn; // // UIImageView *imgView = [[UIImageView alloc]init]; // imgView.image = [UIImage imageNamed:@"home_top_arrow"]; // [headerBgView addSubview:imgView]; // [imgView mas_makeConstraints:^(MASConstraintMaker *make) { // make.centerY.equalTo(familyBtn.mas_centerY); // make.left.equalTo(familyBtn.mas_right).offset(2); // make.width.equalTo(@25); // make.height.equalTo(@18); // }]; NSMutableArray *urlArray = [[NSMutableArray alloc]init]; for (YXBannerModel *model in self.bannerArray) { NSString *urlStr = [NSString stringWithFormat:@"%@%@",kBaseUrlHeadImg,model.url]; [urlArray addObject:urlStr]; } SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(15, 80, SCREEN_WIDTH-30, 180) delegate:self placeholderImage:nil]; // cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"]; cycleScrollView.pageDotImage = [UIImage imageNamed:@"pageControlDot"]; cycleScrollView.imageURLStringsGroup = urlArray; cycleScrollView.layer.cornerRadius = 8; cycleScrollView.layer.masksToBounds = YES; [headerBgView addSubview:cycleScrollView]; CGFloat width = SCREEN_WIDTH/4.0; YXFindItemView *serviceView = [[YXFindItemView alloc]init]; serviceView.picImgView.image = [UIImage imageNamed:@"find_service"]; serviceView.textLabel.text = @"服务"; [headerBgView addSubview:serviceView]; [serviceView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(cycleScrollView.mas_bottom).offset(20); make.left.equalTo(@0); make.width.equalTo(@(width)); make.height.equalTo(@80); }]; UITapGestureRecognizer *serviceTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickServiceItemAction)]; [serviceView addGestureRecognizer:serviceTap]; YXFindItemView *shopView = [[YXFindItemView alloc]init]; shopView.picImgView.image = [UIImage imageNamed:@"find_shop"]; shopView.textLabel.text = @"商城"; [headerBgView addSubview:shopView]; [shopView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(serviceView.mas_top); make.left.equalTo(serviceView.mas_right); make.width.equalTo(@(width)); make.height.equalTo(@80); }]; UITapGestureRecognizer *shopTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickShopItemAction)]; [shopView addGestureRecognizer:shopTap]; YXFindItemView *activityView = [[YXFindItemView alloc]init]; activityView.picImgView.image = [UIImage imageNamed:@"find_activity"]; activityView.textLabel.text = @"活动"; [headerBgView addSubview:activityView]; [activityView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(serviceView.mas_top); make.left.equalTo(shopView.mas_right); make.width.equalTo(@(width)); make.height.equalTo(@80); }]; UITapGestureRecognizer *activityTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickActivityItemAction)]; [activityView addGestureRecognizer:activityTap]; YXFindItemView *moreView = [[YXFindItemView alloc]init]; moreView.picImgView.image = [UIImage imageNamed:@"find_more"]; moreView.textLabel.text = @"更多"; [headerBgView addSubview:moreView]; [moreView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(serviceView.mas_top); make.left.equalTo(activityView.mas_right); make.width.equalTo(@(width)); make.height.equalTo(@80); }]; UITapGestureRecognizer *moreTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickMoreItemAction)]; [moreView addGestureRecognizer:moreTap]; UIImageView *hotImgView = [[UIImageView alloc]init]; hotImgView.image = [UIImage imageNamed:@"find_hot"]; [headerBgView addSubview:hotImgView]; [hotImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(serviceView.mas_bottom).offset(30); make.left.equalTo(@15); make.width.equalTo(@12); make.height.equalTo(@16); }]; UILabel *textLabel = [[UILabel alloc]init]; textLabel.text = @"热门推荐"; textLabel.font = [UIFont boldSystemFontOfSize:16]; textLabel.textColor = [UIColor colorWithHexString:@"#333333"]; [headerBgView addSubview:textLabel]; [textLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(hotImgView.mas_centerY); make.left.equalTo(hotImgView.mas_right).offset(3); make.width.equalTo(@150); make.height.equalTo(@30); }]; } -(void)clickServiceItemAction { [self openWebVcWithUrl:@"findMore/serviceHome"]; } -(void)clickShopItemAction { [self openWebVcWithUrl:@"findMore/mallHome"]; } -(void)clickActivityItemAction { [self openWebVcWithUrl:@"findMore/activityHome"]; } -(void)clickMoreItemAction { [self openWebVcWithUrl:@"findMore/moreHome"]; } -(void)openWebVcWithUrl:(NSString *)path { RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init]; webVc.requestURL = [NSString stringWithFormat:@"%@%@",kBaseUrlH5,path]; webVc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:webVc animated:YES]; } #pragma mark - SDCycleScrollViewDelegate - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index { NSLog(@"---点击了第%ld张图片", (long)index); if (index < self.bannerArray.count) { YXBannerModel *model = self.bannerArray[index]; RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init]; webVc.requestURL = model.detail_url; webVc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:webVc animated:YES]; } } #pragma mark - 菜单 - (void)familyBtnAction:(UIButton *)button { NSMutableArray *titleArray = [[NSMutableArray alloc]initWithCapacity:5]; for (int i = 0; i < TheDataManager.homes.count; i++) { RDSHomeModel *model = TheDataManager.homes[i]; [titleArray addObject:model.name]; } [YBPopupMenu showRelyOnView:button titles:titleArray icons:nil menuWidth:130 otherSettings:^(YBPopupMenu *popupMenu) { popupMenu.delegate = self; popupMenu.animationManager.duration = 0.25; popupMenu.textColor = [UIColor colorWithHexString:@"#1F1F1F"]; }]; } //#pragma mark - YPPopupMenuDelegate //- (void)ybPopupMenu:(YBPopupMenu *)ybPopupMenu didSelectedAtIndex:(NSInteger)index //{ // RDSHomeModel *model = TheDataManager.homes[index]; // [self.familyBtn setTitle:model.name forState:UIControlStateNormal]; // // //} /* #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