// // HomeRootVC.m // jitao // // Created by 罗云飞 on 2017/9/14. // Copyright © 2017年 罗云飞. All rights reserved. // #import "HomeRootVC.h" #import "HomeCollectionViewCell.h" #import "ZZCarousel.h" #import "NewRollButton.h" #import "OneOnOneViewController.h" #import "ServiceRecommendViewController.h" #import "HighidentificationViewController.h"//高新认定 #import "ServiceModel.h" #import "BusinessModel.h" #import "GuanggaoModel.h" #import "ScienceAchievementsViewController.h"//科技成果 #import "SciencedemandViewController.h"//科技需求 #import "ScienceexpertViewController.h"//科技专家 #import "YBPopupMenu.h" #import "MyattentionViewController.h" #import "MyOrderViewController.h" #import "AchievementsReleaseViewController.h" #import "ReleaserequirementsViewController.h" #define TITLES @[@"我的关注", @"我的订单",@"发布成果",@"发布需求"] #define ICONS @[@"wdgz",@"wddd",@"fbcg",@"fbxq"] @interface HomeRootVC (){ UICollectionView *mainCollectionView; UICollectionViewFlowLayout *flowLayout; NSMutableArray *dataArray; UICollectionReusableView *headerView; ZZCarousel *_headwheel;//广告图 NSArray *_headwheelArray; NewRollButton *rollButton;// NSMutableArray *classArray; int pageSize; int pageNumber; NSString *ID;//品类ID } @property (strong ,nonatomic) UIButton * registerAccount; @end @implementation HomeRootVC - (void)viewDidLoad { [super viewDidLoad]; [self setNavTitle:@"服务"]; [self dataInitialization]; [self VarietyNetworkrequest:nil]; [self CarouselNetworkrequest:nil]; [self loadsView]; [self addRefreshing]; // Do any additional setup after loading the view. } #pragma mark ----------轮播网络请求------------- - (void)CarouselNetworkrequest:(id)object{ NSMutableDictionary *dic = NewMutableDictionaryInit; [NetworkRequestManager requestGetWithInterfacePrefix:JT_getImagers parameters:dic onSuccess:^(id requestData) { if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ _headwheelArray = nil; _headwheelArray = requestData[@"data"]; _headwheel?[_headwheel reloadData]:nil; } } onFailure:^{ }]; } #pragma mark ----------获取品类下项目网络请求-------- - (void)BusinessProjectNetworkrequest:(id)object { int pageNumberIndex=1; if (!object) { [MBProgressHUD showLoadToView:self.view title:@"请稍后..."]; }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) { pageNumberIndex = 1; }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) { pageNumberIndex = pageNumber+1; } NSMutableDictionary *parameters = NewMutableDictionaryInit; [parameters safeSetObject:ID forKey:@"id"]; [parameters safeSetObject:@(pageSize) forKey:@"pSize"]; [parameters safeSetObject:@(pageNumberIndex) forKey:@"pNo"]; [NetworkRequestManager requestGetWithInterfacePrefix:JT_getBusinessProject parameters:parameters onSuccess:^(id requestData) { [self dismiss:object]; if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ pageNumber = pageNumberIndex; if ([object isKindOfClass:[MJRefreshNormalHeader class]]) { [dataArray removeAllObjects]; }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) { if ([requestData[@"data"][@"list"] count]<=0) { [MBProgressHUD showError:NewConnectServerNoMoreDataTitle toView:self.view]; } }else{ [dataArray removeAllObjects]; } for (NSDictionary *dic in requestData[@"data"][@"list"]) { BusinessModel *model = [[BusinessModel alloc] initWithDictionary:dic error:nil]; [dataArray addObject:model]; } [mainCollectionView reloadData]; } } onFailure:^{ [self dismiss:object]; }]; } #pragma mark ----------初级品种目录网络请求-------- - (void)VarietyNetworkrequest:(id)object { NSMutableDictionary *parameters = NewMutableDictionaryInit; [NetworkRequestManager requestGetWithInterfacePrefix:JT_getVarieties parameters:parameters onSuccess:^(id requestData) { if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ [classArray removeAllObjects]; for (NSDictionary *dic in requestData[@"data"]) { ServiceModel *model = [[ServiceModel alloc] initWithDictionary:dic error:nil]; [classArray addObject:model]; } [rollButton reloadDatas:classArray]; ServiceModel *model = classArray[0]; ID = model.ID; [self BusinessProjectNetworkrequest:object]; } } onFailure:^{ }]; } #pragma mark - 数据初始化 -(void)dataInitialization { pageSize = 10; pageNumber = 1; dataArray = NewMutableArrayInit; _headwheelArray = [NSArray new]; classArray = NewMutableArrayInit; } #pragma mark - UI初始化 -(void)loadsView { [self.navgationBar addSubview:self.registerAccount]; _registerAccount.sd_layout .widthIs(30) .rightSpaceToView(self.navgationBar, 10) .heightIs(44) .topSpaceToView(self.navgationBar, 18); [self.view addSubview:mainCollectionView = [NewControlPackage collectionViewInitWithFrame:CGRectMake(0.0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-TABBAR_HEIGHT-NavHeader) delegate:self dataSource:self backgroundColor:NewGroupTableViewBackgroundColor scrollEnabled:YES alwaysBounceVertical:YES alwaysBounceHorizontal:NO showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO collectionViewFlowLayout:flowLayout sectionInset:UIEdgeInsetsMake(0, 0, 0, 0) headerReference:CGSizeMake(0, 0) footerReference:CGSizeMake(0, 0) minimumInteritemSpacing:0 minimumLineSpacing:0 scrollDirection:0 hidden:NO tag:105 userInteractionEnabled:YES]]; [mainCollectionView registerClass:[HomeCollectionViewCell class] forCellWithReuseIdentifier:@"HomeRootVCCell"]; [mainCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HomeRootVCHeaderView"]; } - (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { UICollectionReusableView *reusableview = nil; if (kind == UICollectionElementKindSectionHeader) { if (!headerView) { headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HomeRootVCHeaderView" forIndexPath:indexPath]; headerView.backgroundColor = NewClearColor; if (!_headwheel) { _headwheel = nil; //创建轮播图 _headwheel = [self headViewwheel:500]; [headerView addSubview:_headwheel]; [_headwheel reloadData]; } UIView *view = [[UIView alloc] init]; view.backgroundColor = NewWhiteColor; [headerView addSubview:view]; view.sd_layout .topSpaceToView(_headwheel, 0) .heightIs(64) .widthIs(SCREEN_WIDTH); UIButton *tuijianBT = [UIButton new]; [tuijianBT setImage:[UIImage imageNamed:@"tj"] forState:UIControlStateNormal]; NewTouchUpInside(tuijianBT, tuijianBTclick:); [view addSubview:tuijianBT]; tuijianBT.sd_layout .leftSpaceToView(view, 15) .rightSpaceToView(view, view.width/2+5) .topSpaceToView(view, 5) .bottomSpaceToView(view, 5); UIButton *yiduiyiBT = [UIButton new]; [yiduiyiBT setImage:[UIImage imageNamed:@"ydy"] forState:UIControlStateNormal]; NewTouchUpInside(yiduiyiBT, yiduiyiBTclick:); [view addSubview:yiduiyiBT]; yiduiyiBT.sd_layout .leftSpaceToView(view, view.width/2+5) .rightSpaceToView(view, 5) .topSpaceToView(view, 5) .bottomSpaceToView(view, 5); UILabel *line = [UILabel new]; line.backgroundColor = NewRGBColor(236, 236, 236, 1); [headerView addSubview:line]; line.sd_layout .widthIs(SCREEN_WIDTH) .heightIs(10) .topSpaceToView(view, 0); [headerView addSubview:rollButton = [[NewRollButton alloc]init]]; rollButton.sd_layout .topSpaceToView(line, 0) .heightIs(fitScreenWidth(54)) .widthIs(SCREEN_WIDTH); __weak typeof(self) weakSelf = self; [rollButton setNewRollButtonCallback:^(NSDictionary *dictionary) { [weakSelf rollButtonClick:dictionary]; }]; } reusableview = headerView; } return reusableview; } #pragma mark ---------点击分类按钮--------- - (void)rollButtonClick:(NSDictionary *)dic { ServiceModel *model = (ServiceModel *)dic; ID = model.ID; [self BusinessProjectNetworkrequest:nil]; } //头视图高度 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { return CGSizeMake(SCREEN_WIDTH, 169+64+10+fitScreenWidth(54)); } //单元格大小 -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(SCREEN_WIDTH/2-20, 150); } //定义每个UICollectionView 的 margin 边距 上左下右 - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(10, 15, 0, 15); } -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return dataArray.count; } -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { HomeCollectionViewCell*cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeRootVCCell" forIndexPath:indexPath]; if (dataArray.count>0) { [cell assignment:dataArray[indexPath.row]]; } return cell; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (dataArray.count>0) { BusinessModel *model = dataArray[indexPath.row]; if ([model.projectUrl isEqualToString:@"/app/discovery/achievementList"]) {//科技成果列表 ScienceAchievementsViewController *vc = [[ScienceAchievementsViewController alloc] init]; NewPushViewController(vc); }else if ([model.projectUrl isEqualToString:@"/app/discovery/demandList"]){//科技需求列表 SciencedemandViewController *vc = [[SciencedemandViewController alloc] init]; NewPushViewController(vc); }else if ([model.projectUrl isEqualToString:@"/app/discovery/expertsList"]){//科技专家列表 ScienceexpertViewController *vc = [[ScienceexpertViewController alloc] init]; NewPushViewController(vc); }else{ HighidentificationViewController *vc = [[HighidentificationViewController alloc] init]; vc.ID = model.ID; NewPushViewController(vc); } } } #pragma mark-------------------------ZZCarousel轮播图片---------------------------------- -(ZZCarousel*)headViewwheel:(NSInteger)tag { //self.navigationController.navigationBar.frame.size.height (SCREEN_WIDTH * 500 ) / 1080 ZZCarousel* wheel = [[ZZCarousel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,169)]; wheel.tag = tag; /* * carouseScrollTimeInterval --- 此属性为设置轮播多长时间滚动到下一张 */ wheel.carouseScrollTimeInterval = CarouselTime; // 代理 wheel.delegate = self; /* * isAutoScroll --- 默认为NO,当为YES时 才能使轮播进行滚动 */ wheel.isAutoScroll = YES; /* * pageType --- 设置轮播样式 默认为系统样式。ZZCarousel 中封装了 两种样式,另外一种为数字样式 */ wheel.pageType = ZZCarouselPageTypeOfNone; /* * 设置UIPageControl 在轮播中的位置、系统默认的UIPageControl 的顶层颜色 和底层颜色已经背景颜色 */ if(wheel.tag == 500) { wheel.pageControlFrame = CGRectMake((SCREEN_WIDTH - 60 ) / 2, wheel.frame.size.height - 10, 60, 5); wheel.pageIndicatorTintColor = [UIColor whiteColor]; wheel.currentPageIndicatorTintColor = NewRGBColor(191, 191, 191, 1); wheel.pageControlBackGroundColor = [UIColor whiteColor]; /* * 设置数字样式的 UIPageControl 中的字体和字体颜色。 背景颜色仍然按照上面pageControlBackGroundColor属性来设置 */ wheel.pageControlOfNumberFont = [UIFont fontWithName:@"Helvetica-Bold" size:18]; wheel.pageContolOfNumberFontColor = [UIColor whiteColor]; } return wheel; } //ZZCarouselDelegate 轮播图片代理方法 -(NSInteger)numberOfZZCarousel:(ZZCarousel *)wheel { return _headwheelArray.count; } //图片赋值 -(ZZCarouselView *)zzcarousel:(UICollectionView *)zzcarousel viewForItemAtIndex:(NSIndexPath *)index itemsIndex:(NSInteger)itemsIndex identifire:(NSString *)identifire ZZCarousel:(ZZCarousel *)zZCarousel { /* * index参数 ※ 注意 */ ZZCarouselView *cell = [zzcarousel dequeueReusableCellWithReuseIdentifier:identifire forIndexPath:index]; if (!cell) { cell = [[ZZCarouselView alloc]init]; } // cell.title.text = [_imagesGroup objectAtIndex:indexPath.row]; // [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"图片地址"]]; /* * itemsIndex 参数 ※ 注意 */ if(zZCarousel.tag == 500){ if(_headwheelArray.count > itemsIndex){ [cell.imageView sd_setImageWithURL:NewURL([_headwheelArray[itemsIndex] mosaicUrlPrefix]) placeholderImage:NewImageNamed(@"banner")]; }else { [cell.imageView setImage:NewImageError_T]; } } return cell; } //图片点击方法 -(void)zzcarouselScrollView:(ZZCarousel *)zzcarouselScrollView didSelectItemAtIndex:(NSInteger)index { NSLog(@"%@",[NSString stringWithFormat:@"点击了 第%ld张 轮播图片",(long)index]); } #pragma mark -----一对一按钮---- - (void)yiduiyiBTclick:(UIButton *)sender { OneOnOneViewController *vc = [[OneOnOneViewController alloc] init]; NewPushViewController(vc); } #pragma mark -----推荐按钮---- - (void)tuijianBTclick:(UIButton *)sender { ServiceRecommendViewController *vc = [[ServiceRecommendViewController alloc] init]; NewPushViewController(vc); } #pragma mark - 上拉下拉初始化 - (void)addRefreshing { __weak typeof(self) weakSelf = self; __weak UICollectionView *newvc = mainCollectionView; newvc.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ if ([NetworkRequestManager connectedToNetwork]) { [weakSelf CarouselNetworkrequest:newvc.mj_header]; [weakSelf VarietyNetworkrequest:newvc.mj_header]; [weakSelf BusinessProjectNetworkrequest:newvc.mj_header]; }else{ [newvc.mj_header endRefreshing]; } }]; newvc.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ if ([NetworkRequestManager connectedToNetwork]) { [weakSelf BusinessProjectNetworkrequest:newvc.mj_footer]; }else{ [newvc.mj_footer endRefreshing]; } }]; } - (void)dismiss:(id)object { if ([object isKindOfClass:[MJRefreshNormalHeader class]]) { __weak UICollectionView *newvc = mainCollectionView; [newvc.mj_header endRefreshing]; }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){ __weak UICollectionView *newvc = mainCollectionView; [newvc.mj_footer endRefreshing]; }else { [MBProgressHUD hideHUDForView:self.view]; } } - (UIButton *)registerAccount { if (!_registerAccount) { _registerAccount = [UIButton buttonWithType:UIButtonTypeCustom]; // [_registerAccount setTitle:@"" forState:UIControlStateNormal]; [_registerAccount setTitleColor:[UIColor colorWithString:@"#9A9A9A"] forState:UIControlStateNormal]; [_registerAccount setBackgroundColor:[UIColor clearColor]]; [_registerAccount setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight]; [_registerAccount.titleLabel setFont:[UIFont systemFontOfSize:fitScreenWidth(14)]]; [_registerAccount addTarget:self action:@selector(touchRegister:) forControlEvents:UIControlEventTouchUpInside]; // [_registerAccount setupAutoSizeWithHorizontalPadding:5 buttonHeight:44]; [_registerAccount setImage:NewImageNamed(@"gd") forState:UIControlStateNormal]; } return _registerAccount; } - (void)touchRegister:(UIButton *)sender{ [YBPopupMenu showRelyOnView:sender titles:TITLES icons:ICONS menuWidth:140 delegate:self]; } #pragma mark - YBPopupMenuDelegate - (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu { NSLog(@"点击了 %@ 选项",TITLES[index]); if (index == 0) { if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); MyattentionViewController *vc = [[MyattentionViewController alloc] init]; NewPushViewController(vc); }else{ NSLog(@"%@",@"未登录"); NewLoginViewController *vc = [[NewLoginViewController alloc] init]; [vc setLoginSuccess:^(NSString *string) { NewPopViewController; }]; NewPushViewController(vc); } }else if (index == 1){ if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); MyOrderViewController*vc = [[MyOrderViewController alloc] init]; NewPushViewController(vc); }else{ NSLog(@"%@",@"未登录"); NewLoginViewController *vc = [[NewLoginViewController alloc] init]; [vc setLoginSuccess:^(NSString *string) { NewPopViewController; }]; NewPushViewController(vc); } }else if (index == 2) { if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); AchievementsReleaseViewController *vc = [[AchievementsReleaseViewController alloc] init]; NewPushViewController(vc); }else{ NSLog(@"%@",@"未登录"); NewLoginViewController *vc = [[NewLoginViewController alloc] init]; [vc setLoginSuccess:^(NSString *string) { NewPopViewController; }]; NewPushViewController(vc); } }else if (index == 3){ if ([UserHelper isLogin]) { NSLog(@"%@",@"已登录"); ReleaserequirementsViewController *vc = [[ReleaserequirementsViewController alloc] init]; NewPushViewController(vc); }else{ NSLog(@"%@",@"未登录"); NewLoginViewController *vc = [[NewLoginViewController alloc] init]; [vc setLoginSuccess:^(NSString *string) { NewPopViewController; }]; NewPushViewController(vc); } } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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