口袋优选

KBTodayViewController.m 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  1. //
  2. // KBTodayViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/17.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBTodayViewController.h"
  9. #import "SDCycleScrollView.h"
  10. #import "KBOnePicCell.h"
  11. #import "KBCountHeaderView.h"
  12. #import "KBMorePicCell.h"
  13. #import "KBTodayBannerModel.h"
  14. #import "KBChildGoodModel.h"
  15. #import "KBMorePicModel.h"
  16. #import "KBGoodsInfo.h"
  17. #import "KBAdversementCell.h"
  18. #import "KBGoodDetailViewController.h"
  19. #import "KBGoodListCidViewController.h"
  20. #import "KBWebDetailController.h"
  21. #import "KBGoodListViewController.h"
  22. #import "KBNineNineMainViewController.h"
  23. #import "KBMorePicCollectionCell.h"
  24. #import "KBMorePicCollectionModel.h"
  25. #import "KBGoodCollectionCell.h"
  26. #import "KBShareGoodsModel.h"
  27. #import "KBShareGoodsViewController.h"
  28. #import "KBPrivilegeReferralViewController.h"
  29. #import "NSNumber+YHExpanded.h"
  30. #import "KBTodayModelCollectionCell.h"
  31. #import "KBRankListViewController.h"
  32. #import "KBTodayMudleModel.h"
  33. #import "KBCategoryListViewContoller.h"
  34. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  35. #import <AlibabaAuthSDK/ALBBSession.h>
  36. #import <AlibabaAuthSDK/ALBBSDK.h>
  37. #import "KBGetMoneyViewController.h"
  38. #import "KBBuyLimitMainController.h"
  39. #import "KBTodayReatCollectionCell.h"
  40. #import "AdPopModel.h"
  41. #import "LDTodayAdView.h"
  42. #import "AdJumpManager.h"
  43. #import "NewPagedFlowView.h"
  44. static NSString *KYHMorePicCollectionCell = @"KYHMorePicCollectionCell";
  45. static NSString *KYHMorePicCell = @"KYHMorePicCell";
  46. static NSString *KYHGoodCollectionCell = @"KYHGoodCollectionCell";
  47. static NSString *KModelCollecionCell = @"modelCollecionCell";
  48. static NSString *KReactCollecionCell = @"ReactCollecionCell";
  49. static NSString *KSectionOne = @"KSectionOne";
  50. static NSString *KSectionTwo = @"KSectionTwo";
  51. static NSString *KSectionThree = @"KSectionThree";
  52. static NSString *KSectionAd = @"KSectionAd";
  53. static CGFloat bannerHeight = 150;
  54. @interface KBTodayViewController ()
  55. <
  56. UICollectionViewDelegate,
  57. UICollectionViewDataSource,
  58. UICollectionViewDelegateFlowLayout,
  59. SDCycleScrollViewDelegate,
  60. YHMorePicCellDelegate,
  61. YHMorePicCollectionCellDelegate,
  62. LDTodayModelCollectionCellDelegate,
  63. YHCountDownViewDelegate,
  64. NewPagedFlowViewDelegate,
  65. NewPagedFlowViewDataSource
  66. >
  67. {
  68. NSInteger _page;
  69. LDTodayAdView *_adView;
  70. NSArray *_adDataArr;
  71. }
  72. @property (nonatomic, strong) UICollectionView *collectionView;
  73. @property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
  74. @property (nonatomic, strong) NSArray *bannerList;
  75. @property (nonatomic, strong) NSMutableArray *goodsArr;
  76. @property (nonatomic, strong) KBMorePicCell *morePicCell;
  77. @property (nonatomic, strong) KBMorePicCollectionCell *morePicCollectionCell;
  78. @property (nonatomic, strong) NSArray *morePicArr;
  79. @property (nonatomic, strong) NSArray *morePicCollectionArr;
  80. @property (nonatomic, strong) NSMutableArray *moduleDataArr;
  81. @property (nonatomic, strong) KBGoodsInfo *goodsInfo; //商品信息,包括刷新事件
  82. @property (nonatomic, strong) NewPagedFlowView *NewPagedFlowView;
  83. /**组头*/
  84. @property (nonatomic, strong) UICollectionReusableView *sectionOne;
  85. @property (nonatomic, strong) UICollectionReusableView *sectionThree;
  86. @end
  87. @implementation KBTodayViewController
  88. - (void)viewDidLoad {
  89. [super viewDidLoad];
  90. [self configCollectionView];
  91. [self request];
  92. [self.collectionView reloadData];
  93. }
  94. - (void)request {
  95. [self loadBannerData];
  96. [self loadHotRecomPicCollectionData];
  97. [self loadHotRecomPicData];
  98. [self loadModelCellData];
  99. [self loadCategoryGoodsList];
  100. [self loadAdData];
  101. }
  102. - (void)configCollectionView {
  103. _page = 1;
  104. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  105. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, ChildTableViewHeight+40) collectionViewLayout:flowLayout];
  106. flowLayout.minimumLineSpacing = 5;
  107. flowLayout.minimumInteritemSpacing = 1;
  108. self.collectionView.showsVerticalScrollIndicator=NO;
  109. self.collectionView.showsHorizontalScrollIndicator=NO;
  110. [self.collectionView registerClass:[KBMorePicCollectionCell class] forCellWithReuseIdentifier:KYHMorePicCollectionCell];
  111. [self.collectionView registerClass:[KBMorePicCell class] forCellWithReuseIdentifier:KYHMorePicCell];
  112. [self.collectionView registerClass:[KBGoodCollectionCell class] forCellWithReuseIdentifier:KYHGoodCollectionCell];
  113. [self.collectionView registerClass:[KBTodayModelCollectionCell class] forCellWithReuseIdentifier:KModelCollecionCell];
  114. [self.collectionView registerClass:[KBTodayReatCollectionCell class] forCellWithReuseIdentifier:KReactCollecionCell];
  115. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionOne];
  116. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionTwo];
  117. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionThree];
  118. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionAd];
  119. // self.collectionView.backgroundColor = [UIColor YHColorWithHex:0xf6f6f6];
  120. self.collectionView.backgroundColor = [UIColor clearColor];
  121. self.collectionView.layer.masksToBounds=YES;
  122. self.collectionView.delegate = self;
  123. self.collectionView.dataSource = self;
  124. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  125. [self refreshData];
  126. }];
  127. header.activityIndicatorViewStyle=UIActivityIndicatorViewStyleWhite;
  128. header.stateLabel.textColor=[UIColor whiteColor];
  129. header.lastUpdatedTimeLabel.hidden=YES;
  130. [header setTitle:@"数据正在刷新" forState:MJRefreshStateRefreshing];
  131. // header.lastUpdatedTimeLabel.hidden = YES;
  132. // header.stateLabel.hidden = YES;
  133. //正在刷新的图片
  134. // NSArray *imgArr = @[[UIImage imageNamed:@"ant1"],[UIImage imageNamed:@"ant2"]];
  135. // [header setImages:imgArr duration:0.3 forState:MJRefreshStateRefreshing];
  136. // [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStateWillRefresh];
  137. // [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStatePulling];
  138. self.collectionView.mj_header = header;
  139. self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  140. [self loadMoreData];
  141. }];
  142. [self.collectionView.mj_footer beginRefreshing];
  143. if (@available(iOS 11.0, *)) {
  144. self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用
  145. }else {
  146. self.automaticallyAdjustsScrollViewInsets = NO;
  147. }
  148. [self.view addSubview:self.collectionView];
  149. // CGFloat height = (bannerHeight/375.f)*SCREEN_WIDTH;
  150. // CGRect rect = CGRectMake(FITSIZE(10), 3, SCREEN_WIDTH-FITSIZE(20), height);
  151. //
  152. // self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:rect delegate:self placeholderImage:nil];
  153. // self.cycleScrollView.backgroundColor=[UIColor clearColor];
  154. // self.cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"page_sel"];
  155. // self.cycleScrollView.pageDotImage = [UIImage imageNamed:@"page_nor"];
  156. //
  157. // self.cycleScrollView.layer.masksToBounds=YES;
  158. // self.cycleScrollView.clipsToBounds = YES;
  159. // self.cycleScrollView.layer.shadowColor = [UIColor YHColorWithHex:0x000000].CGColor;
  160. // self.cycleScrollView.layer.shadowOffset = CGSizeMake(3,3);
  161. // self.cycleScrollView.layer.shadowOpacity = 0.2f;
  162. // self.cycleScrollView.layer.shadowRadius = 3;
  163. // self.cycleScrollView.layer.cornerRadius=5;
  164. // self.cycleScrollView.autoScrollTimeInterval=3;
  165. // self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleToFill;
  166. self.NewPagedFlowView = [[NewPagedFlowView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH * bannerHeight / 375)];
  167. self.NewPagedFlowView.backgroundColor = [UIColor clearColor];
  168. self.NewPagedFlowView.delegate = self;
  169. self.NewPagedFlowView.dataSource = self;
  170. self.NewPagedFlowView.minimumPageAlpha = 0.1;
  171. self.NewPagedFlowView.isCarousel = YES;
  172. self.NewPagedFlowView.orientation = NewPagedFlowViewOrientationHorizontal;
  173. self.NewPagedFlowView.isOpenAutoScroll = YES;
  174. self.NewPagedFlowView.layer.shadowOffset = CGSizeMake(2, 5);
  175. self.NewPagedFlowView.layer.shadowOpacity = 0.3;
  176. self.NewPagedFlowView.layer.shadowColor = [UIColor blackColor].CGColor;
  177. }
  178. - (void)loadAdData {
  179. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adv/advByType",BaseURL];
  180. NSDictionary *para = @{@"adv_type":@"1"};
  181. [KBHttp get:url params:para success:^(id json) {
  182. _adDataArr = [NSArray yy_modelArrayWithClass:[AdPopModel class] json:json[@"data"]];
  183. if (_adDataArr.count > 0) {
  184. [self creatAdView:_adDataArr];
  185. }
  186. [self.collectionView reloadData];
  187. } failure:^(NSError *error) {
  188. }];
  189. }
  190. - (void)creatAdView:(NSArray *)list {
  191. // LDTodayAdView *adView = [[LDTodayAdView alloc] initWithFrame:CGRectMake(Fitsize(10), Fitsize(3), SCREEN_WIDTH-Fitsize(20), (SCREEN_WIDTH-Fitsize(20))*200/750)];
  192. LDTodayAdView *adView = [[LDTodayAdView alloc] initWithFrame:CGRectMake(Fitsize(10), 5, SCREEN_WIDTH-Fitsize(20), (SCREEN_WIDTH-Fitsize(20))*200/750)];
  193. _adView.tag=2002;
  194. _adView = adView;
  195. _adView.model = list.firstObject;
  196. adView.tapAdBlock = ^{
  197. [MobClick event:AdvClick label:@"1"];
  198. [AdJumpManager jumpToPageWithModel:list.firstObject ParentViewControll:self];
  199. };
  200. }
  201. - (void)loadBannerData {
  202. [KBCacheHttp get:Banner_list params:nil success:^(id json, BOOL isCache) {
  203. self.bannerList = [NSArray yy_modelArrayWithClass:[KBTodayBannerModel class] json:json[@"data"]];
  204. [self creatCycleScrollView];
  205. } failure:^(NSError *error) {
  206. }];
  207. }
  208. - (void)creatCycleScrollView {
  209. NSMutableArray *imgArr = [NSMutableArray array];
  210. for (KBTodayBannerModel *model in self.bannerList) {
  211. [imgArr addObject:model.photo];
  212. }
  213. // self.cycleScrollView.imageURLStringsGroup = imgArr;
  214. [self.NewPagedFlowView reloadData];
  215. }
  216. /**
  217. 加载下部商品列表
  218. */
  219. - (void)loadCategoryGoodsList {
  220. NSDictionary *para = @{@"sort":@"1",
  221. @"page":@(_page),
  222. @"category_id":self.model.Id,
  223. @"stype":@"0"};
  224. [KBCacheHttp post:StocklistByCategoryId params:para success:^(id json, BOOL isCache) {
  225. if ([self.collectionView.mj_header isRefreshing]) [self.goodsArr removeAllObjects];
  226. //清空缓存数据,展示真正的数据(如果page是1,且不是缓存数据,说明是真正的数据)
  227. if (_page == 1 && !isCache) [self.goodsArr removeAllObjects];
  228. self.goodsInfo = [KBGoodsInfo yy_modelWithJSON:json];
  229. NSArray *list = [NSArray yy_modelArrayWithClass:[KBChildGoodModel class] json:json[@"data"]];
  230. [self noMoreDataWithArray:list];
  231. [self.goodsArr addObjectsFromArray:list];
  232. [self.collectionView reloadData];
  233. } failure:^(NSError *error) {
  234. [self endRefreshing];
  235. [self.collectionView.mj_footer endRefreshing];
  236. }];
  237. }
  238. - (void)noMoreDataWithArray:(NSArray *)array {
  239. if (array.count <= 0) {
  240. [self.collectionView.mj_footer endRefreshingWithNoMoreData];
  241. }else {
  242. [self.collectionView.mj_footer endRefreshing];
  243. }
  244. }
  245. - (void)endRefreshing {
  246. [self.collectionView.mj_header endRefreshing];
  247. }
  248. - (void)refreshData {
  249. _page = 1;
  250. [self loadBannerData];
  251. [self loadModelCellData];
  252. [self loadHotRecomPicData];
  253. [self loadHotRecomPicCollectionData];
  254. [self loadCategoryGoodsList];
  255. [self loadAdData];
  256. }
  257. /**
  258. 上拉加载
  259. */
  260. - (void)loadMoreData {
  261. _page++;
  262. [self loadCategoryGoodsList];
  263. }
  264. /**
  265. 多图推荐
  266. */
  267. - (void)loadHotRecomPicData {
  268. [KBCacheHttp get:Goldgroups params:nil success:^(id json, BOOL isCache) {
  269. self.morePicArr = [NSArray yy_modelArrayWithClass:[KBMorePicModel class] json:json[@"data"]];
  270. if (self.morePicArr.count==0) {
  271. [self.collectionView reloadData];
  272. }
  273. // [self.morePicCell setModelDatas:self.morePicArr];
  274. [self.collectionView reloadData];
  275. } failure:^(NSError *error) {
  276. }];
  277. }
  278. /**
  279. 加载菜单栏目
  280. */
  281. - (void)loadHotRecomPicCollectionData {
  282. [KBCacheHttp get:GoldCollectiongroups params:nil success:^(id json, BOOL isCache) {
  283. self.morePicCollectionArr = [NSArray yy_modelArrayWithClass:[KBMorePicCollectionModel class] json:json[@"data"]];
  284. [self.morePicCollectionCell setModelDatas:self.morePicCollectionArr];
  285. [self.collectionView reloadData];
  286. } failure:^(NSError *error) {
  287. }];
  288. }
  289. /**
  290. 加载分类模块数据
  291. */
  292. - (void)loadModelCellData {
  293. NSString *url = [NSString stringWithFormat:@"%@/api/v2/channel/advFourList",BaseURL];
  294. [KBCacheHttp post:url params:@{@"platform":@"2"} success:^(id json, BOOL isCache) {
  295. NSArray *list = [NSArray yy_modelArrayWithClass:[KBTodayMudleModel class] json:json[@"list"]];
  296. if (list.count > 0) {
  297. [self countDownViewSetCount:list.firstObject];
  298. }
  299. [self.moduleDataArr removeAllObjects];
  300. [self.moduleDataArr addObjectsFromArray:list];
  301. [self.collectionView reloadData];
  302. [self endRefreshing];
  303. } failure:^(NSError *error) {
  304. [self endRefreshing];
  305. }];
  306. }
  307. - (void)countDownViewSetCount:(KBTodayMudleModel *)model {
  308. NSString *endTime = [NSString stringWithFormat:@"%@000",model.remainTime];
  309. [[KBCountDownView shareInstace] setEndTimer:endTime];
  310. }
  311. #pragma mark ====
  312. #pragma mark NewPagedFlowView Delegate
  313. - (CGSize)sizeForPageInFlowView:(NewPagedFlowView *)flowView {
  314. return CGSizeMake(SCREEN_WIDTH - 40, (SCREEN_WIDTH - 40) * 150 / 375);
  315. }
  316. - (void)didSelectCell:(UIView *)subView withSubViewIndex:(NSInteger)subIndex {
  317. KBTodayBannerModel *model = self.bannerList[subIndex];
  318. if (model.url.length > 0) {
  319. //活动页
  320. //type为2直接打开淘宝,无需访问中间网页
  321. if ([model.type isEqualToString:@"2"]) {
  322. [self jumpToTaobaoWithUrl:model.url];
  323. }else{
  324. KBWebDetailController *adWeb = [[KBWebDetailController alloc] init];
  325. adWeb.url = model.url;
  326. [self.navigationController pushViewController:adWeb animated:YES];
  327. }
  328. }else {
  329. //列表页
  330. KBGoodListViewController *list = [[KBGoodListViewController alloc] init];
  331. list.cate_id = model.group_id;
  332. list.name = model.note;
  333. [self.navigationController pushViewController:list animated:YES];
  334. }
  335. [MobClick event:home_banner label:model.photo];
  336. }
  337. #pragma mark NewPagedFlowView Datasource
  338. - (NSInteger)numberOfPagesInFlowView:(NewPagedFlowView *)flowView {
  339. return self.bannerList.count;
  340. }
  341. - (PGIndexBannerSubiew *)flowView:(NewPagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{
  342. PGIndexBannerSubiew *bannerView = [flowView dequeueReusableCell];
  343. if (!bannerView) {
  344. bannerView = [[PGIndexBannerSubiew alloc] init];
  345. bannerView.tag = index;
  346. bannerView.layer.cornerRadius = 4;
  347. bannerView.layer.masksToBounds = YES;
  348. }
  349. if (self.bannerList.count > 0 && self.bannerList.count>index) {
  350. KBTodayBannerModel *model = self.bannerList[index];
  351. //在这里下载网络图片
  352. [bannerView.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.photo] placeholderImage:[UIImage imageNamed:@""]];
  353. }
  354. return bannerView;
  355. }
  356. #pragma mark ------ YHCountDownViewDelegate -------
  357. - (void)countViewTimeOutAction {
  358. [self.collectionView.mj_header beginRefreshing];
  359. }
  360. #pragma mark ====================== YHMorePicCellDelegate==========
  361. /**
  362. 点击推荐位多图
  363. */
  364. - (void)YHMorePicCellDidSelectedItem:(NSInteger)index {
  365. KBMorePicModel *model = self.morePicArr[index];
  366. if (model.url.length > 0) {
  367. //活动页
  368. //type为2直接打开淘宝,无需访问中间网页
  369. if ([model.jump_type isEqualToString:@"2"]) {
  370. [self jumpToTaobaoWithUrl:model.url];
  371. }else{
  372. KBWebDetailController *adWeb = [[KBWebDetailController alloc] init];
  373. adWeb.url = model.url;
  374. [self.navigationController pushViewController:adWeb animated:YES];
  375. }
  376. }else {
  377. //列表页
  378. KBGoodListViewController *list = [[KBGoodListViewController alloc] init];
  379. list.cate_id = model.Id;
  380. list.name = model.name;
  381. [self.navigationController pushViewController:list animated:YES];
  382. }
  383. [MobClick event:home_recommend label:model.name];
  384. }
  385. #pragma mark ====================== YHMorePicCollectionCellDelegate==========
  386. - (void)YHMorePicCollectionCellDidSelectedItem:(NSInteger)index{
  387. KBMorePicCollectionModel *model = self.morePicCollectionArr[index];
  388. if (model.url.length > 0) {
  389. //活动页
  390. //type为2直接打开淘宝,无需访问中间网页
  391. if ([model.jump_type isEqualToString:@"2"]) {
  392. [self jumpToTaobaoWithUrl:model.url];
  393. }else{
  394. KBWebDetailController *adWeb = [[KBWebDetailController alloc] init];
  395. adWeb.url = model.url;
  396. [self.navigationController pushViewController:adWeb animated:YES];
  397. }
  398. }else {
  399. KBGoodListViewController *list = [[KBGoodListViewController alloc] init];
  400. list.cate_id = model.Id;
  401. list.name = model.name;
  402. [self.navigationController pushViewController:list animated:YES];
  403. }
  404. [MobClick event:Home_Items label:model.name];
  405. }
  406. #pragma mark ============ SDCycleScrollViewDelegate ==========
  407. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  408. KBTodayBannerModel *model = self.bannerList[index];
  409. if (model.url.length > 0) {
  410. //活动页
  411. //type为2直接打开淘宝,无需访问中间网页
  412. if ([model.type isEqualToString:@"2"]) {
  413. [self jumpToTaobaoWithUrl:model.url];
  414. }else{
  415. KBWebDetailController *adWeb = [[KBWebDetailController alloc] init];
  416. adWeb.url = model.url;
  417. [self.navigationController pushViewController:adWeb animated:YES];
  418. }
  419. }else {
  420. //列表页
  421. KBGoodListViewController *list = [[KBGoodListViewController alloc] init];
  422. list.cate_id = model.group_id;
  423. list.name = model.note;
  424. [self.navigationController pushViewController:list animated:YES];
  425. }
  426. [MobClick event:home_banner label:model.photo];
  427. }
  428. #pragma mark ------- LDTodayModelCollectionCellDelegate -----
  429. - (void)modelCollectionCellMoreButtonClick:(KBTodayModelCollectionCell *)cell{
  430. KBTodayMudleModel *model = cell.model;
  431. if ([model.type isEqualToString:@"1"]) {
  432. KBBuyLimitMainController *buyLimit = [[KBBuyLimitMainController alloc] init];
  433. [self.navigationController pushViewController:buyLimit animated:YES];
  434. }else if ([model.type isEqualToString:@"2"]){
  435. KBGoodListViewController *rankList = [[KBGoodListViewController alloc] init];
  436. rankList.name = model.name;
  437. rankList.flag = 2;
  438. rankList.cate_id = model.Id;
  439. [self.navigationController pushViewController:rankList animated:YES];
  440. }else {
  441. //列表页
  442. KBGoodListViewController *list = [[KBGoodListViewController alloc] init];
  443. list.cate_id = model.Id;
  444. list.name = model.name;
  445. [self.navigationController pushViewController:list animated:YES];
  446. }
  447. [MobClick event:TodayClickTop label:model.name];
  448. }
  449. #pragma mark ============ UICollectionView Delegate && DataSource ==========
  450. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  451. {
  452. if (section == 0 ) {
  453. return 1;
  454. }else if (section == 1){
  455. return self.morePicArr.count;
  456. }else if (section == 2){
  457. return self.moduleDataArr.count;
  458. }else if(section == 3){
  459. return self.goodsArr.count;
  460. }
  461. return 0;
  462. }
  463. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  464. return 4;
  465. }
  466. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  467. if (indexPath.section == 0) {
  468. if (self.morePicCollectionArr==nil||self.morePicCollectionArr.count==0) {
  469. return CGSizeMake(SCREEN_WIDTH, .1);
  470. }
  471. NSInteger offHeight=0;
  472. if (iPhone5) {
  473. offHeight=10;
  474. }
  475. NSInteger Crow=1;
  476. NSInteger Coff=-1;
  477. NSInteger CrowItemSum=5;
  478. Coff=self.morePicCollectionArr.count%CrowItemSum;
  479. if (Coff!=0) {
  480. CrowItemSum=4;
  481. Coff=self.morePicCollectionArr.count%CrowItemSum;
  482. if (Coff!=0) {
  483. CrowItemSum=3;
  484. Coff=self.morePicCollectionArr.count%CrowItemSum;
  485. if (Coff!=0) {
  486. CrowItemSum=5;
  487. Crow++;
  488. }
  489. }
  490. }
  491. Crow=self.morePicCollectionArr.count/CrowItemSum;
  492. if (Coff!=0) {
  493. Crow++;
  494. }
  495. CGFloat totalHeight = (SCREEN_WIDTH/4+offHeight)*Crow;
  496. return CGSizeMake(SCREEN_WIDTH, totalHeight);
  497. }
  498. if (indexPath.section == 1) {
  499. // if (!self.morePicArr.count||self.morePicArr.count==0) {
  500. // return CGSizeMake(SCREEN_WIDTH, .1);
  501. // }
  502. // CGFloat leftWidth = SCREEN_WIDTH*0.37;
  503. // CGFloat leftHeight = leftWidth*19/14;
  504. // return CGSizeMake(SCREEN_WIDTH, leftHeight);
  505. CGFloat width = (SCREEN_WIDTH-22)/2;
  506. CGSize size = CGSizeMake(width, width*83/170);
  507. return size;
  508. }else if (indexPath.section == 2){
  509. return CGSizeMake(SCREEN_WIDTH-FITSIZE(20), Fitsize(228));
  510. } else if (indexPath.section == 3) {
  511. CGFloat width = (SCREEN_WIDTH)/2;
  512. CGFloat height = width + 102;
  513. return CGSizeMake(width-FITSIZE(12.5f), height);
  514. }
  515. return CGSizeZero;
  516. }
  517. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  518. {
  519. if (section == 0) {
  520. CGFloat height = (bannerHeight/375.f)*SCREEN_WIDTH;
  521. return CGSizeMake(SCREEN_WIDTH, height);
  522. }else if (section == 1){
  523. return CGSizeMake(SCREEN_WIDTH,5);
  524. }else if (section == 2){
  525. CGFloat height = _adDataArr.count>0?((SCREEN_WIDTH-Fitsize(20))*200/750+10):5;
  526. return CGSizeMake(SCREEN_WIDTH,height);
  527. }else {
  528. return CGSizeMake(SCREEN_WIDTH, FITSIZE(40));
  529. }
  530. }
  531. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  532. {
  533. return CGSizeMake(0, 0);
  534. }
  535. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  536. {
  537. if (indexPath.section==0) {
  538. self.morePicCollectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHMorePicCollectionCell forIndexPath:indexPath];
  539. self.morePicCollectionCell.backgroundColor=[UIColor clearColor];
  540. self.morePicCollectionCell.delegate = self;
  541. [self.morePicCollectionCell setModelDatas:self.morePicCollectionArr];
  542. return self.morePicCollectionCell;
  543. }
  544. if (indexPath.section == 1) {
  545. // self.morePicCell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHMorePicCell forIndexPath:indexPath];
  546. // self.morePicCell.delegate = self;
  547. // [self.morePicCell setModelDatas:self.morePicArr];
  548. KBTodayReatCollectionCell *reactCell = [self.collectionView dequeueReusableCellWithReuseIdentifier:KReactCollecionCell forIndexPath:indexPath];
  549. KBMorePicModel *model = self.morePicArr[indexPath.row];
  550. reactCell.model = model;
  551. return reactCell;
  552. }else if (indexPath.section == 2){//限时抢购
  553. KBTodayModelCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KModelCollecionCell forIndexPath:indexPath];
  554. cell.delegate = self;
  555. cell.indexPath = indexPath;
  556. cell.backgroundColor=[UIColor clearColor];
  557. KBTodayMudleModel *model = self.moduleDataArr[indexPath.row];
  558. cell.model = model;
  559. if (indexPath.row == 0) {
  560. KBCountDownView *countdown = [KBCountDownView shareInstace];
  561. countdown.y = Fitsize(15);
  562. countdown.x = Fitsize(132);
  563. countdown.delegate = self;
  564. [cell addSubview:countdown];
  565. cell.desLabel.hidden = YES;
  566. }else {
  567. cell.desLabel.hidden = NO;
  568. }
  569. return cell;
  570. }
  571. else if(indexPath.section == 3){
  572. KBChildGoodModel *model = self.goodsArr[indexPath.item];
  573. KBGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHGoodCollectionCell forIndexPath:indexPath];
  574. cell.model = model;
  575. return cell;
  576. }
  577. return nil;
  578. }
  579. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  580. if (indexPath.section == 0) {
  581. self.sectionOne = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionOne forIndexPath:indexPath];
  582. [self.sectionOne addSubview:self.NewPagedFlowView];
  583. return self.sectionOne;
  584. }
  585. if (indexPath.section == 1) {
  586. UICollectionReusableView *sectionTwo = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionTwo forIndexPath:indexPath];
  587. return sectionTwo;
  588. }
  589. if (indexPath.section == 2) {
  590. UICollectionReusableView *sectionTwo = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionAd forIndexPath:indexPath];
  591. UIView *view=[sectionTwo viewWithTag:2002];
  592. if (view) {
  593. [view removeFromSuperview];
  594. }
  595. [sectionTwo addSubview:_adView];
  596. return sectionTwo;
  597. }
  598. if (indexPath.section == 3) {
  599. self.sectionThree = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionThree forIndexPath:indexPath];
  600. UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, Fitsize(65), Fitsize(40))];
  601. title.font = [UIFont systemFontOfSize:Fitsize(17)];//[UIColor homeRedColor]
  602. title.centerX = SCREEN_WIDTH/2;
  603. title.text = @"精选好物";
  604. [title sizeToFit];
  605. title.textColor =[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0x53F3FD] toColor:[UIColor YHColorWithHex:0x726BFF] withWidth:title.width];
  606. UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(title.left-20, 0, Fitsize(13), Fitsize(15))];
  607. icon.centerY = title.centerY;
  608. icon.image = [UIImage imageNamed:@"hotRecom_left"];
  609. UIImageView *icon2 = [[UIImageView alloc] initWithFrame:CGRectMake(title.right+5, 0, Fitsize(13), Fitsize(15))];
  610. icon2.centerY = title.centerY;
  611. icon2.image = [UIImage imageNamed:@"hotRecom_right"];
  612. [self.sectionThree addSubview:title];
  613. [self.sectionThree addSubview:icon];
  614. [self.sectionThree addSubview:icon2];
  615. // UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, Fitsize(40))];
  616. // title.text = @"精选好物";
  617. // title.textColor = [UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0x47FFDA] toColor:[UIColor YHColorWithHex:0x38D4FB] withWidth:SCREEN_WIDTH];
  618. // title.font = [UIFont systemFontOfSize:Fitsize(19)];
  619. // [title sizeToFit];
  620. // title.centerX = SCREEN_WIDTH/2+Fitsize(10);
  621. // title.centerY = Fitsize(20);
  622. // [self.sectionThree addSubview:title];
  623. //
  624. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(title.x-Fitsize(25), 0, Fitsize(23), FITSIZE(21))];
  625. // imageView.centerY = Fitsize(20);
  626. // imageView.image = [UIImage imageNamed:@"good_gs"];
  627. // [self.sectionThree addSubview:imageView];
  628. return self.sectionThree;
  629. }
  630. return nil;
  631. }
  632. #pragma mark -内边距
  633. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  634. if (section == 1) {
  635. return UIEdgeInsetsMake(0, 10, 0, 10);
  636. }else if(section==3 ){
  637. return UIEdgeInsetsMake(0, 10, 0, 10);
  638. }else {
  639. return UIEdgeInsetsMake(0, 0, 0, 0);
  640. }
  641. }
  642. #pragma mark -行间距
  643. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  644. if (section == 1) {
  645. return 2;
  646. }else {
  647. return 5;
  648. }
  649. }
  650. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  651. if (indexPath.section == 1) {
  652. KBMorePicModel *model = self.morePicArr[indexPath.row];
  653. if (model.url.length > 0) {
  654. //活动页
  655. //type为2直接打开淘宝,无需访问中间网页
  656. if ([model.jump_type isEqualToString:@"2"]) {
  657. [self jumpToTaobaoWithUrl:model.url];
  658. }else{
  659. KBWebDetailController *adWeb = [[KBWebDetailController alloc] init];
  660. adWeb.url = model.url;
  661. [self.navigationController pushViewController:adWeb animated:YES];
  662. }
  663. }else {
  664. //列表页
  665. KBCategoryListViewContoller *list = [[KBCategoryListViewContoller alloc] init];
  666. list.cate_id = model.Id;
  667. list.name = model.name;
  668. list.material_id = model.material_id;
  669. [self.navigationController pushViewController:list animated:YES];
  670. }
  671. [MobClick event:home_recommend label:model.name];
  672. }
  673. if (indexPath.section == 3) {
  674. KBChildGoodModel *model = self.goodsArr[indexPath.row];
  675. KBEventModel *evevtModel = [[KBEventModel alloc] initWithOrigin:model.origin category_id:self.model.Id source:homeAction];
  676. KBGoodDetailViewController *detail = [[KBGoodDetailViewController alloc] init];
  677. detail.eventModel = evevtModel;
  678. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  679. detail.requestModel = requestModel;
  680. [self.navigationController pushViewController:detail animated:YES];
  681. [MobClick event:home_hot];
  682. }
  683. }
  684. #pragma mark ------
  685. #pragma mark - scrollView
  686. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  687. {
  688. //scrollView已经有拖拽手势,直接拿到scrollView的拖拽手势
  689. UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer;
  690. //获取到拖拽的速度 >0 向下拖动 <0 向上拖动
  691. CGFloat velocity = [pan velocityInView:scrollView].y;
  692. if (velocity <- 10) {
  693. //向上拖动,隐藏导航栏
  694. self.collectionView.height = ChildTableViewHeight+NavBarHeight-KStatusBarHeight;
  695. }else if (velocity > 10) {
  696. //向下拖动,显示导航栏
  697. self.collectionView.height = ChildTableViewHeight;
  698. }else if(velocity == 0){
  699. //停止拖拽
  700. }
  701. NSNotification *noti = [[NSNotification alloc] initWithName:ScrollDirectorNoti object:nil userInfo:@{@"director":@(velocity)}];
  702. [[NSNotificationCenter defaultCenter] postNotification:noti];
  703. }
  704. #pragma mark ------
  705. - (void)jumpToTaobaoWithUrl:(NSString *)url {
  706. id<AlibcTradePage> page = [AlibcTradePageFactory page:url];
  707. //淘客信息
  708. AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
  709. taoKeParams.pid= ALTK_PID;
  710. //打开方式
  711. AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  712. showParam.openType = AlibcOpenTypeNative;
  713. [[AlibcTradeSDK sharedInstance].tradeService show:self.parentViewController page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  714. } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  715. }];
  716. }
  717. #pragma mark ===================== layezer ==============
  718. - (NSArray *)goodsArr {
  719. if (!_goodsArr) {
  720. _goodsArr = [NSMutableArray array];
  721. }
  722. return _goodsArr;
  723. }
  724. - (NSMutableArray *)moduleDataArr {
  725. if (!_moduleDataArr) {
  726. _moduleDataArr = [NSMutableArray array];
  727. }
  728. return _moduleDataArr;
  729. }
  730. - (void)didReceiveMemoryWarning {
  731. [super didReceiveMemoryWarning];
  732. // Dispose of any resources that can be recreated.
  733. }
  734. /*
  735. #pragma mark - Navigation
  736. // In a storyboard-based application, you will often want to do a little preparation before navigation
  737. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  738. // Get the new view controller using [segue destinationViewController].
  739. // Pass the selected object to the new view controller.
  740. }
  741. */
  742. @end