YXFindViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. //
  2. // YXFindViewController.m
  3. // Temperature
  4. //
  5. // Created by TC on 2025/2/9.
  6. //
  7. #import "YXFindViewController.h"
  8. #import <MJRefresh/MJRefresh.h>
  9. #import <YBPopupMenu/YBPopupMenu.h>
  10. #import "YXFindCollectionViewCell.h"
  11. #import <SDWebImage/SDWebImage.h>
  12. #import "SDCycleScrollView.h"
  13. #import "YXFindItemView.h"
  14. #import "YXGoodsModel.h"
  15. #import "YXBannerModel.h"
  16. #import "RDSControlWebVC.h"
  17. @interface YXFindViewController ()<UICollectionViewDelegateFlowLayout,UICollectionViewDelegate, UICollectionViewDataSource,YBPopupMenuDelegate,SDCycleScrollViewDelegate>
  18. @property (nonatomic, weak) UICollectionView *collectionView;
  19. @property (nonatomic, strong) UICollectionReusableView *headerView;
  20. //@property (weak, nonatomic) UIButton *familyBtn;
  21. @property (nonatomic, strong) NSMutableArray *bannerArray;
  22. @property (nonatomic, strong) NSMutableArray *dataArray;
  23. @end
  24. @implementation YXFindViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. self.fd_prefersNavigationBarHidden = YES;
  28. self.view.backgroundColor = [UIColor whiteColor];
  29. self.dataArray = [[NSMutableArray alloc]initWithCapacity:5];
  30. [self createCollectionView];
  31. [self getBanner];
  32. [self getGoods];
  33. }
  34. -(void)getBanner
  35. {
  36. RDS_WEAKSELF(weakSelf)
  37. [RDSDemoApiHelper rds_getBannerSuccess:^(id responseObject) {
  38. if ([responseObject[@"code"] intValue] == 0) {
  39. NSDictionary *dataDic = responseObject[@"data"];
  40. NSArray *listArray = dataDic[@"list"];
  41. self.bannerArray = [YXBannerModel mj_objectArrayWithKeyValuesArray:listArray];
  42. [weakSelf.collectionView reloadData];
  43. } else{
  44. [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
  45. }
  46. } failure:^(NSError *error) {
  47. }];
  48. }
  49. -(void)getGoods
  50. {
  51. RDS_WEAKSELF(weakSelf)
  52. [RDSDemoApiHelper rds_getGoodsSuccess:^(id responseObject) {
  53. if ([responseObject[@"code"] intValue] == 0) {
  54. NSDictionary *dataDic = responseObject[@"data"];
  55. NSArray *listArray = dataDic[@"list"];
  56. weakSelf.dataArray = [YXGoodsModel mj_objectArrayWithKeyValuesArray:listArray];
  57. [weakSelf.collectionView reloadData];
  58. } else{
  59. [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
  60. }
  61. } failure:^(NSError *error) {
  62. }];
  63. }
  64. - (void)createCollectionView {
  65. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  66. layout.minimumLineSpacing = 10;
  67. layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
  68. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  69. layout.sectionHeadersPinToVisibleBounds = false;
  70. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  71. collectionView.showsHorizontalScrollIndicator = NO;
  72. collectionView.showsVerticalScrollIndicator = NO;
  73. collectionView.backgroundColor = RDSViewBgColor;
  74. [collectionView registerNib:[UINib nibWithNibName:@"YXFindCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"findCellID"];
  75. collectionView.delegate = self;
  76. collectionView.dataSource = self;
  77. collectionView.pagingEnabled = NO;
  78. [self.view addSubview:collectionView];
  79. self.collectionView = collectionView;
  80. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.left.equalTo(@0);
  82. make.right.equalTo(@0);
  83. make.bottom.equalTo(@0);
  84. make.top.equalTo(@0);
  85. }];
  86. collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  87. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"findHeader"];
  88. // MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(p_getCurrentUserInfo)];
  89. // header.automaticallyChangeAlpha = YES;
  90. // header.lastUpdatedTimeLabel.hidden = YES;
  91. // self.collectionView.mj_header = header;
  92. }
  93. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  94. {
  95. CGFloat width = SCREEN_WIDTH / 2 - 20;
  96. CGSize size = CGSizeMake(width, 255);
  97. return size;
  98. }
  99. #pragma mark - UICollectionViewDelegate
  100. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  101. YXGoodsModel *model = self.dataArray[indexPath.row];
  102. RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init];
  103. webVc.requestURL = model.detail_url;
  104. webVc.hidesBottomBarWhenPushed = YES;
  105. [self.navigationController pushViewController:webVc animated:YES];
  106. }
  107. #pragma mark - UICollectionViewDataSource
  108. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  109. return 1;
  110. }
  111. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  112. return self.dataArray.count;
  113. }
  114. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  115. {
  116. YXFindCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"findCellID" forIndexPath:indexPath];
  117. YXGoodsModel *model = self.dataArray[indexPath.row];
  118. NSString *urlStr = [NSString stringWithFormat:@"%@%@",kBaseUrlHeadImg,model.image];
  119. [cell.picImageView sd_setImageWithURL:[NSURL URLWithString:urlStr]];
  120. cell.titleLabel.text = model.name;
  121. cell.priceLabel.text = [NSString stringWithFormat:@"¥%@",model.price];
  122. return cell;
  123. }
  124. // 不允许高亮
  125. - (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
  126. YXFindCollectionViewCell *cell = (YXFindCollectionViewCell*)[self.collectionView cellForItemAtIndexPath:indexPath];
  127. cell.highlighted = NO;
  128. }
  129. // 设置header尺寸
  130. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  131. return CGSizeMake(SCREEN_WIDTH, 430);
  132. }
  133. // 设置footer尺寸
  134. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
  135. return CGSizeZero;
  136. }
  137. //sectionheader
  138. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  139. if (kind == UICollectionElementKindSectionHeader) {
  140. UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"findHeader" forIndexPath:indexPath];
  141. headerView.backgroundColor = RDSViewBgColor;
  142. self.headerView = headerView;
  143. [self creatHeaderView];
  144. return headerView;
  145. }
  146. return nil;
  147. }
  148. -(void)creatHeaderView
  149. {
  150. UIView *headerBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 430)];
  151. [self.headerView addSubview:headerBgView];
  152. UIImageView *bgImgView = [[UIImageView alloc]init];
  153. bgImgView.image = [UIImage imageNamed:@"my_top_bg"];
  154. [headerBgView addSubview:bgImgView];
  155. [bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  156. make.top.bottom.left.right.equalTo(@0);
  157. }];
  158. //
  159. // UIButton *familyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  160. // [familyBtn setTitle:TheDataManager.current_home_name forState:UIControlStateNormal];
  161. // familyBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18];
  162. // [familyBtn setTitleColor:[UIColor colorWithHexString:@"#1E1E1E"] forState:UIControlStateNormal];
  163. // [familyBtn addTarget:self action:@selector(familyBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  164. // [headerBgView addSubview:familyBtn];
  165. // [familyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  166. // make.left.equalTo(@15);
  167. // make.top.equalTo(@60);
  168. // // make.width.equalTo(@150);
  169. // make.height.equalTo(@30);
  170. // }];
  171. // self.familyBtn = familyBtn;
  172. //
  173. // UIImageView *imgView = [[UIImageView alloc]init];
  174. // imgView.image = [UIImage imageNamed:@"home_top_arrow"];
  175. // [headerBgView addSubview:imgView];
  176. // [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  177. // make.centerY.equalTo(familyBtn.mas_centerY);
  178. // make.left.equalTo(familyBtn.mas_right).offset(2);
  179. // make.width.equalTo(@25);
  180. // make.height.equalTo(@18);
  181. // }];
  182. NSMutableArray *urlArray = [[NSMutableArray alloc]init];
  183. for (YXBannerModel *model in self.bannerArray) {
  184. NSString *urlStr = [NSString stringWithFormat:@"%@%@",kBaseUrlHeadImg,model.url];
  185. [urlArray addObject:urlStr];
  186. }
  187. SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(15, 80, SCREEN_WIDTH-30, 180) delegate:self placeholderImage:nil];
  188. // cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"];
  189. cycleScrollView.pageDotImage = [UIImage imageNamed:@"pageControlDot"];
  190. cycleScrollView.imageURLStringsGroup = urlArray;
  191. cycleScrollView.layer.cornerRadius = 8;
  192. cycleScrollView.layer.masksToBounds = YES;
  193. [headerBgView addSubview:cycleScrollView];
  194. CGFloat width = SCREEN_WIDTH/4.0;
  195. YXFindItemView *serviceView = [[YXFindItemView alloc]init];
  196. serviceView.picImgView.image = [UIImage imageNamed:@"find_service"];
  197. serviceView.textLabel.text = @"服务";
  198. [headerBgView addSubview:serviceView];
  199. [serviceView mas_makeConstraints:^(MASConstraintMaker *make) {
  200. make.top.equalTo(cycleScrollView.mas_bottom).offset(20);
  201. make.left.equalTo(@0);
  202. make.width.equalTo(@(width));
  203. make.height.equalTo(@80);
  204. }];
  205. UITapGestureRecognizer *serviceTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickServiceItemAction)];
  206. [serviceView addGestureRecognizer:serviceTap];
  207. YXFindItemView *shopView = [[YXFindItemView alloc]init];
  208. shopView.picImgView.image = [UIImage imageNamed:@"find_shop"];
  209. shopView.textLabel.text = @"商城";
  210. [headerBgView addSubview:shopView];
  211. [shopView mas_makeConstraints:^(MASConstraintMaker *make) {
  212. make.top.equalTo(serviceView.mas_top);
  213. make.left.equalTo(serviceView.mas_right);
  214. make.width.equalTo(@(width));
  215. make.height.equalTo(@80);
  216. }];
  217. UITapGestureRecognizer *shopTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickShopItemAction)];
  218. [shopView addGestureRecognizer:shopTap];
  219. YXFindItemView *activityView = [[YXFindItemView alloc]init];
  220. activityView.picImgView.image = [UIImage imageNamed:@"find_activity"];
  221. activityView.textLabel.text = @"活动";
  222. [headerBgView addSubview:activityView];
  223. [activityView mas_makeConstraints:^(MASConstraintMaker *make) {
  224. make.top.equalTo(serviceView.mas_top);
  225. make.left.equalTo(shopView.mas_right);
  226. make.width.equalTo(@(width));
  227. make.height.equalTo(@80);
  228. }];
  229. UITapGestureRecognizer *activityTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickActivityItemAction)];
  230. [activityView addGestureRecognizer:activityTap];
  231. YXFindItemView *moreView = [[YXFindItemView alloc]init];
  232. moreView.picImgView.image = [UIImage imageNamed:@"find_more"];
  233. moreView.textLabel.text = @"更多";
  234. [headerBgView addSubview:moreView];
  235. [moreView mas_makeConstraints:^(MASConstraintMaker *make) {
  236. make.top.equalTo(serviceView.mas_top);
  237. make.left.equalTo(activityView.mas_right);
  238. make.width.equalTo(@(width));
  239. make.height.equalTo(@80);
  240. }];
  241. UITapGestureRecognizer *moreTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickMoreItemAction)];
  242. [moreView addGestureRecognizer:moreTap];
  243. UIImageView *hotImgView = [[UIImageView alloc]init];
  244. hotImgView.image = [UIImage imageNamed:@"find_hot"];
  245. [headerBgView addSubview:hotImgView];
  246. [hotImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  247. make.top.equalTo(serviceView.mas_bottom).offset(30);
  248. make.left.equalTo(@15);
  249. make.width.equalTo(@12);
  250. make.height.equalTo(@16);
  251. }];
  252. UILabel *textLabel = [[UILabel alloc]init];
  253. textLabel.text = @"热门推荐";
  254. textLabel.font = [UIFont boldSystemFontOfSize:16];
  255. textLabel.textColor = [UIColor colorWithHexString:@"#333333"];
  256. [headerBgView addSubview:textLabel];
  257. [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  258. make.centerY.equalTo(hotImgView.mas_centerY);
  259. make.left.equalTo(hotImgView.mas_right).offset(3);
  260. make.width.equalTo(@150);
  261. make.height.equalTo(@30);
  262. }];
  263. }
  264. -(void)clickServiceItemAction
  265. {
  266. [self openWebVcWithUrl:@"findMore/serviceHome"];
  267. }
  268. -(void)clickShopItemAction
  269. {
  270. [self openWebVcWithUrl:@"findMore/mallHome"];
  271. }
  272. -(void)clickActivityItemAction
  273. {
  274. [self openWebVcWithUrl:@"findMore/activityHome"];
  275. }
  276. -(void)clickMoreItemAction
  277. {
  278. [self openWebVcWithUrl:@"findMore/moreHome"];
  279. }
  280. -(void)openWebVcWithUrl:(NSString *)path
  281. {
  282. RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init];
  283. webVc.requestURL = [NSString stringWithFormat:@"%@%@",kBaseUrlH5,path];
  284. webVc.hidesBottomBarWhenPushed = YES;
  285. [self.navigationController pushViewController:webVc animated:YES];
  286. }
  287. #pragma mark - SDCycleScrollViewDelegate
  288. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
  289. {
  290. NSLog(@"---点击了第%ld张图片", (long)index);
  291. if (index < self.bannerArray.count) {
  292. YXBannerModel *model = self.bannerArray[index];
  293. RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init];
  294. webVc.requestURL = model.detail_url;
  295. webVc.hidesBottomBarWhenPushed = YES;
  296. [self.navigationController pushViewController:webVc animated:YES];
  297. }
  298. }
  299. #pragma mark - 菜单
  300. - (void)familyBtnAction:(UIButton *)button {
  301. NSMutableArray *titleArray = [[NSMutableArray alloc]initWithCapacity:5];
  302. for (int i = 0; i < TheDataManager.homes.count; i++) {
  303. RDSHomeModel *model = TheDataManager.homes[i];
  304. [titleArray addObject:model.name];
  305. }
  306. [YBPopupMenu showRelyOnView:button titles:titleArray icons:nil menuWidth:130 otherSettings:^(YBPopupMenu *popupMenu) {
  307. popupMenu.delegate = self;
  308. popupMenu.animationManager.duration = 0.25;
  309. popupMenu.textColor = [UIColor colorWithHexString:@"#1F1F1F"];
  310. }];
  311. }
  312. //#pragma mark - YPPopupMenuDelegate
  313. //- (void)ybPopupMenu:(YBPopupMenu *)ybPopupMenu didSelectedAtIndex:(NSInteger)index
  314. //{
  315. // RDSHomeModel *model = TheDataManager.homes[index];
  316. // [self.familyBtn setTitle:model.name forState:UIControlStateNormal];
  317. //
  318. //
  319. //}
  320. /*
  321. #pragma mark - Navigation
  322. // In a storyboard-based application, you will often want to do a little preparation before navigation
  323. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  324. // Get the new view controller using [segue destinationViewController].
  325. // Pass the selected object to the new view controller.
  326. }
  327. */
  328. @end