123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827 |
- //
- // KBHomeMainViewController.m
- // YouHuiProject
- //
- // Created by xiaoxi on 2018/1/16.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBHomeMainViewController.h"
- #import "KBChildPageViewController.h"
- #import "KBScrollSearchView.h"
- #import "KBTodayViewController.h"
- #import "KBHomeChannelModel.h"
- #import "KBChannelPopView.h"
- #import "PYSearch.h"
- #import "KBShopCarViewController.h"
- #import "KBFindSearchResultViewController.h"
- #import "KBTaobaoAuthorView.h"
- #import "CCAlertShowView.h"
- #import "KBUpdateAlertView.h"
- #import "AdPopView.h"
- #import "AdPopModel.h"
- #import "AdJumpManager.h"
- #import "KBGetMoneyViewController.h"
- #import "NetworkTool.h"
- #import "YBCacheTool.h"
- #import <AlibcTradeSDK/AlibcTradeSDK.h>
- #import "KBSignInViewController.h"
- #import "KBLoginViewController.h"
- #import "HotSearchModel.h"
- #import "KBGoodDetailViewController.h"
- #import "KBClassifyViewController.h"
- @interface KBHomeMainViewController ()<LPPageVCDelegate,LPPageVCDataSource,YHScrollSearchDelegate,YHChannelPopViewDelegate,PYSearchViewControllerDelegate> {
- NSInteger _selectedIndex;
- BOOL showNavBar;
- }
- @property (nonatomic, strong) NSMutableArray *vcArray;
- @property (nonatomic, strong) NSMutableArray *titleArr;
- @property (nonatomic, strong) NSMutableArray *modelArr;
- @property (nonatomic, strong) NSMutableArray *hotSearchText;
- @property (nonatomic, strong) NSMutableArray *everyOneSearch;
- @property (nonatomic, strong) NSMutableArray *adPopDataArr;
- @property (nonatomic, strong) KBScrollSearchView *searchView;
- @property (nonatomic, strong) KBTaobaoAuthorView *noNetworkView;
- @property (nonatomic, strong) NSArray *hotSearchModelArray;
- @property (nonatomic, strong) UIImageView *bgImageView;
- @end
- @implementation KBHomeMainViewController
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- if (showNavBar) {
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
- }else {
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
- }
-
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self configNavigationBar];
- [self loadHotSearchText];
- [self configSegmentDelegate];
- [self loadChildViewController];
- [self loadPopAdData];
- [self creatNetworkView];
- [self checkUpdateApp];
- [self addNotifationForHomePage];
- }
- - (void)configNavigationBar {
-
- self.bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, KStatusBarHeight+NavBarHeight+40+Fitsize(70))];
- self.bgImageView.contentMode = UIViewContentModeScaleAspectFill;
- self.bgImageView.backgroundColor = [UIColor YHColorWithHex:0xD5D5D5];
- [self.view addSubview:self.bgImageView];
- [self.view sendSubviewToBack:self.bgImageView];
-
- showNavBar = YES;
- self.view.backgroundColor = [UIColor yhGrayColor];
- [self.navigationBar setNavightionBarBackgroundColor:[UIColor clearColor]];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshData) name:ChangeSex object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollDirectorNoti:) name:ScrollDirectorNoti object:nil];
-
- UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
- [rightBtn setImage:[UIImage imageNamed:@"home_sign"] forState:UIControlStateNormal];
- rightBtn.contentMode = UIViewContentModeScaleAspectFill;
- [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [self.navigationBar setCustomRightButtons:@[rightBtn]];
-
- UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
- [leftBtn setImage:[UIImage imageNamed:@"fenlei"] forState:UIControlStateNormal];
- [leftBtn setTitle:@"分类" forState:UIControlStateNormal];
- leftBtn.titleLabel.font = [UIFont systemFontOfSize:9];
- [leftBtn setButtonImageTitleStyle:ButtonImageTitleStyleTop padding:1];
- leftBtn.contentMode = UIViewContentModeScaleAspectFill;
- [leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [self.navigationBar setCustomLeftButtons:@[leftBtn]];
- }
- - (void)leftBtnClick {
- KBClassifyViewController *classify = [[KBClassifyViewController alloc] init];
- [self.navigationController pushViewController:classify animated:YES];
- }
- - (void)rightBtnClick {
- [MobClick event:ClickHomeSignIn];
- if (![AccountTool isLogin]) {
- [self goToLoginPage];
- return;
- }
- KBSignInViewController *sign = [[KBSignInViewController alloc] init];
- [self.navigationController pushViewController:sign animated:YES];
- }
- - (void)addNotifationForHomePage {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showAlertAction) name:KGlobalPopQueneKey object:nil];
- }
- - (void)showAlertAction {
- NSMutableArray *alertArray = [GlobalPopQueneManager shareManager].alertArray;
- if (alertArray.count > 0) {
- if (![GlobalPopQueneManager shareManager].isShowing) {
- CCAlertShowView *showView = alertArray.firstObject;
- [GlobalPopQueneManager shareManager].isShowing = YES;
- [showView show];
- [[GlobalPopQueneManager shareManager].alertArray removeObject:showView];
- }
- }
- }
- - (void)goToLoginPage {
- KBLoginViewController *login = [[KBLoginViewController alloc] init];
- [self presentViewController:login animated:YES completion:nil];
- }
- - (void)loadPopAdData {
-
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/adv/advByType",BaseURL];
- NSDictionary *para = @{@"adv_type":@"6"};
- [KBHttp get:url params:para success:^(id json) {
-
- NSArray *list = [NSArray yy_modelArrayWithClass:[AdPopModel class] json:json[@"data"]];
- [self.adPopDataArr addObjectsFromArray:list];
- [self creatPopView];
-
- } failure:^(NSError *error) {
-
- }];
-
-
- }
- - (void)creatPopView {
-
- if (self.adPopDataArr.count == 0 ) {
- return;
- }
-
- for (AdPopModel *model in self.adPopDataArr) {
- AdPopView *adPopView = [[AdPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) adModel:model];
- CCAlertShowView *showView = [CCAlertShowView alertViewWithView:adPopView];
- showView.tapBackgroundDismissEnable = NO;
- adPopView.clickBlock = ^(AdPopModel *model) {
- //跳转处理
- [AdJumpManager jumpToPageWithModel:model ParentViewControll:self];
- [showView dismiss];
- [GlobalPopQueneManager shareManager].isShowing = NO;
- [[NSNotificationCenter defaultCenter] postNotificationName:KGlobalPopQueneKey object:nil];
-
- };
- adPopView.closeBlock = ^{
- [showView dismiss];
- [GlobalPopQueneManager shareManager].isShowing = NO;
- [[NSNotificationCenter defaultCenter] postNotificationName:KGlobalPopQueneKey object:nil];
-
- };
- [[GlobalPopQueneManager shareManager].alertArray addObject:showView];
- [[NSNotificationCenter defaultCenter] postNotificationName:KGlobalPopQueneKey object:nil];
- }
-
- // AdPopModel *model = self.adPopDataArr.firstObject;
- // AdPopView *adPopView = [[AdPopView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(250), Fitsize(350)) adModel:model];
- // CCAlertShowView *showView = [CCAlertShowView alertViewWithView:adPopView];
- // showView.tapBackgroundDismissEnable = NO;
- // adPopView.clickBlock = ^(AdPopModel *model) {
- // //跳转处理
- //
- // [AdJumpManager jumpToPageWithModel:model ParentViewControll:self];
- // [self.adPopDataArr removeFirstObject];
- // [self creatPopView];
- // [showView dismiss];
- //
- // };
- // adPopView.closeBlock = ^{
- //
- // [self.adPopDataArr removeFirstObject];
- // [self creatPopView];
- // [showView dismiss];
- // };
- // [showView showInView:self.view];
- }
- - (void)configSegmentDelegate {
-
- // self.normalTextColor = [UIColor YHColorWithHex:0x444444];
- // self.higlightTextColor = [UIColor homeRedColor];
- // self.lineBackground = [UIColor homeRedColor];
- self.normalTextColor = [UIColor whiteColor];
- self.higlightTextColor = [UIColor whiteColor];
- self.lineBackground = [UIColor whiteColor];
- self.segmentStyle = LPPageVCSegmentStyleLineHighlight;
-
- self.delegate = self;
- self.dataSource = self;
- }
- - (void)creatNetworkView {
-
-
- // int state = [NetworkTool checkNetWorkPermission];
- //
- // switch (state) {
- // case 0:
- // [self showAletyWith:@"网络关闭"];
- // break;
- // case 1:
- // [self showAletyWith:@"仅wifi "];
- // break;
- // case 2:
- // [self showAletyWith:@"流量+wifi"];
- // break;
- //
- // default:
- // break;
- // }
- //
- if (![PublicFunction isAvailableNetworkType]) {
- self.noNetworkView = [[KBTaobaoAuthorView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) text:@"检测到当前网络不可用,请刷新试试。" clickBlock:^{
- [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil];
- [self setupAlibcSDK];
- }];
- [self.noNetworkView.loginBtn setTitle:@"立即刷新" forState:UIControlStateNormal];
- [self.view addSubview:self.noNetworkView];
- // [userDefaults setObject:@(YES) forKey:@"FirstLaunched"];
- }
- }
- /**
- 配置阿里百川SDK
- */
- - (void)setupAlibcSDK {
- // 百川平台基础SDK初始化,加载并初始化各个业务能力插件
- [[AlibcTradeSDK sharedInstance] asyncInitWithSuccess:^{
-
- } failure:^(NSError *error) {
- NSLog(@"Init failed: %@", error.description);
- }];
-
- // 开发阶段打开日志开关,方便排查错误信息
- //默认调试模式打开日志,release关闭,可以不调用下面的函数
- // [[AlibcTradeSDK sharedInstance] setDebugLogOpen:YES];
-
- // 配置全局的淘客参数
- //如果没有阿里妈妈的淘客账号,setTaokeParams函数需要调用
- AlibcTradeTaokeParams *taokeParams = [[AlibcTradeTaokeParams alloc] init];
- taokeParams.pid = ALTK_PID; //mm_XXXXX为你自己申请的阿里妈妈淘客pid
- [[AlibcTradeSDK sharedInstance] setTaokeParams:taokeParams];
-
- //设置全局的app标识,在电商模块里等同于isv_code
- //没有申请过isv_code的接入方,默认不需要调用该函数
- [[AlibcTradeSDK sharedInstance] setISVCode:@"your_isv_code"];
-
- // 设置全局配置,是否强制使用h5
- [[AlibcTradeSDK sharedInstance] setIsForceH5:NO];
- }
- - (void)showAletyWith:(NSString *)msg {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:msg preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
- UIAlertAction *set = [UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
- if([[UIApplication sharedApplication]canOpenURL:url] ) {
- if (@available(iOS 10.0, *)) {
- [[UIApplication sharedApplication] openURL:url options:@{}completionHandler:^(BOOL success) {
- }];
- } else {
- [[UIApplication sharedApplication]openURL:url];
- }
- }
- }];
-
- [alert addAction:cancel];
- [alert addAction:set];
- [self presentViewController:alert animated:YES completion:nil];
- }
- - (void)refreshData {
- [self loadChildViewController];
- [self loadHotSearchText];
- }
- /**
- 加载滚动热搜
- */
- - (void)loadHotSearchText {
-
- [KBCacheHttp get:HotSearch params:nil success:^(id json, BOOL isCache) {
- NSArray *list = json[@"data"];
- [self.hotSearchText removeAllObjects];
- for (NSDictionary *dic in list) {
- [self.hotSearchText addObject:dic[@"name"]];
- }
- if (!self.searchView) {
- self.searchView = [[KBScrollSearchView alloc] initWithFrame:CGRectMake(Fitsize(60), NavBarHeight-30-8, SCREEN_WIDTH-Fitsize(125), 30) andTitles:self.hotSearchText];
- self.searchView.delegate = self;
- }
- [self.navigationBar addSubview:self.searchView];
-
-
- } failure:^(NSError *error) {
- NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
- NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
- NSLog(@"服务器的错误原因:%@",str);
- if (!self.searchView) {
- self.searchView = [[KBScrollSearchView alloc] initWithFrame:CGRectMake(10, NavBarHeight-30-8, SCREEN_WIDTH-20, 30) andTitles:@[@"输入或粘贴商品标题"]];
- self.searchView.delegate = self;
- }
- [self.navigationBar addSubview:self.searchView];
- }];
-
-
-
- NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/goods/everyoneSearch", BaseURL];
-
- [KBCacheHttp get:urlString params:nil success:^(id json, BOOL isCache) {
- [self.everyOneSearch removeAllObjects];
- // for (NSDictionary *dic in json) {
- // [self.everyOneSearch addObject:dic];
- // }
- self.hotSearchModelArray = [NSArray yy_modelArrayWithClass:[HotSearchModel class] json:json];
- for (HotSearchModel *model in self.hotSearchModelArray) {
- [self.everyOneSearch addObject:model.name];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)loadChildViewController {
-
- [KBCacheHttp get:ChannelList params:nil success:^(id json, BOOL isCache) {
- self.noNetworkView.hidden = YES;
- [self.modelArr removeAllObjects];
-
- _selectedIndex = 0;
- NSArray *list = json[@"data"];
- for (int i=0; i<list.count; i++) {
- NSDictionary *dic=list[i];
- KBHomeChannelModel *model = [KBHomeChannelModel yy_modelWithJSON:dic];
- [self.modelArr addObject:model];
- }
- [self changeSortByArr:self.modelArr];
- self.bottomLine.hidden = YES;
- } failure:^(NSError *error) {
-
- }];
-
-
- }
- #pragma mark -重新对标题页进行排序
- -(void)changeSortByArr:(NSArray *)arrList{
- NSArray *arrtmp=[arrList copy];
- [self.vcArray removeAllObjects];
- [self.titleArr removeAllObjects];
- [self.modelArr removeAllObjects];
- NSString *str=[[NSUserDefaults standardUserDefaults] objectForKey:@"sortArr"];
- NSArray *arr=[str componentsSeparatedByString:@","];
- NSMutableArray *mutArr=[NSMutableArray array];
-
- for (int i = 0; i < arrtmp.count; i++) {
- NSLog(@"is_move---%@",arrtmp[i]);
- KBHomeChannelModel *model = arrtmp[i];
- if (i== 0) {//先把0拿出来
- [self.modelArr addObject:model];
- KBTodayViewController *today = [[KBTodayViewController alloc] init];
- today.model = model;
- [self.vcArray addObject:today];
- [self.titleArr addObject:model.name];
- }else if([model.is_move integerValue]==0) {//把不可移动的拿出来
- KBChildPageViewController *child = [[KBChildPageViewController alloc] init];
- child.model = model;
- [self.modelArr addObject:model];
- [self.vcArray addObject:child];
- [self.titleArr addObject:model.name];
- }else{//把可以移动的放到mutarr中
- [mutArr addObject:model];
- }
- }
- NSMutableArray *mutArr2=[NSMutableArray arrayWithArray:mutArr];//复制一份
- // 对本地存储字符串进行 mut排序
- for (NSString *ID in arr) {
- for (KBHomeChannelModel *model in mutArr) {
- if ([model.Id isEqualToString:ID]) {
- KBChildPageViewController *child = [[KBChildPageViewController alloc] init];
- child.model = model;
- [self.modelArr addObject:model];
- [self.vcArray addObject:child];
- [self.titleArr addObject:model.name];
- [mutArr2 removeObject:model];
- }
- }
- }
- if (mutArr2.count>0) {
- for (KBHomeChannelModel *model in mutArr2) {
- KBChildPageViewController *child = [[KBChildPageViewController alloc] init];
- child.model = model;
- [self.modelArr addObject:model];
- [self.vcArray addObject:child];
- [self.titleArr addObject:model.name];
- }
- }
- [self reloadData];
- }
- /**
- 购物车
- */
- - (void)gotoShoppingCar {
- KBShopCarViewController *shopCar = [[KBShopCarViewController alloc] init];
- [self.navigationController pushViewController:shopCar animated:YES];
- }
- - (void)scrollDirectorNoti:(NSNotification *)noti{
- NSDictionary *info = noti.userInfo;
- CGFloat director = [info[@"director"] floatValue];
- if (director <- 10) {
- [UIView animateWithDuration:0.3 animations:^{
- self.bgImageView.y = -Fitsize(70)-KStatusBarHeight+10;
- }];
-
- }else if (director > 10) {
- [UIView animateWithDuration:0.3 animations:^{
- self.bgImageView.y = 0;
- }];
- }
- // NSDictionary *info = noti.userInfo;
- // CGFloat director = [info[@"director"] floatValue];
- // if (director <- 10) {
- // //向上拖动,隐藏导航栏
- // if (self.navigationBar.y == -NavBarHeight) {
- // return;
- // }
- //
- // [UIView animateWithDuration:0.15 animations:^{
- // self.navigationBar.y = -NavBarHeight+KStatusBarHeight;
- // self.searchView.alpha = 0;
- // self.navigationBar.backgroundColor = [UIColor whiteColor];
- // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
- // showNavBar = NO;
- // [_segmentScrollView layoutIfNeeded];
- // }];
- //
- // }else if (director > 10) {
- // //向下拖动,显示导航栏
- // if (self.navigationBar.y == 0) {
- // return;
- // }
- //
- // [UIView animateWithDuration:0.15 animations:^{
- // self.navigationBar.y = 0;
- // self.searchView.alpha = 1;
- // self.navigationBar.backgroundColor = [UIColor clearColor];
- // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
- // showNavBar = YES;
- // [_segmentScrollView layoutIfNeeded];
- // }];
- //
- // }else if(director == 0){
- // //停止拖拽
- // }
- }
- #pragma mark ======================= LPPageVC Delegate & DataSource =======================
- - (UIViewController *)pageVC:(LPPageVC *)pageVC viewControllerAtIndex:(NSInteger)index{
- return self.vcArray[index];
- }
- - (NSString *)pageVC:(LPPageVC *)pageVC titleAtIndex:(NSInteger)index{
- return self.titleArr[index];
- }
- - (NSInteger)numberOfContentForPageVC:(LPPageVC *)pageVC {
- return self.titleArr.count;
- }
- - (void)pageVC:(LPPageVC *)pageVC didClickEditMode:(LPPageVCEditMode)mode {
- KBChannelPopView *popView = [[KBChannelPopView alloc] initWithmodels:self.modelArr delegate:self selectedIndex:_selectedIndex superVc:self];
- popView.changeSortBlock = ^{
- [self changeSortByArr:self.modelArr];
- };
- [popView showInView:self.view belowSubView:self.navigationBar];
- }
- - (void)pageVC:(LPPageVC *)pageVC didChangeToIndex:(NSInteger)toIndex fromIndex:(NSInteger)fromIndex {
- _selectedIndex = toIndex;
- NSInteger index = toIndex;
- if (toIndex<0 || toIndex >self.modelArr.count-1) {
- index = 0;
- }
- KBHomeChannelModel *model = self.modelArr[index];
- [self.bgImageView sd_setImageWithURL:[NSURL URLWithString:model.back_img] placeholderImage:nil];
- [MobClick event:top_classify label:self.titleArr[toIndex]];
- }
- #pragma mark ================= YHChannelPopViewDelegate ============
- - (void)YHChannelPopViewDidSelectedIndex:(NSInteger)index {
- [self setSelectedIndex:index];
- }
- #pragma mark ======================= YHScrollSearchViewDelegate=========
- - (void)clickTitleButton:(UIButton *)button {
- [self createSearchViewControllerWith:button.titleLabel.text];
- }
- - (void)createSearchViewControllerWith:(NSString *)text {
- PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:@[] searchBarPlaceholder:text];
- // searchViewController.swapHotSeachWithSearchHistory = YES;
- searchViewController.searchHistoryStyle = PYSearchHistoryStyleARCBorderTag;
- searchViewController.hotSearchStyle = PYHotSearchStyleARCBorderTag;
- searchViewController.searchTextField.font = [UIFont systemFontOfSize:13];
- searchViewController.searchTextField.enablesReturnKeyAutomatically = NO;
- searchViewController.delegate = self;
- [self getHotSearchToSearchViewController:searchViewController];
-
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController];
- [self presentViewController:nav animated:NO completion:^{
- // for (int i = 0; i < searchViewController.hotSearchTags.count; i++) {
- // UILabel *tag = searchViewController.hotSearchTags[i];
- // NSDictionary *dic = self.everyOneSearch[i];
- // if ([dic[@"color"] boolValue]) {
- //// tag.layer.borderColor = [UIColor homeRedColor].CGColor;
- // tag.textColor = [UIColor homeRedColor];
- // }
- // }
- }];
-
- searchViewController.didSearchBlock = ^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
- //处理搜索点击事件
- [MobClick event:search_count label:Search_Normal];
- KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
- resultVC.searchBar = searchBar;
- resultVC.searchName = searchText;
- if (searchText.length == 0) {
- searchBar.text = searchBar.placeholder;
- resultVC.searchName = searchBar.placeholder;
- }
- searchViewController.searchSuggestions = nil;
- [nav pushViewController:resultVC animated:NO];
- };
- }
- /**
- 加载热门搜索
- */
- - (void)getHotSearchToSearchViewController:(PYSearchViewController *)searchViewController {
-
- searchViewController.hotSearchModelArray = self.hotSearchModelArray;
- searchViewController.hotSearches = self.everyOneSearch;
- }
- #pragma mark - PYSearchViewControllerDelegate
- /**
- 输入完成时触发
- */
- - (void)searchViewController:(PYSearchViewController *)searchViewController searchTextDidChange:(UISearchBar *)seachBar searchText:(NSString *)searchText
- {
- if (searchText.length) {
- [KBHttp 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 {
- KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController 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 {
- HotSearchModel *model = self.hotSearchModelArray[index];
- if ([model.type isEqualToString:@"0"]) {
- KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
- resultVC.searchName = model.name;
- resultVC.searchBar = searchViewController.searchBar;
- [searchViewController.navigationController pushViewController:resultVC animated:NO];
- }else {
- KBGoodDetailViewController *detail = [[KBGoodDetailViewController alloc] init];
- DetailRequestModel *requestModel = [[DetailRequestModel alloc]
- initWithId:model.goods_id
- is_coupon:model.is_coupon
- coupon_price:model.coupon_price
- price:model.price
- discount_price:model.discount_price
- commission_rate:model.commission_rate
- coupon_start_time:model.coupon_start_time
- coupon_end_time:model.coupon_end_time];
- detail.requestModel = requestModel;
- [searchViewController.navigationController pushViewController:detail animated:YES];
- }
-
- [MobClick event:search_count label:Search_Hot_String];
-
-
- }
- /**
- 点击历史
- */
- - (void)searchViewController:(PYSearchViewController *)searchViewController
- didSelectSearchHistoryAtIndex:(NSInteger)index
- searchText:(NSString *)searchText {
- NSArray *searchHistory = [searchViewController getHistorySearchArray];
- HotSearchModel *model = searchHistory[index];
-
- if ([model.type isEqualToString:@"0"]) {
- KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
- resultVC.searchName = model.name;
- resultVC.searchBar = searchViewController.searchBar;
- [searchViewController.navigationController pushViewController:resultVC animated:NO];
- }else {
- KBGoodDetailViewController *detail = [[KBGoodDetailViewController alloc] init];
- DetailRequestModel *requestModel = [[DetailRequestModel alloc]
- initWithId:model.goods_id
- is_coupon:model.is_coupon
- coupon_price:model.coupon_price
- price:model.price
- discount_price:model.discount_price
- commission_rate:model.commission_rate
- coupon_start_time:model.coupon_start_time
- coupon_end_time:model.coupon_end_time];
- detail.requestModel = requestModel;
- [searchViewController.navigationController pushViewController:detail animated:YES];
- }
-
- [MobClick event:search_count label:Search_History_String];
- }
- #pragma mark ------------------ 版本更新检测 ------
- /**
- 监测是否更新app
- */
- - (void)checkUpdateApp{
-
- [KBHttp post:Check_Update params:nil success:^(id json) {
-
- NSString *isUpdate = json[@"data"][@"status"];
- NSString *isNeeded = json[@"data"][@"type"];
- NSString *message = json[@"data"][@"content"];
-
-
- //强制更新
- if ([isUpdate boolValue] && [isNeeded boolValue]){
- [self showAlertWithNeedUpdate:YES message:message];
- return ;
- }
-
- //非强制更新
- if ([isUpdate boolValue]) {
- if (![[NSUserDefaults standardUserDefaults] objectForKey:JZHomeUPdateApp]) {
- [self showAlertWithNeedUpdate:[isNeeded boolValue] message:message];
- } else{
- NSDate *date = [[NSUserDefaults standardUserDefaults] objectForKey:JZHomeUPdateApp];
- CGFloat timeinterval = [[NSString stringWithFormat:@"%.0f",[[NSDate date] timeIntervalSinceDate:date]] floatValue];
- if ((timeinterval > 60*60*24*3)) {
- [self showAlertWithNeedUpdate:[isNeeded boolValue] message:message];
- }
- }
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)showAlertWithNeedUpdate:(BOOL)isNeed message:(NSString *)message{
-
- KBUpdateAlertView *popView = [[KBUpdateAlertView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(257), Fitsize(406)) text:message isNeeded:isNeed];
- CCAlertShowView *showView = [CCAlertShowView alertViewWithView:popView];
- showView.tapBackgroundDismissEnable = NO;
- popView.cancelBlock = ^{
- [showView dismiss];
- };
-
- popView.sureBlock = ^{
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:APP_STORE_URL]];
- if (!isNeed) {
- [showView dismiss];
- }
- };
- [showView show];
-
-
- //获取当前时间
- NSDate *date = [NSDate date];
- [[NSUserDefaults standardUserDefaults]setObject:date forKey:JZHomeUPdateApp];
- [[NSUserDefaults standardUserDefaults] synchronize];
- }
- #pragma mark ======================= layzer =======================
- - (NSMutableArray *)vcArray {
- if (!_vcArray) {
- _vcArray = [NSMutableArray array];
- }
- return _vcArray;
- }
- - (NSMutableArray *)titleArr {
- if (!_titleArr) {
- _titleArr = [NSMutableArray array];
- }
- return _titleArr;
- }
- - (NSMutableArray *)modelArr {
- if (!_modelArr) {
- _modelArr = [NSMutableArray array];
- }
- return _modelArr;
- }
- - (NSMutableArray *)hotSearchText {
- if (!_hotSearchText) {
- _hotSearchText = [NSMutableArray array];
- }
- return _hotSearchText;
- }
- - (NSMutableArray *)everyOneSearch {
- if (!_everyOneSearch) {
- _everyOneSearch = [NSMutableArray array];
- }
- return _everyOneSearch;
- }
- - (NSMutableArray *)adPopDataArr {
- if (!_adPopDataArr) {
- _adPopDataArr = [NSMutableArray array];
- }
- return _adPopDataArr;
- }
- - (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
|