口袋优选

KBHomeMainViewController.m 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. //
  2. // KBHomeMainViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/1/16.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBHomeMainViewController.h"
  9. #import "KBChildPageViewController.h"
  10. #import "KBScrollSearchView.h"
  11. #import "KBTodayViewController.h"
  12. #import "KBHomeChannelModel.h"
  13. #import "KBChannelPopView.h"
  14. #import "PYSearch.h"
  15. #import "KBShopCarViewController.h"
  16. #import "KBFindSearchResultViewController.h"
  17. #import "KBTaobaoAuthorView.h"
  18. #import "CCAlertShowView.h"
  19. #import "KBUpdateAlertView.h"
  20. #import "AdPopView.h"
  21. #import "AdPopModel.h"
  22. #import "AdJumpManager.h"
  23. #import "KBGetMoneyViewController.h"
  24. #import "NetworkTool.h"
  25. #import "YBCacheTool.h"
  26. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  27. #import "KBSignInViewController.h"
  28. #import "KBLoginViewController.h"
  29. #import "HotSearchModel.h"
  30. #import "KBGoodDetailViewController.h"
  31. #import "KBClassifyViewController.h"
  32. @interface KBHomeMainViewController ()<LPPageVCDelegate,LPPageVCDataSource,YHScrollSearchDelegate,YHChannelPopViewDelegate,PYSearchViewControllerDelegate> {
  33. NSInteger _selectedIndex;
  34. BOOL showNavBar;
  35. }
  36. @property (nonatomic, strong) NSMutableArray *vcArray;
  37. @property (nonatomic, strong) NSMutableArray *titleArr;
  38. @property (nonatomic, strong) NSMutableArray *modelArr;
  39. @property (nonatomic, strong) NSMutableArray *hotSearchText;
  40. @property (nonatomic, strong) NSMutableArray *everyOneSearch;
  41. @property (nonatomic, strong) NSMutableArray *adPopDataArr;
  42. @property (nonatomic, strong) KBScrollSearchView *searchView;
  43. @property (nonatomic, strong) KBTaobaoAuthorView *noNetworkView;
  44. @property (nonatomic, strong) NSArray *hotSearchModelArray;
  45. @property (nonatomic, strong) UIImageView *bgImageView;
  46. @end
  47. @implementation KBHomeMainViewController
  48. - (void)viewWillDisappear:(BOOL)animated {
  49. [super viewWillDisappear:animated];
  50. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  51. }
  52. - (void)viewDidAppear:(BOOL)animated {
  53. [super viewDidAppear:animated];
  54. if (showNavBar) {
  55. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  56. }else {
  57. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  58. }
  59. }
  60. - (void)viewDidLoad {
  61. [super viewDidLoad];
  62. [self configNavigationBar];
  63. [self loadHotSearchText];
  64. [self configSegmentDelegate];
  65. [self loadChildViewController];
  66. [self loadPopAdData];
  67. [self creatNetworkView];
  68. [self checkUpdateApp];
  69. [self addNotifationForHomePage];
  70. }
  71. - (void)configNavigationBar {
  72. self.bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, KStatusBarHeight+NavBarHeight+40+Fitsize(70))];
  73. self.bgImageView.contentMode = UIViewContentModeScaleAspectFill;
  74. self.bgImageView.backgroundColor = [UIColor YHColorWithHex:0xD5D5D5];
  75. [self.view addSubview:self.bgImageView];
  76. [self.view sendSubviewToBack:self.bgImageView];
  77. showNavBar = YES;
  78. self.view.backgroundColor = [UIColor yhGrayColor];
  79. [self.navigationBar setNavightionBarBackgroundColor:[UIColor clearColor]];
  80. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshData) name:ChangeSex object:nil];
  81. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollDirectorNoti:) name:ScrollDirectorNoti object:nil];
  82. UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  83. [rightBtn setImage:[UIImage imageNamed:@"home_sign"] forState:UIControlStateNormal];
  84. rightBtn.contentMode = UIViewContentModeScaleAspectFill;
  85. [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
  86. [self.navigationBar setCustomRightButtons:@[rightBtn]];
  87. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  88. [leftBtn setImage:[UIImage imageNamed:@"fenlei"] forState:UIControlStateNormal];
  89. [leftBtn setTitle:@"分类" forState:UIControlStateNormal];
  90. leftBtn.titleLabel.font = [UIFont systemFontOfSize:9];
  91. [leftBtn setButtonImageTitleStyle:ButtonImageTitleStyleTop padding:1];
  92. leftBtn.contentMode = UIViewContentModeScaleAspectFill;
  93. [leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
  94. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  95. }
  96. - (void)leftBtnClick {
  97. KBClassifyViewController *classify = [[KBClassifyViewController alloc] init];
  98. [self.navigationController pushViewController:classify animated:YES];
  99. }
  100. - (void)rightBtnClick {
  101. [MobClick event:ClickHomeSignIn];
  102. if (![AccountTool isLogin]) {
  103. [self goToLoginPage];
  104. return;
  105. }
  106. KBSignInViewController *sign = [[KBSignInViewController alloc] init];
  107. [self.navigationController pushViewController:sign animated:YES];
  108. }
  109. - (void)addNotifationForHomePage {
  110. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showAlertAction) name:KGlobalPopQueneKey object:nil];
  111. }
  112. - (void)showAlertAction {
  113. NSMutableArray *alertArray = [GlobalPopQueneManager shareManager].alertArray;
  114. if (alertArray.count > 0) {
  115. if (![GlobalPopQueneManager shareManager].isShowing) {
  116. CCAlertShowView *showView = alertArray.firstObject;
  117. [GlobalPopQueneManager shareManager].isShowing = YES;
  118. [showView show];
  119. [[GlobalPopQueneManager shareManager].alertArray removeObject:showView];
  120. }
  121. }
  122. }
  123. - (void)goToLoginPage {
  124. KBLoginViewController *login = [[KBLoginViewController alloc] init];
  125. [self presentViewController:login animated:YES completion:nil];
  126. }
  127. - (void)loadPopAdData {
  128. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adv/advByType",BaseURL];
  129. NSDictionary *para = @{@"adv_type":@"6"};
  130. [KBHttp get:url params:para success:^(id json) {
  131. NSArray *list = [NSArray yy_modelArrayWithClass:[AdPopModel class] json:json[@"data"]];
  132. [self.adPopDataArr addObjectsFromArray:list];
  133. [self creatPopView];
  134. } failure:^(NSError *error) {
  135. }];
  136. }
  137. - (void)creatPopView {
  138. if (self.adPopDataArr.count == 0 ) {
  139. return;
  140. }
  141. for (AdPopModel *model in self.adPopDataArr) {
  142. AdPopView *adPopView = [[AdPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) adModel:model];
  143. CCAlertShowView *showView = [CCAlertShowView alertViewWithView:adPopView];
  144. showView.tapBackgroundDismissEnable = NO;
  145. adPopView.clickBlock = ^(AdPopModel *model) {
  146. //跳转处理
  147. [AdJumpManager jumpToPageWithModel:model ParentViewControll:self];
  148. [showView dismiss];
  149. [GlobalPopQueneManager shareManager].isShowing = NO;
  150. [[NSNotificationCenter defaultCenter] postNotificationName:KGlobalPopQueneKey object:nil];
  151. };
  152. adPopView.closeBlock = ^{
  153. [showView dismiss];
  154. [GlobalPopQueneManager shareManager].isShowing = NO;
  155. [[NSNotificationCenter defaultCenter] postNotificationName:KGlobalPopQueneKey object:nil];
  156. };
  157. [[GlobalPopQueneManager shareManager].alertArray addObject:showView];
  158. [[NSNotificationCenter defaultCenter] postNotificationName:KGlobalPopQueneKey object:nil];
  159. }
  160. // AdPopModel *model = self.adPopDataArr.firstObject;
  161. // AdPopView *adPopView = [[AdPopView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(250), Fitsize(350)) adModel:model];
  162. // CCAlertShowView *showView = [CCAlertShowView alertViewWithView:adPopView];
  163. // showView.tapBackgroundDismissEnable = NO;
  164. // adPopView.clickBlock = ^(AdPopModel *model) {
  165. // //跳转处理
  166. //
  167. // [AdJumpManager jumpToPageWithModel:model ParentViewControll:self];
  168. // [self.adPopDataArr removeFirstObject];
  169. // [self creatPopView];
  170. // [showView dismiss];
  171. //
  172. // };
  173. // adPopView.closeBlock = ^{
  174. //
  175. // [self.adPopDataArr removeFirstObject];
  176. // [self creatPopView];
  177. // [showView dismiss];
  178. // };
  179. // [showView showInView:self.view];
  180. }
  181. - (void)configSegmentDelegate {
  182. // self.normalTextColor = [UIColor YHColorWithHex:0x444444];
  183. // self.higlightTextColor = [UIColor homeRedColor];
  184. // self.lineBackground = [UIColor homeRedColor];
  185. self.normalTextColor = [UIColor whiteColor];
  186. self.higlightTextColor = [UIColor whiteColor];
  187. self.lineBackground = [UIColor whiteColor];
  188. self.segmentStyle = LPPageVCSegmentStyleLineHighlight;
  189. self.delegate = self;
  190. self.dataSource = self;
  191. }
  192. - (void)creatNetworkView {
  193. // int state = [NetworkTool checkNetWorkPermission];
  194. //
  195. // switch (state) {
  196. // case 0:
  197. // [self showAletyWith:@"网络关闭"];
  198. // break;
  199. // case 1:
  200. // [self showAletyWith:@"仅wifi "];
  201. // break;
  202. // case 2:
  203. // [self showAletyWith:@"流量+wifi"];
  204. // break;
  205. //
  206. // default:
  207. // break;
  208. // }
  209. //
  210. if (![PublicFunction isAvailableNetworkType]) {
  211. self.noNetworkView = [[KBTaobaoAuthorView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) text:@"检测到当前网络不可用,请刷新试试。" clickBlock:^{
  212. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeSex object:nil];
  213. [self setupAlibcSDK];
  214. }];
  215. [self.noNetworkView.loginBtn setTitle:@"立即刷新" forState:UIControlStateNormal];
  216. [self.view addSubview:self.noNetworkView];
  217. // [userDefaults setObject:@(YES) forKey:@"FirstLaunched"];
  218. }
  219. }
  220. /**
  221. 配置阿里百川SDK
  222. */
  223. - (void)setupAlibcSDK {
  224. // 百川平台基础SDK初始化,加载并初始化各个业务能力插件
  225. [[AlibcTradeSDK sharedInstance] asyncInitWithSuccess:^{
  226. } failure:^(NSError *error) {
  227. NSLog(@"Init failed: %@", error.description);
  228. }];
  229. // 开发阶段打开日志开关,方便排查错误信息
  230. //默认调试模式打开日志,release关闭,可以不调用下面的函数
  231. // [[AlibcTradeSDK sharedInstance] setDebugLogOpen:YES];
  232. // 配置全局的淘客参数
  233. //如果没有阿里妈妈的淘客账号,setTaokeParams函数需要调用
  234. AlibcTradeTaokeParams *taokeParams = [[AlibcTradeTaokeParams alloc] init];
  235. taokeParams.pid = ALTK_PID; //mm_XXXXX为你自己申请的阿里妈妈淘客pid
  236. [[AlibcTradeSDK sharedInstance] setTaokeParams:taokeParams];
  237. //设置全局的app标识,在电商模块里等同于isv_code
  238. //没有申请过isv_code的接入方,默认不需要调用该函数
  239. [[AlibcTradeSDK sharedInstance] setISVCode:@"your_isv_code"];
  240. // 设置全局配置,是否强制使用h5
  241. [[AlibcTradeSDK sharedInstance] setIsForceH5:NO];
  242. }
  243. - (void)showAletyWith:(NSString *)msg {
  244. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:msg preferredStyle:UIAlertControllerStyleAlert];
  245. UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
  246. UIAlertAction *set = [UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  247. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  248. if([[UIApplication sharedApplication]canOpenURL:url] ) {
  249. if (@available(iOS 10.0, *)) {
  250. [[UIApplication sharedApplication] openURL:url options:@{}completionHandler:^(BOOL success) {
  251. }];
  252. } else {
  253. [[UIApplication sharedApplication]openURL:url];
  254. }
  255. }
  256. }];
  257. [alert addAction:cancel];
  258. [alert addAction:set];
  259. [self presentViewController:alert animated:YES completion:nil];
  260. }
  261. - (void)refreshData {
  262. [self loadChildViewController];
  263. [self loadHotSearchText];
  264. }
  265. /**
  266. 加载滚动热搜
  267. */
  268. - (void)loadHotSearchText {
  269. [KBCacheHttp get:HotSearch params:nil success:^(id json, BOOL isCache) {
  270. NSArray *list = json[@"data"];
  271. [self.hotSearchText removeAllObjects];
  272. for (NSDictionary *dic in list) {
  273. [self.hotSearchText addObject:dic[@"name"]];
  274. }
  275. if (!self.searchView) {
  276. self.searchView = [[KBScrollSearchView alloc] initWithFrame:CGRectMake(Fitsize(60), NavBarHeight-30-8, SCREEN_WIDTH-Fitsize(125), 30) andTitles:self.hotSearchText];
  277. self.searchView.delegate = self;
  278. }
  279. [self.navigationBar addSubview:self.searchView];
  280. } failure:^(NSError *error) {
  281. NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
  282. NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
  283. NSLog(@"服务器的错误原因:%@",str);
  284. if (!self.searchView) {
  285. self.searchView = [[KBScrollSearchView alloc] initWithFrame:CGRectMake(10, NavBarHeight-30-8, SCREEN_WIDTH-20, 30) andTitles:@[@"输入或粘贴商品标题"]];
  286. self.searchView.delegate = self;
  287. }
  288. [self.navigationBar addSubview:self.searchView];
  289. }];
  290. NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/goods/everyoneSearch", BaseURL];
  291. [KBCacheHttp get:urlString params:nil success:^(id json, BOOL isCache) {
  292. [self.everyOneSearch removeAllObjects];
  293. // for (NSDictionary *dic in json) {
  294. // [self.everyOneSearch addObject:dic];
  295. // }
  296. self.hotSearchModelArray = [NSArray yy_modelArrayWithClass:[HotSearchModel class] json:json];
  297. for (HotSearchModel *model in self.hotSearchModelArray) {
  298. [self.everyOneSearch addObject:model.name];
  299. }
  300. } failure:^(NSError *error) {
  301. }];
  302. }
  303. - (void)loadChildViewController {
  304. [KBCacheHttp get:ChannelList params:nil success:^(id json, BOOL isCache) {
  305. self.noNetworkView.hidden = YES;
  306. [self.modelArr removeAllObjects];
  307. _selectedIndex = 0;
  308. NSArray *list = json[@"data"];
  309. for (int i=0; i<list.count; i++) {
  310. NSDictionary *dic=list[i];
  311. KBHomeChannelModel *model = [KBHomeChannelModel yy_modelWithJSON:dic];
  312. [self.modelArr addObject:model];
  313. }
  314. [self changeSortByArr:self.modelArr];
  315. self.bottomLine.hidden = YES;
  316. } failure:^(NSError *error) {
  317. }];
  318. }
  319. #pragma mark -重新对标题页进行排序
  320. -(void)changeSortByArr:(NSArray *)arrList{
  321. NSArray *arrtmp=[arrList copy];
  322. [self.vcArray removeAllObjects];
  323. [self.titleArr removeAllObjects];
  324. [self.modelArr removeAllObjects];
  325. NSString *str=[[NSUserDefaults standardUserDefaults] objectForKey:@"sortArr"];
  326. NSArray *arr=[str componentsSeparatedByString:@","];
  327. NSMutableArray *mutArr=[NSMutableArray array];
  328. for (int i = 0; i < arrtmp.count; i++) {
  329. NSLog(@"is_move---%@",arrtmp[i]);
  330. KBHomeChannelModel *model = arrtmp[i];
  331. if (i== 0) {//先把0拿出来
  332. [self.modelArr addObject:model];
  333. KBTodayViewController *today = [[KBTodayViewController alloc] init];
  334. today.model = model;
  335. [self.vcArray addObject:today];
  336. [self.titleArr addObject:model.name];
  337. }else if([model.is_move integerValue]==0) {//把不可移动的拿出来
  338. KBChildPageViewController *child = [[KBChildPageViewController alloc] init];
  339. child.model = model;
  340. [self.modelArr addObject:model];
  341. [self.vcArray addObject:child];
  342. [self.titleArr addObject:model.name];
  343. }else{//把可以移动的放到mutarr中
  344. [mutArr addObject:model];
  345. }
  346. }
  347. NSMutableArray *mutArr2=[NSMutableArray arrayWithArray:mutArr];//复制一份
  348. // 对本地存储字符串进行 mut排序
  349. for (NSString *ID in arr) {
  350. for (KBHomeChannelModel *model in mutArr) {
  351. if ([model.Id isEqualToString:ID]) {
  352. KBChildPageViewController *child = [[KBChildPageViewController alloc] init];
  353. child.model = model;
  354. [self.modelArr addObject:model];
  355. [self.vcArray addObject:child];
  356. [self.titleArr addObject:model.name];
  357. [mutArr2 removeObject:model];
  358. }
  359. }
  360. }
  361. if (mutArr2.count>0) {
  362. for (KBHomeChannelModel *model in mutArr2) {
  363. KBChildPageViewController *child = [[KBChildPageViewController alloc] init];
  364. child.model = model;
  365. [self.modelArr addObject:model];
  366. [self.vcArray addObject:child];
  367. [self.titleArr addObject:model.name];
  368. }
  369. }
  370. [self reloadData];
  371. }
  372. /**
  373. 购物车
  374. */
  375. - (void)gotoShoppingCar {
  376. KBShopCarViewController *shopCar = [[KBShopCarViewController alloc] init];
  377. [self.navigationController pushViewController:shopCar animated:YES];
  378. }
  379. - (void)scrollDirectorNoti:(NSNotification *)noti{
  380. NSDictionary *info = noti.userInfo;
  381. CGFloat director = [info[@"director"] floatValue];
  382. if (director <- 10) {
  383. [UIView animateWithDuration:0.3 animations:^{
  384. self.bgImageView.y = -Fitsize(70)-KStatusBarHeight+10;
  385. }];
  386. }else if (director > 10) {
  387. [UIView animateWithDuration:0.3 animations:^{
  388. self.bgImageView.y = 0;
  389. }];
  390. }
  391. // NSDictionary *info = noti.userInfo;
  392. // CGFloat director = [info[@"director"] floatValue];
  393. // if (director <- 10) {
  394. // //向上拖动,隐藏导航栏
  395. // if (self.navigationBar.y == -NavBarHeight) {
  396. // return;
  397. // }
  398. //
  399. // [UIView animateWithDuration:0.15 animations:^{
  400. // self.navigationBar.y = -NavBarHeight+KStatusBarHeight;
  401. // self.searchView.alpha = 0;
  402. // self.navigationBar.backgroundColor = [UIColor whiteColor];
  403. // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  404. // showNavBar = NO;
  405. // [_segmentScrollView layoutIfNeeded];
  406. // }];
  407. //
  408. // }else if (director > 10) {
  409. // //向下拖动,显示导航栏
  410. // if (self.navigationBar.y == 0) {
  411. // return;
  412. // }
  413. //
  414. // [UIView animateWithDuration:0.15 animations:^{
  415. // self.navigationBar.y = 0;
  416. // self.searchView.alpha = 1;
  417. // self.navigationBar.backgroundColor = [UIColor clearColor];
  418. // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  419. // showNavBar = YES;
  420. // [_segmentScrollView layoutIfNeeded];
  421. // }];
  422. //
  423. // }else if(director == 0){
  424. // //停止拖拽
  425. // }
  426. }
  427. #pragma mark ======================= LPPageVC Delegate & DataSource =======================
  428. - (UIViewController *)pageVC:(LPPageVC *)pageVC viewControllerAtIndex:(NSInteger)index{
  429. return self.vcArray[index];
  430. }
  431. - (NSString *)pageVC:(LPPageVC *)pageVC titleAtIndex:(NSInteger)index{
  432. return self.titleArr[index];
  433. }
  434. - (NSInteger)numberOfContentForPageVC:(LPPageVC *)pageVC {
  435. return self.titleArr.count;
  436. }
  437. - (void)pageVC:(LPPageVC *)pageVC didClickEditMode:(LPPageVCEditMode)mode {
  438. KBChannelPopView *popView = [[KBChannelPopView alloc] initWithmodels:self.modelArr delegate:self selectedIndex:_selectedIndex superVc:self];
  439. popView.changeSortBlock = ^{
  440. [self changeSortByArr:self.modelArr];
  441. };
  442. [popView showInView:self.view belowSubView:self.navigationBar];
  443. }
  444. - (void)pageVC:(LPPageVC *)pageVC didChangeToIndex:(NSInteger)toIndex fromIndex:(NSInteger)fromIndex {
  445. _selectedIndex = toIndex;
  446. NSInteger index = toIndex;
  447. if (toIndex<0 || toIndex >self.modelArr.count-1) {
  448. index = 0;
  449. }
  450. KBHomeChannelModel *model = self.modelArr[index];
  451. [self.bgImageView sd_setImageWithURL:[NSURL URLWithString:model.back_img] placeholderImage:nil];
  452. [MobClick event:top_classify label:self.titleArr[toIndex]];
  453. }
  454. #pragma mark ================= YHChannelPopViewDelegate ============
  455. - (void)YHChannelPopViewDidSelectedIndex:(NSInteger)index {
  456. [self setSelectedIndex:index];
  457. }
  458. #pragma mark ======================= YHScrollSearchViewDelegate=========
  459. - (void)clickTitleButton:(UIButton *)button {
  460. [self createSearchViewControllerWith:button.titleLabel.text];
  461. }
  462. - (void)createSearchViewControllerWith:(NSString *)text {
  463. PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:@[] searchBarPlaceholder:text];
  464. // searchViewController.swapHotSeachWithSearchHistory = YES;
  465. searchViewController.searchHistoryStyle = PYSearchHistoryStyleARCBorderTag;
  466. searchViewController.hotSearchStyle = PYHotSearchStyleARCBorderTag;
  467. searchViewController.searchTextField.font = [UIFont systemFontOfSize:13];
  468. searchViewController.searchTextField.enablesReturnKeyAutomatically = NO;
  469. searchViewController.delegate = self;
  470. [self getHotSearchToSearchViewController:searchViewController];
  471. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController];
  472. [self presentViewController:nav animated:NO completion:^{
  473. // for (int i = 0; i < searchViewController.hotSearchTags.count; i++) {
  474. // UILabel *tag = searchViewController.hotSearchTags[i];
  475. // NSDictionary *dic = self.everyOneSearch[i];
  476. // if ([dic[@"color"] boolValue]) {
  477. //// tag.layer.borderColor = [UIColor homeRedColor].CGColor;
  478. // tag.textColor = [UIColor homeRedColor];
  479. // }
  480. // }
  481. }];
  482. searchViewController.didSearchBlock = ^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
  483. //处理搜索点击事件
  484. [MobClick event:search_count label:Search_Normal];
  485. KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
  486. resultVC.searchBar = searchBar;
  487. resultVC.searchName = searchText;
  488. if (searchText.length == 0) {
  489. searchBar.text = searchBar.placeholder;
  490. resultVC.searchName = searchBar.placeholder;
  491. }
  492. searchViewController.searchSuggestions = nil;
  493. [nav pushViewController:resultVC animated:NO];
  494. };
  495. }
  496. /**
  497. 加载热门搜索
  498. */
  499. - (void)getHotSearchToSearchViewController:(PYSearchViewController *)searchViewController {
  500. searchViewController.hotSearchModelArray = self.hotSearchModelArray;
  501. searchViewController.hotSearches = self.everyOneSearch;
  502. }
  503. #pragma mark - PYSearchViewControllerDelegate
  504. /**
  505. 输入完成时触发
  506. */
  507. - (void)searchViewController:(PYSearchViewController *)searchViewController searchTextDidChange:(UISearchBar *)seachBar searchText:(NSString *)searchText
  508. {
  509. if (searchText.length) {
  510. [KBHttp get:SearchAdvice params:@{@"name":searchText} success:^(id json) {
  511. NSArray *list = json[@"data"];
  512. searchViewController.searchSuggestions = list;
  513. } failure:^(NSError *error) {
  514. }];
  515. }
  516. }
  517. /**
  518. 点击建议
  519. */
  520. - (void)searchViewController:(PYSearchViewController *)searchViewController
  521. didSelectSearchSuggestionAtIndex:(NSInteger)index
  522. searchText:(NSString *)searchText {
  523. KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
  524. resultVC.searchName = searchText;
  525. resultVC.searchBar = searchViewController.searchBar;
  526. [searchViewController.navigationController pushViewController:resultVC animated:NO];
  527. }
  528. /**
  529. 点击热搜
  530. */
  531. - (void)searchViewController:(PYSearchViewController *)searchViewController
  532. didSelectHotSearchAtIndex:(NSInteger)index
  533. searchText:(NSString *)searchText {
  534. HotSearchModel *model = self.hotSearchModelArray[index];
  535. if ([model.type isEqualToString:@"0"]) {
  536. KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
  537. resultVC.searchName = model.name;
  538. resultVC.searchBar = searchViewController.searchBar;
  539. [searchViewController.navigationController pushViewController:resultVC animated:NO];
  540. }else {
  541. KBGoodDetailViewController *detail = [[KBGoodDetailViewController alloc] init];
  542. DetailRequestModel *requestModel = [[DetailRequestModel alloc]
  543. initWithId:model.goods_id
  544. is_coupon:model.is_coupon
  545. coupon_price:model.coupon_price
  546. price:model.price
  547. discount_price:model.discount_price
  548. commission_rate:model.commission_rate
  549. coupon_start_time:model.coupon_start_time
  550. coupon_end_time:model.coupon_end_time];
  551. detail.requestModel = requestModel;
  552. [searchViewController.navigationController pushViewController:detail animated:YES];
  553. }
  554. [MobClick event:search_count label:Search_Hot_String];
  555. }
  556. /**
  557. 点击历史
  558. */
  559. - (void)searchViewController:(PYSearchViewController *)searchViewController
  560. didSelectSearchHistoryAtIndex:(NSInteger)index
  561. searchText:(NSString *)searchText {
  562. NSArray *searchHistory = [searchViewController getHistorySearchArray];
  563. HotSearchModel *model = searchHistory[index];
  564. if ([model.type isEqualToString:@"0"]) {
  565. KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
  566. resultVC.searchName = model.name;
  567. resultVC.searchBar = searchViewController.searchBar;
  568. [searchViewController.navigationController pushViewController:resultVC animated:NO];
  569. }else {
  570. KBGoodDetailViewController *detail = [[KBGoodDetailViewController alloc] init];
  571. DetailRequestModel *requestModel = [[DetailRequestModel alloc]
  572. initWithId:model.goods_id
  573. is_coupon:model.is_coupon
  574. coupon_price:model.coupon_price
  575. price:model.price
  576. discount_price:model.discount_price
  577. commission_rate:model.commission_rate
  578. coupon_start_time:model.coupon_start_time
  579. coupon_end_time:model.coupon_end_time];
  580. detail.requestModel = requestModel;
  581. [searchViewController.navigationController pushViewController:detail animated:YES];
  582. }
  583. [MobClick event:search_count label:Search_History_String];
  584. }
  585. #pragma mark ------------------ 版本更新检测 ------
  586. /**
  587. 监测是否更新app
  588. */
  589. - (void)checkUpdateApp{
  590. [KBHttp post:Check_Update params:nil success:^(id json) {
  591. NSString *isUpdate = json[@"data"][@"status"];
  592. NSString *isNeeded = json[@"data"][@"type"];
  593. NSString *message = json[@"data"][@"content"];
  594. //强制更新
  595. if ([isUpdate boolValue] && [isNeeded boolValue]){
  596. [self showAlertWithNeedUpdate:YES message:message];
  597. return ;
  598. }
  599. //非强制更新
  600. if ([isUpdate boolValue]) {
  601. if (![[NSUserDefaults standardUserDefaults] objectForKey:JZHomeUPdateApp]) {
  602. [self showAlertWithNeedUpdate:[isNeeded boolValue] message:message];
  603. } else{
  604. NSDate *date = [[NSUserDefaults standardUserDefaults] objectForKey:JZHomeUPdateApp];
  605. CGFloat timeinterval = [[NSString stringWithFormat:@"%.0f",[[NSDate date] timeIntervalSinceDate:date]] floatValue];
  606. if ((timeinterval > 60*60*24*3)) {
  607. [self showAlertWithNeedUpdate:[isNeeded boolValue] message:message];
  608. }
  609. }
  610. }
  611. } failure:^(NSError *error) {
  612. }];
  613. }
  614. - (void)showAlertWithNeedUpdate:(BOOL)isNeed message:(NSString *)message{
  615. KBUpdateAlertView *popView = [[KBUpdateAlertView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(257), Fitsize(406)) text:message isNeeded:isNeed];
  616. CCAlertShowView *showView = [CCAlertShowView alertViewWithView:popView];
  617. showView.tapBackgroundDismissEnable = NO;
  618. popView.cancelBlock = ^{
  619. [showView dismiss];
  620. };
  621. popView.sureBlock = ^{
  622. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:APP_STORE_URL]];
  623. if (!isNeed) {
  624. [showView dismiss];
  625. }
  626. };
  627. [showView show];
  628. //获取当前时间
  629. NSDate *date = [NSDate date];
  630. [[NSUserDefaults standardUserDefaults]setObject:date forKey:JZHomeUPdateApp];
  631. [[NSUserDefaults standardUserDefaults] synchronize];
  632. }
  633. #pragma mark ======================= layzer =======================
  634. - (NSMutableArray *)vcArray {
  635. if (!_vcArray) {
  636. _vcArray = [NSMutableArray array];
  637. }
  638. return _vcArray;
  639. }
  640. - (NSMutableArray *)titleArr {
  641. if (!_titleArr) {
  642. _titleArr = [NSMutableArray array];
  643. }
  644. return _titleArr;
  645. }
  646. - (NSMutableArray *)modelArr {
  647. if (!_modelArr) {
  648. _modelArr = [NSMutableArray array];
  649. }
  650. return _modelArr;
  651. }
  652. - (NSMutableArray *)hotSearchText {
  653. if (!_hotSearchText) {
  654. _hotSearchText = [NSMutableArray array];
  655. }
  656. return _hotSearchText;
  657. }
  658. - (NSMutableArray *)everyOneSearch {
  659. if (!_everyOneSearch) {
  660. _everyOneSearch = [NSMutableArray array];
  661. }
  662. return _everyOneSearch;
  663. }
  664. - (NSMutableArray *)adPopDataArr {
  665. if (!_adPopDataArr) {
  666. _adPopDataArr = [NSMutableArray array];
  667. }
  668. return _adPopDataArr;
  669. }
  670. - (void)didReceiveMemoryWarning {
  671. [super didReceiveMemoryWarning];
  672. // Dispose of any resources that can be recreated.
  673. }
  674. /*
  675. #pragma mark - Navigation
  676. // In a storyboard-based application, you will often want to do a little preparation before navigation
  677. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  678. // Get the new view controller using [segue destinationViewController].
  679. // Pass the selected object to the new view controller.
  680. }
  681. */
  682. @end