// // HCClassifyViewController.m // hc // // Created by hc on 2018/4/28. // Copyright © 2018年 hc. All rights reserved. // #import "HCClassifyViewController.h" #import "HCClassifyLeftView.h" #import "HCClassifyRightView.h" #import "HCCategoryModel.h" #import "HCSecondCategoryModel.h" #import "HCGoodListViewController.h" #import "HCClassifyListController.h" #import "HCFindNavBarStaticView.h" #import "PYSearchViewController.h" #import "HCFindSearchResultViewController.h" #import "HCFindRequestViewModel.h" #import "AdJumpManager.h" #import "AdJumpManager.h" #import "CreatSearchManager.h" @interface HCClassifyViewController () { } @property (nonatomic, strong) HCClassifyLeftView *leftView; //类别 @property (nonatomic, strong) HCClassifyRightView *rightView;//详单 @property (nonatomic, strong) NSMutableArray *dataArr; @property (nonatomic, strong) NSArray *secondDataArr; @property (nonatomic, strong) HCFindNavBarStaticView *navBarStaticView; @property (nonatomic, strong) NSMutableArray *everyoneSearchArr; @property (nonatomic, strong) NSString *classifyName; @property (nonatomic, strong) NSArray *hotSearchModelArray; @property (nonatomic, strong) NSString *firstCategoryId; @end @implementation HCClassifyViewController - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; // [SVProgressHUD dismiss]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; } - (void)viewDidLoad { [super viewDidLoad]; [self creatNavBar]; [self createView]; [self requestData]; [self requestEveryoneSearch]; } - (void)creatNavBar { [self.navigationBar addSubview:self.navBarStaticView]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; [self.navigationBar setShowNavigationBarBottomLine:YES]; self.view.backgroundColor = [UIColor whiteColor]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeSex) name:ChangeSex object:nil]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)createView { [self createLeftView]; [self createRightView]; } - (void)changeSex { [self createLeftView]; [self createRightView]; [self refreshData]; } - (void)createLeftView{ self.leftView = [[HCClassifyLeftView alloc]initWithFrame:CGRectMake(0, NavBarHeight, 92*SCREEN_MUTI, SCREEN_HEIGHT - NavBarHeight)]; __weak typeof(self) weakSelf = self; self.leftView.selectRowBlock = ^(NSInteger index) { HCCategoryModel *model = weakSelf.dataArr[index]; weakSelf.secondDataArr = model.itemList; weakSelf.rightView.dataSource = model.itemList; weakSelf.rightView.model = model.adv; weakSelf.classifyName = model.name; weakSelf.firstCategoryId = model.Id; }; [self.view addSubview:self.leftView]; } - (void)createRightView{ self.rightView = [[HCClassifyRightView alloc]initWithFrame:CGRectMake(92*SCREEN_MUTI, NavBarHeight, SCREEN_WIDTH - 92*SCREEN_MUTI, SCREEN_HEIGHT -NavBarHeight)]; __weak typeof(self) weakSelf = self; self.rightView.selectItemBlock = ^(NSInteger index) { HCClassifyListController *list = [[HCClassifyListController alloc] init]; HCSecondCategoryModel *model = weakSelf.secondDataArr[index]; list.firstCategoryId = weakSelf.firstCategoryId; list.cate_id = model.Id; list.name = model.name; [weakSelf.navigationController pushViewController:list animated:YES]; NSString *tagStr = [NSString stringWithFormat:@"%@-%@",weakSelf.classifyName,model.name]; [MobClick event:Classify label:tagStr]; }; self.rightView.selectHeader = ^(AdPopModel *model) { [AdJumpManager jumpToPageWithModel:model ParentViewControll:weakSelf]; }; [self.view addSubview:self.rightView]; } - (void)requestData { [SVProgressHUD show]; NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/category/list", BaseURL]; [HCCacheHttp get:urlString params:nil success:^(id json, BOOL isCache) { [self.dataArr removeAllObjects]; NSArray *arr = [NSArray yy_modelArrayWithClass:[HCCategoryModel class] json:json[@"data"]]; [self.dataArr addObjectsFromArray:arr]; self.leftView.dataArray = arr; HCCategoryModel *model = arr.firstObject; self.classifyName = model.name; self.secondDataArr = model.itemList; self.rightView.dataSource = model.itemList; // self.rightView.bannerImgUrl=model.adModel; self.rightView.model=model.adv; self.firstCategoryId = model.Id; [SVProgressHUD dismiss]; } failure:^(NSError *error) { [SVProgressHUD dismiss]; }]; } - (void)requestEveryoneSearch { NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/goods/everyoneSearch", BaseURL]; [HCCacheHttp get:urlString params:nil success:^(id json, BOOL isCache) { [self.everyoneSearchArr removeAllObjects]; self.hotSearchModelArray = [NSArray yy_modelArrayWithClass:[HotSearchModel class] json:json]; for (HotSearchModel *model in self.hotSearchModelArray) { [self.everyoneSearchArr addObject:model.name]; } } failure:^(NSError *error) { }]; } - (void)refreshData { [self.dataArr removeAllObjects]; [self requestData]; } #pragma mark - navBarView - (void)yh_FindNavBarStaticViewClickSearch { [self createSearchViewControllerWith:nil]; } #pragma mark - -------------search ----------- - (void)createSearchViewControllerWith:(NSString *)text { CreatSearchManager *manager = [CreatSearchManager shareManager]; [manager createSearchViewControllerWith:text viewController:self]; // return; // // PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:@[] searchBarPlaceholder:@"输入商品名或粘贴淘宝标题"]; // searchViewController.searchHistoryStyle = PYSearchHistoryStyleARCBorderTag; // searchViewController.hotSearchStyle = PYHotSearchStyleARCBorderTag; // searchViewController.searchTextField.font = [UIFont systemFontOfSize:13]; // searchViewController.delegate = self; // searchViewController.searchBar.text = text; // // [self getHotSearchToSearchViewController:searchViewController]; // // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController]; // [self presentViewController:nav animated:NO completion:^{ // // }]; // // searchViewController.didSearchBlock = ^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) { // [MobClick event:search_count label:Search_Normal]; // //处理搜索点击事件 // HCFindSearchResultViewController *resultVC = [[HCFindSearchResultViewController alloc] init]; // resultVC.searchBar = searchBar; // resultVC.searchName = searchText; // [nav pushViewController:resultVC animated:NO]; // // }; } /** 加载热搜词汇 */ - (void)getHotSearchToSearchViewController:(PYSearchViewController *)searchViewController { searchViewController.hotSearchModelArray = self.hotSearchModelArray; searchViewController.hotSearches = self.everyoneSearchArr; } #pragma mark - PYSearchViewControllerDelegate /** 输入完成时触发 */ - (void)searchViewController:(PYSearchViewController *)searchViewController searchTextDidChange:(UISearchBar *)seachBar searchText:(NSString *)searchText { if (searchText.length) { [HCHttp get:SearchAdvice params:@{@"name":searchText} success:^(id json) { NSArray *list = json[@"data"]; searchViewController.searchSuggestions = list; } failure:^(NSError *error) { }]; } } /** 点击建议 */ - (void)searchViewController:(PYSearchViewController *)searchViewController didSelectSearchSuggestionAtIndex:(NSInteger)index searchText:(NSString *)searchText { HCFindSearchResultViewController *resultVC = [[HCFindSearchResultViewController alloc] init]; resultVC.searchName = searchText; resultVC.searchBar = searchViewController.searchBar; [searchViewController.navigationController pushViewController:resultVC animated:NO]; } /** 点击热搜 */ - (void)searchViewController:(PYSearchViewController *)searchViewController didSelectHotSearchAtIndex:(NSInteger)index searchText:(NSString *)searchText { HCFindSearchResultViewController *resultVC = [[HCFindSearchResultViewController alloc] init]; resultVC.searchName = searchText; resultVC.searchBar = searchViewController.searchBar; [searchViewController.navigationController pushViewController:resultVC animated:NO]; [MobClick event:search_count label:Search_Hot_String]; } /** 点击历史 */ - (void)searchViewController:(PYSearchViewController *)searchViewController didSelectSearchHistoryAtIndex:(NSInteger)index searchText:(NSString *)searchText { HCFindSearchResultViewController *resultVC = [[HCFindSearchResultViewController alloc] init]; resultVC.searchName = searchText; resultVC.searchBar = searchViewController.searchBar; [searchViewController.navigationController pushViewController:resultVC animated:NO]; [MobClick event:search_count label:Search_History_String]; } #pragma mark ----- - (HCFindNavBarStaticView *)navBarStaticView { if (!_navBarStaticView) { _navBarStaticView = [[HCFindNavBarStaticView alloc] initWithFrame:CGRectMake(60, 0, kScreenWidth-60, NavBarHeight-1)]; _navBarStaticView.backgroundColor = [UIColor whiteColor]; _navBarStaticView.delegate = self; } return _navBarStaticView; } - (NSMutableArray *)dataArr { if (!_dataArr) { _dataArr = [NSMutableArray array]; } return _dataArr; } - (NSMutableArray *)everyoneSearchArr { if (!_everyoneSearchArr) { _everyoneSearchArr = [NSMutableArray array]; } return _everyoneSearchArr; } - (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