猎豆优选

LDTodayViewController.m 48KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  1. //
  2. // LDTodayViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/17.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDTodayViewController.h"
  9. #import "SDCycleScrollView.h"
  10. #import "LDOnePicCell.h"
  11. #import "LDCountHeaderView.h"
  12. #import "LDMorePicCell.h"
  13. #import "LDTodayBannerModel.h"
  14. #import "LDChildGoodModel.h"
  15. #import "LDMorePicModel.h"
  16. #import "LDGoodsInfo.h"
  17. #import "LDAdversementCell.h"
  18. #import "LDAdWebViewController.h"
  19. #import "LDGoodListViewController.h"
  20. #import "FSBaseViewController.h"
  21. #import "LDMorePicCollectionCell.h"
  22. #import "LDMorePicCollectionModel.h"
  23. #import "LDGoodCollectionCell.h"
  24. #import "LDSearchCoupleWebViewController.h"
  25. #import "LDShareGoodsModel.h"
  26. #import "LDShareGoodsViewController.h"
  27. #import "LDPrivilegeReferralViewController.h"
  28. #import "NSNumber+YHExpanded.h"
  29. #import "LDTodayModelCollectionCell.h"
  30. #import "LDRankListViewController.h"
  31. #import "LDTodayMudleModel.h"
  32. #import "FSBaseViewController.h"
  33. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  34. #import <AlibabaAuthSDK/ALBBSession.h>
  35. #import <AlibabaAuthSDK/ALBBSDK.h>
  36. #import "KBTodayReatCollectionCell.h"
  37. #import "LDBuyLimitMainController.h"
  38. #import "NewPagedFlowView.h"
  39. #import "LDSearchCoupleWebViewController.h"
  40. #import "LDLoginViewController.h"
  41. #import "FSBaseViewController.h"
  42. #import "LDTodayAdView.h"
  43. #import "AdJumpManager.h"
  44. #import "LDHomeMainViewController.h"
  45. #import "LDTodayNewsView.h"
  46. #import "LDSuperBrandView.h"
  47. #import "LDTodayHorizontalGoodCell.h"
  48. #import "LDSuperBrandModel.h"
  49. #import "LDTodayGoodModel.h"
  50. #import "LDTodayGroupCell.h"
  51. #import "LDTodayFlowLayout.h"
  52. #import "LDNewsListViewController.h"
  53. #import "LDScrollNewsModel.h"
  54. static NSString *KYHMorePicCollectionCell = @"KYHMorePicCollectionCell";
  55. static NSString *KYHMorePicCell = @"KYHMorePicCell";
  56. static NSString *KYHGoodCollectionCell = @"KYHGoodCollectionCell";
  57. static NSString *KModelCollecionCell = @"modelCollecionCell";
  58. static NSString *KTodayNewsCell = @"KTodayNewsCell";
  59. static NSString *KSuperBrandCell = @"KSuperBrandCell";
  60. static NSString *KTodayGroupCell = @"KTodayGroupCell";
  61. static NSString *KSectionOne = @"KSectionOne";
  62. static NSString *KSectionTwo = @"KSectionTwo";
  63. static NSString *KSectionThree = @"KSectionThree";
  64. static NSString *KReactCollecionCell = @"ReactCollecionCell";
  65. static CGFloat bannerScale = 117.f/355.f;
  66. @interface LDTodayViewController ()
  67. <
  68. UICollectionViewDelegate,
  69. UICollectionViewDataSource,
  70. TodayCollectionViewDelegateFlowLayout,
  71. SDCycleScrollViewDelegate,
  72. YHMorePicCellDelegate,
  73. YHMorePicCollectionCellDelegate,
  74. LDTodayModelCollectionCellDelegate,
  75. YHCountDownViewDelegate,
  76. NewPagedFlowViewDelegate,
  77. NewPagedFlowViewDataSource
  78. >
  79. {
  80. NSInteger _page;
  81. LDTodayAdView *_adView;
  82. NSArray *_adDataArr;
  83. UIButton *redBtn;
  84. NSMutableDictionary *redDic;
  85. }
  86. @property (nonatomic, strong) UICollectionView *collectionView;
  87. @property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
  88. @property (nonatomic, strong) NSArray *bannerList;
  89. @property (nonatomic, strong) NSArray *superBrandList;
  90. @property (nonatomic, strong) NSMutableArray *goodsArr;
  91. @property (nonatomic, strong) LDMorePicCell *morePicCell;
  92. @property (nonatomic, strong) LDMorePicCollectionCell *morePicCollectionCell;
  93. @property (nonatomic, strong) NSArray *morePicArr;
  94. @property (nonatomic, strong) NSArray *morePicCollectionArr;
  95. @property (nonatomic, strong) NSMutableArray *moduleDataArr;
  96. @property (nonatomic, strong) LDGoodsInfo *goodsInfo; //商品信息,包括刷新事件
  97. @property (nonatomic, strong) NewPagedFlowView *NewPagedFlowView;
  98. @property (nonatomic, strong) LDTodayNewsView *scrollNewsView;
  99. @property (nonatomic, strong) LDSuperBrandView *superBrandView;
  100. /**组头*/
  101. @property (nonatomic, strong) UICollectionReusableView *sectionOne;
  102. @property (nonatomic, strong) UICollectionReusableView *sectionThree;
  103. @end
  104. @implementation LDTodayViewController
  105. - (void)viewDidLoad {
  106. [super viewDidLoad];
  107. [self configCollectionView];
  108. [self request];
  109. [self.collectionView reloadData];
  110. }
  111. - (void)request {
  112. [self loadBannerData];
  113. [self loadHotRecomPicCollectionData];
  114. [self loadCategoryGoodsList];
  115. [self loadAdData];
  116. // [self loadSuperBrand];
  117. [self addRedView];
  118. }
  119. -(void)viewWillAppear:(BOOL)animated
  120. {
  121. [super viewWillAppear:animated];
  122. [self isredViewHidden];
  123. }
  124. #pragma mark-添加红包图表
  125. -(void)addRedView
  126. {
  127. redBtn =[[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-94, SCREEN_HEIGHT/4, 81, 59)];
  128. [redBtn setImage:[UIImage imageNamed:@"top_red"] forState:UIControlStateNormal];
  129. [redBtn addTarget:self action:@selector(redBtnclick) forControlEvents:UIControlEventTouchUpInside];
  130. redBtn.hidden=YES;
  131. [self.view addSubview:redBtn];
  132. UILabel *priceLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 25, 81, 24)];
  133. priceLabel.textColor=[UIColor YHColorWithHex:0xFFFFFF];
  134. if (@available(iOS 8.2, *)) {
  135. priceLabel.font=[UIFont systemFontOfSize:17 weight:0.5];
  136. }
  137. priceLabel.textAlignment=NSTextAlignmentCenter;
  138. priceLabel.tag=12342;
  139. [redBtn addSubview:priceLabel];
  140. UILabel *tipelabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 46, 81, 11)];
  141. tipelabel.textColor=[UIColor YHColorWithHex:0xFFFFFF];
  142. tipelabel.font=[UIFont systemFontOfSize:8];
  143. tipelabel.textAlignment=NSTextAlignmentCenter;
  144. tipelabel.text=@"未拆完";
  145. [redBtn addSubview:tipelabel];
  146. }
  147. #pragma mark-红包点击
  148. -(void)redBtnclick
  149. {
  150. LDAdWebViewController *web = [[LDAdWebViewController alloc] init];
  151. web.url = redDic[@"url"];
  152. [self.navigationController pushViewController:web animated:YES];
  153. }
  154. #pragma mark-----是否显示红包
  155. -(void)isredViewHidden
  156. {
  157. [LDHttp post:[NSString stringWithFormat:@"%@/api/v2/redactive/getRedPopo",BaseURL] params:nil success:^(id json) {
  158. redDic=[NSMutableDictionary dictionaryWithDictionary:json[@"data"]];
  159. if ([redDic[@"status"] integerValue] == 1) {
  160. redBtn.hidden=NO;
  161. UILabel *priceL =[redBtn viewWithTag:12342];
  162. NSString *price =[NSString stringWithFormat:@"¥%@元",redDic[@"money"]];
  163. NSMutableAttributedString *attri = [[NSMutableAttributedString alloc]initWithString:price];
  164. [attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12]range:NSMakeRange(0,1)];
  165. [attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17]range:NSMakeRange(1,price.length-1)];
  166. priceL.attributedText=attri;
  167. }else{
  168. redBtn.hidden=YES;
  169. }
  170. } failure:^(NSError *error) {
  171. }];
  172. }
  173. - (void)configCollectionView {
  174. _page = 1;
  175. LDTodayFlowLayout *flowLayout = [[LDTodayFlowLayout alloc]init];
  176. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 5, SCREEN_WIDTH, ChildTableViewHeight+40) collectionViewLayout:flowLayout];
  177. flowLayout.minimumLineSpacing = 0;
  178. flowLayout.minimumInteritemSpacing = 0;
  179. [self.collectionView registerClass:[LDMorePicCollectionCell class] forCellWithReuseIdentifier:KYHMorePicCollectionCell];
  180. [self.collectionView registerClass:[LDMorePicCell class] forCellWithReuseIdentifier:KYHMorePicCell];
  181. [self.collectionView registerClass:[LDTodayHorizontalGoodCell class] forCellWithReuseIdentifier:KYHGoodCollectionCell];
  182. [self.collectionView registerClass:[LDTodayModelCollectionCell class] forCellWithReuseIdentifier:KModelCollecionCell];
  183. [self.collectionView registerClass:[KBTodayReatCollectionCell class] forCellWithReuseIdentifier:KReactCollecionCell];
  184. [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:KTodayNewsCell];
  185. [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:KSuperBrandCell];
  186. [self.collectionView registerClass:[LDTodayGroupCell class] forCellWithReuseIdentifier:KTodayGroupCell];
  187. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionOne];
  188. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionTwo];
  189. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionThree];
  190. self.collectionView.backgroundColor = [UIColor clearColor];
  191. self.collectionView.showsVerticalScrollIndicator = NO;
  192. self.collectionView.delegate = self;
  193. self.collectionView.dataSource = self;
  194. MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
  195. [self refreshData];
  196. }];
  197. header.lastUpdatedTimeLabel.hidden = YES;
  198. header.stateLabel.hidden = YES;
  199. //正在刷新的图片
  200. NSArray *imgArr = @[[UIImage imageNamed:@"ant1"],[UIImage imageNamed:@"ant2"]];
  201. [header setImages:imgArr duration:0.3 forState:MJRefreshStateRefreshing];
  202. [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStateWillRefresh];
  203. [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStatePulling];
  204. self.collectionView.mj_header = header;
  205. self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  206. [self loadMoreData];
  207. }];
  208. [self.collectionView.mj_footer beginRefreshing];
  209. if (@available(iOS 11.0, *)) {
  210. self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用
  211. }else {
  212. self.automaticallyAdjustsScrollViewInsets = NO;
  213. }
  214. [self.view addSubview:self.collectionView];
  215. // CGFloat height = (bannerHeight/375.f)*SCREEN_WIDTH;
  216. // CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, height);
  217. //
  218. // self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:rect delegate:self placeholderImage:nil];
  219. // self.cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"page_sel"];
  220. // self.cycleScrollView.pageDotImage = [UIImage imageNamed:@"page_nor"];
  221. // self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleToFill;
  222. self.NewPagedFlowView = [[NewPagedFlowView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH * bannerScale)];
  223. self.NewPagedFlowView.backgroundColor = [UIColor clearColor];
  224. self.NewPagedFlowView.delegate = self;
  225. self.NewPagedFlowView.dataSource = self;
  226. self.NewPagedFlowView.minimumPageAlpha = 0.1;
  227. self.NewPagedFlowView.isCarousel = YES;
  228. self.NewPagedFlowView.orientation = NewPagedFlowViewOrientationHorizontal;
  229. self.NewPagedFlowView.isOpenAutoScroll = YES;
  230. // self.NewPagedFlowView.layer.shadowOffset = CGSizeMake(2, 5);
  231. // self.NewPagedFlowView.layer.shadowOpacity = 0.3;
  232. // self.NewPagedFlowView.layer.shadowColor = [UIColor blackColor].CGColor;
  233. // [self.loginBackView mas_makeConstraints:^(MASConstraintMaker *make) {
  234. // make.width.mas_equalTo(SCREEN_WIDTH);
  235. // make.height.mas_equalTo(FITSIZE(45));
  236. // make.bottom.mas_equalTo(200);
  237. // }];
  238. }
  239. - (void)loadAdData {
  240. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adv/advByType",BaseURL];
  241. NSDictionary *para = @{@"adv_type":@"1"};
  242. [LDHttp get:url params:para success:^(id json) {
  243. _adDataArr = [NSArray yy_modelArrayWithClass:[AdPopModel class] json:json[@"data"]];
  244. if (_adDataArr.count > 0) {
  245. [self creatAdView:_adDataArr];
  246. }
  247. [self.collectionView reloadData];
  248. } failure:^(NSError *error) {
  249. }];
  250. }
  251. - (void)creatAdView:(NSArray *)list {
  252. // LDTodayAdView *adView = [[LDTodayAdView alloc] initWithFrame:CGRectMake(Fitsize(10), Fitsize(3), SCREEN_WIDTH-Fitsize(20), (SCREEN_WIDTH-Fitsize(20))*200/750)];
  253. LDTodayAdView *adView = [[LDTodayAdView alloc] initWithFrame:CGRectMake(5, 5, SCREEN_WIDTH-10, (SCREEN_WIDTH-10)*200/750)];
  254. _adView.tag=2002;
  255. _adView = adView;
  256. _adView.model = list.firstObject;
  257. adView.tapAdBlock = ^{
  258. [MobClick event:AdvClick label:@"1"];
  259. [AdJumpManager jumpToPageWithModel:list.firstObject ParentViewControll:self];
  260. };
  261. }
  262. - (void)loadBannerData {
  263. [LDCacheHttp get:Banner_list params:nil success:^(id json, BOOL isCache) {
  264. self.bannerList = [NSArray yy_modelArrayWithClass:[LDTodayBannerModel class] json:json[@"data"]];
  265. NSLog(@"%@",json[@"data"]);
  266. [self creatCycleScrollView];
  267. } failure:^(NSError *error) {
  268. }];
  269. }
  270. /**
  271. 加载超级大牌
  272. */
  273. - (void)loadSuperBrand {
  274. NSString *url = [NSString stringWithFormat:@"%@/api/v2/channel/SuperBrand",BaseURL];
  275. NSDictionary *para = @{@"position":@"1",
  276. @"category_id":self.model.Id
  277. };
  278. [LDCacheHttp post:url params:para success:^(id json, BOOL isCache) {
  279. self.superBrandList = [NSArray yy_modelArrayWithClass:[LDSuperBrandModel class] json:json[@"data"]];
  280. [self.superBrandView setSuperBrandData:self.superBrandList];
  281. [self.collectionView reloadData];
  282. } failure:^(NSError *error) {
  283. }];
  284. }
  285. - (void)creatCycleScrollView {
  286. NSMutableArray *imgArr = [NSMutableArray array];
  287. for (LDTodayBannerModel *model in self.bannerList) {
  288. [imgArr addObject:model.photo];
  289. }
  290. // self.cycleScrollView.imageURLStringsGroup = imgArr;
  291. [self.NewPagedFlowView reloadData];
  292. }
  293. /**
  294. 加载下部商品列表
  295. */
  296. - (void)loadCategoryGoodsList {
  297. NSDictionary *para = @{@"sort":@"1",
  298. @"page":@(_page),
  299. @"category_id":self.model.Id,
  300. @"stype":@"0"};
  301. NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/goodsAndStockList",BaseURL];
  302. [LDCacheHttp post:url params:para success:^(id json, BOOL isCache) {
  303. if ([self.collectionView.mj_header isRefreshing]) [self.goodsArr removeAllObjects];
  304. //清空缓存数据,展示真正的数据(如果page是1,且不是缓存数据,说明是真正的数据)
  305. if (_page == 1 && !isCache) [self.goodsArr removeAllObjects];
  306. NSArray *list = [NSArray yy_modelArrayWithClass:[LDTodayGoodModel class] json:json];
  307. [self noMoreDataWithArray:list];
  308. [self.goodsArr addObjectsFromArray:list];
  309. [self.collectionView reloadData];
  310. [self.collectionView.mj_header endRefreshing];
  311. } failure:^(NSError *error) {
  312. [self endRefreshing];
  313. [self.collectionView.mj_footer endRefreshing];
  314. }];
  315. }
  316. - (void)noMoreDataWithArray:(NSArray *)array {
  317. if (array.count <= 0) {
  318. [self.collectionView.mj_footer endRefreshingWithNoMoreData];
  319. }else {
  320. [self.collectionView.mj_footer endRefreshing];
  321. }
  322. }
  323. - (void)endRefreshing {
  324. [self.collectionView.mj_header endRefreshing];
  325. }
  326. - (void)refreshData {
  327. _page = 1;
  328. [self loadBannerData];
  329. // [self loadModelCellData];
  330. // [self loadHotRecomPicData];
  331. [self loadAdData];
  332. [self loadHotRecomPicCollectionData];
  333. [self loadCategoryGoodsList];
  334. // [self loadSuperBrand];//超级大牌数据
  335. // [self loadTodayScollNews];
  336. }
  337. /**
  338. 上拉加载
  339. */
  340. - (void)loadMoreData {
  341. _page++;
  342. [self loadCategoryGoodsList];
  343. }
  344. /**
  345. 多图推荐
  346. */
  347. - (void)loadHotRecomPicData {
  348. [LDCacheHttp get:Goldgroups params:nil success:^(id json, BOOL isCache) {
  349. self.morePicArr = [NSArray yy_modelArrayWithClass:[LDMorePicModel class] json:json[@"data"]];
  350. if (self.morePicArr.count==0) {
  351. [self.collectionView reloadData];
  352. }
  353. [self.morePicCell setModelDatas:self.morePicArr];
  354. [self.collectionView reloadData];
  355. } failure:^(NSError *error) {
  356. }];
  357. }
  358. /**
  359. 加载菜单栏目
  360. */
  361. - (void)loadHotRecomPicCollectionData {
  362. [LDCacheHttp post:GoldCollectiongroups params:nil success:^(id json, BOOL isCache) {
  363. self.morePicCollectionArr = [NSArray yy_modelArrayWithClass:[LDMorePicCollectionModel class] json:json[@"data"]];
  364. [self.morePicCollectionCell setModelDatas:self.morePicCollectionArr];
  365. [self.collectionView reloadData];
  366. } failure:^(NSError *error) {
  367. }];
  368. }
  369. /**
  370. 加载滚动头条
  371. */
  372. - (void)loadTodayScollNews {
  373. NSString *url = [NSString stringWithFormat:@"%@/api/v2/message_push/LieDouHeadlines",BaseURL];
  374. [LDHttp post:url params:nil success:^(id json) {
  375. NSArray *list = [NSArray yy_modelArrayWithClass:[LDScrollNewsModel class] json:json[@"data"]];
  376. [self.scrollNewsView setDataList:list];
  377. } failure:^(NSError *error) {
  378. }];
  379. }
  380. /**
  381. 加载分类模块数据
  382. */
  383. - (void)loadModelCellData {
  384. NSString *url = [NSString stringWithFormat:@"%@/api/v2/channel/advFourList",BaseURL];
  385. [LDCacheHttp post:url params:@{@"platform":@"2"} success:^(id json, BOOL isCache) {
  386. NSArray *list = [NSArray yy_modelArrayWithClass:[LDTodayMudleModel class] json:json[@"list"]];
  387. if (list.count > 0) {
  388. [self countDownViewSetCount:list.firstObject];
  389. }
  390. [self.moduleDataArr removeAllObjects];
  391. [self.moduleDataArr addObjectsFromArray:list];
  392. [self.collectionView reloadData];
  393. [self endRefreshing];
  394. } failure:^(NSError *error) {
  395. [self endRefreshing];
  396. }];
  397. }
  398. - (void)countDownViewSetCount:(LDTodayMudleModel *)model {
  399. NSString *endTime = [NSString stringWithFormat:@"%@000",model.remainTime];
  400. [[LDCountDownView shareInstace] setEndTimer:endTime];
  401. }
  402. #pragma mark ------ YHCountDownViewDelegate -------
  403. - (void)countViewTimeOutAction {
  404. [self.collectionView.mj_header beginRefreshing];
  405. }
  406. #pragma mark NewPagedFlowView Datasource
  407. - (NSInteger)numberOfPagesInFlowView:(NewPagedFlowView *)flowView {
  408. return self.bannerList.count;
  409. }
  410. - (PGIndexBannerSubiew *)flowView:(NewPagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{
  411. PGIndexBannerSubiew *bannerView = [flowView dequeueReusableCell];
  412. if (!bannerView) {
  413. bannerView = [[PGIndexBannerSubiew alloc] init];
  414. bannerView.tag = index;
  415. bannerView.layer.cornerRadius = 4;
  416. bannerView.layer.masksToBounds = YES;
  417. }
  418. if (self.bannerList.count > 0 && self.bannerList.count>index) {
  419. LDTodayBannerModel *model = self.bannerList[index];
  420. //在这里下载网络图片
  421. [bannerView.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.photo] placeholderImage:[UIImage imageNamed:@""]];
  422. }
  423. return bannerView;
  424. }
  425. - (CGSize)sizeForPageInFlowView:(NewPagedFlowView *)flowView {
  426. return CGSizeMake(SCREEN_WIDTH - 20, (SCREEN_WIDTH - 20) * bannerScale);
  427. }
  428. - (void)didSelectCell:(UIView *)subView withSubViewIndex:(NSInteger)subIndex {
  429. LDTodayBannerModel *model = self.bannerList[subIndex];
  430. switch (model.click_type.integerValue) {
  431. case 1:
  432. {//h5跳转
  433. LDAdWebViewController *adWeb = [[LDAdWebViewController alloc] init];
  434. adWeb.url =model.click_param;
  435. [self.navigationController pushViewController:adWeb animated:YES];
  436. }
  437. break;
  438. case 2://商品详情
  439. {
  440. LDGoodDetailViewController *detailVC = [[LDGoodDetailViewController alloc] init];
  441. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithDTodayBannerModels:model];
  442. detailVC.requestModel = requestModel;
  443. detailVC.requestModel.goods_id = model.click_param;
  444. [self.navigationController pushViewController:detailVC animated:YES];
  445. }
  446. break;
  447. case 3://专题列表
  448. //列表页
  449. {
  450. LDGoodListViewController *list = [[LDGoodListViewController alloc] init];
  451. list.cate_id = model.click_param;
  452. list.name = model.groupTitle;
  453. list.topRequest = 2;
  454. [self.navigationController pushViewController:list animated:YES];
  455. }
  456. break;
  457. case 4://淘宝链接
  458. {
  459. [self jumpToTaobaoWithUrl:model.click_param];
  460. }
  461. break;
  462. case 5://天猫超市\国际\聚划算\天猫大牌
  463. {
  464. LDSearchCoupleWebViewController *searchCoupleWeb = [[LDSearchCoupleWebViewController alloc] init];
  465. searchCoupleWeb.url = model.click_param;
  466. searchCoupleWeb.jsString = model.ios_js_string;
  467. searchCoupleWeb.name = model.note;
  468. if ([[ALBBSession sharedInstance] isLogin] && [AccountTool isLogin]) {
  469. //进入
  470. [self.navigationController pushViewController:searchCoupleWeb animated:YES];
  471. }else if (![AccountTool isLogin]) {
  472. //未登录
  473. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  474. login.modalPresentationStyle = UIModalPresentationFullScreen;
  475. [self presentViewController:login animated:YES completion:nil];
  476. }else if (![[ALBBSession sharedInstance] isLogin]) {
  477. //淘宝未授权
  478. ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
  479. [albbSDK setAppkey:ALBC_APP_KEY];
  480. [albbSDK setAuthOption:NormalAuth];
  481. [albbSDK auth:self successCallback:^(ALBBSession *session){
  482. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeTaoBaoAuthor object:nil];
  483. [self.navigationController pushViewController:searchCoupleWeb animated:YES];
  484. } failureCallback:^(ALBBSession *session,NSError *error){
  485. NSLog(@"session == %@,error == %@",session,error);
  486. }];
  487. }
  488. }
  489. break;
  490. default:
  491. break;
  492. }
  493. [MobClick event:home_banner label:model.photo];
  494. }
  495. - (void)didScrollToPage:(NSInteger)pageNumber inFlowView:(NewPagedFlowView *)flowView {
  496. if (flowView == self.NewPagedFlowView) {
  497. LDHomeMainViewController *superVc = (LDHomeMainViewController *)self.parentViewController;
  498. //仅在今日精选时改变
  499. if (superVc.showIndex == 0) {
  500. UIImageView *bgImgView = superVc.bgImageView;
  501. LDTodayBannerModel *model = self.bannerList[pageNumber];
  502. [bgImgView sd_setImageWithURL:[NSURL URLWithString:model.photo_bg]];
  503. }
  504. }
  505. }
  506. #pragma mark ====================== YHMorePicCellDelegate==========
  507. /**
  508. 点击推荐位多图
  509. */
  510. - (void)YHMorePicCellDidSelectedItem:(NSInteger)index {
  511. LDMorePicModel *model = self.morePicArr[index];
  512. if (model.url.length > 0) {
  513. //活动页
  514. //type为2直接打开淘宝,无需访问中间网页
  515. if ([model.jump_type isEqualToString:@"2"]) {
  516. [self jumpToTaobaoWithUrl:model.url];
  517. }else{
  518. LDAdWebViewController *adWeb = [[LDAdWebViewController alloc] init];
  519. adWeb.url = model.url;
  520. [self.navigationController pushViewController:adWeb animated:YES];
  521. }
  522. }else {
  523. //列表页
  524. LDGoodListViewController *list = [[LDGoodListViewController alloc] init];
  525. list.cate_id = model.Id;
  526. list.name = model.name;
  527. list.topRequest = 2;
  528. [self.navigationController pushViewController:list animated:YES];
  529. }
  530. [MobClick event:home_recommend label:model.name];
  531. }
  532. #pragma mark ====================== YHMorePicCollectionCellDelegate==========
  533. - (void)YHMorePicCollectionCellDidSelectedItem:(NSInteger)index{
  534. LDMorePicCollectionModel *model = self.morePicCollectionArr[index];
  535. switch ([model.show_type integerValue]) {
  536. case 1:
  537. {
  538. LDAdWebViewController *adWeb = [[LDAdWebViewController alloc] init];
  539. adWeb.url = model.url;
  540. [self.navigationController pushViewController:adWeb animated:YES];
  541. }
  542. break;
  543. case 2:
  544. {
  545. LDGoodListViewController *list = [[LDGoodListViewController alloc] init];
  546. list.cate_id = model.Id;
  547. list.name = model.name;
  548. list.topRequest = 2;
  549. [self.navigationController pushViewController:list animated:YES];
  550. }
  551. break;
  552. case 3:
  553. {
  554. [self jumpToTaobaoWithUrl:model.url];
  555. }
  556. break;
  557. case 4:
  558. {
  559. LDSearchCoupleWebViewController *searchCoupleWeb = [[LDSearchCoupleWebViewController alloc] init];
  560. searchCoupleWeb.url = model.url;
  561. searchCoupleWeb.jsString = model.ios_js_string;
  562. searchCoupleWeb.name = model.name;
  563. if ([[ALBBSession sharedInstance] isLogin] && [AccountTool isLogin]) {
  564. //进入
  565. [self.navigationController pushViewController:searchCoupleWeb animated:YES];
  566. }else if (![AccountTool isLogin]) {
  567. //未登录
  568. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  569. login.modalPresentationStyle = UIModalPresentationFullScreen;
  570. [self presentViewController:login animated:YES completion:nil];
  571. }else if (![[ALBBSession sharedInstance] isLogin]) {
  572. //淘宝未授权
  573. ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
  574. [albbSDK setAppkey:ALBC_APP_KEY];
  575. [albbSDK setAuthOption:NormalAuth];
  576. [albbSDK auth:self successCallback:^(ALBBSession *session){
  577. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeTaoBaoAuthor object:nil];
  578. [self.navigationController pushViewController:searchCoupleWeb animated:YES];
  579. } failureCallback:^(ALBBSession *session,NSError *error){
  580. NSLog(@"session == %@,error == %@",session,error);
  581. }];
  582. }
  583. }
  584. break;
  585. case 5:
  586. {
  587. LDGoodDetailViewController *detailVC = [[LDGoodDetailViewController alloc] init];
  588. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithLDMorePicCollectionModels:model];
  589. detailVC.requestModel = requestModel;
  590. [self.navigationController pushViewController:detailVC animated:YES];
  591. }
  592. break;
  593. default:
  594. break;
  595. }
  596. [MobClick event:Home_Items label:model.name];
  597. }
  598. #pragma mark ============ SDCycleScrollViewDelegate ==========
  599. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  600. LDTodayBannerModel *model = self.bannerList[index];
  601. if (model.url.length > 0) {
  602. //活动页
  603. //type为2直接打开淘宝,无需访问中间网页
  604. if ([model.type isEqualToString:@"2"]) {
  605. [self jumpToTaobaoWithUrl:model.url];
  606. }else{
  607. LDAdWebViewController *adWeb = [[LDAdWebViewController alloc] init];
  608. adWeb.url = model.url;
  609. [self.navigationController pushViewController:adWeb animated:YES];
  610. }
  611. }else {
  612. //列表页
  613. LDGoodListViewController *list = [[LDGoodListViewController alloc] init];
  614. list.cate_id = model.group_id;
  615. list.name = model.note;
  616. list.topRequest = 2;
  617. [self.navigationController pushViewController:list animated:YES];
  618. }
  619. [MobClick event:home_banner label:model.photo];
  620. }
  621. #pragma mark ------- LDTodayModelCollectionCellDelegate -----
  622. - (void)modelCollectionCellMoreButtonClick:(LDTodayModelCollectionCell *)cell{
  623. LDTodayMudleModel *model = cell.model;
  624. NSInteger type = model.type.integerValue;
  625. switch (type) {
  626. case 1:
  627. {
  628. LDBuyLimitMainController *buyLimit = [[LDBuyLimitMainController alloc] init];
  629. [self.navigationController pushViewController:buyLimit animated:YES];
  630. }
  631. break;
  632. case 2:
  633. {
  634. LDRankListViewController *rankList = [[LDRankListViewController alloc] init];
  635. rankList.name = model.name;
  636. [self.navigationController pushViewController:rankList animated:YES];
  637. }
  638. break;
  639. case 3:
  640. {
  641. //列表页
  642. LDGoodListViewController *list = [[LDGoodListViewController alloc] init];
  643. list.cate_id = model.Id;
  644. list.name = model.name;
  645. list.topRequest = 2; //2为通用列表,1为大额券
  646. [self.navigationController pushViewController:list animated:YES];
  647. }
  648. break;
  649. case 4:
  650. {
  651. //列表页
  652. LDGoodListViewController *list = [[LDGoodListViewController alloc] init];
  653. list.cate_id = model.Id;
  654. list.name = model.name;
  655. list.topRequest = 1;
  656. [self.navigationController pushViewController:list animated:YES];
  657. }
  658. break;
  659. default:
  660. break;
  661. }
  662. [MobClick event:TodayClickTop label:model.name];
  663. }
  664. #pragma mark ============ UICollectionView Delegate && DataSource ==========
  665. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  666. {
  667. if (section == 0 ) {
  668. return 2;
  669. }else if (section == 1){
  670. return self.morePicArr.count;
  671. }else if (section == 2){
  672. return self.moduleDataArr.count;
  673. }else if(section == 3){
  674. return self.goodsArr.count;
  675. }
  676. return 0;
  677. }
  678. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  679. return 4;
  680. }
  681. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  682. if (indexPath.section == 0) {
  683. //圆形菜单高度
  684. if (indexPath.row == 0) {
  685. if (self.morePicCollectionArr==nil||self.morePicCollectionArr.count==0) {
  686. return CGSizeMake(SCREEN_WIDTH, .1);
  687. }
  688. NSInteger offHeight=0;
  689. if (iPhone5) {
  690. offHeight=10;
  691. }
  692. NSInteger Crow=1;
  693. NSInteger Coff=-1;
  694. NSInteger CrowItemSum=5;
  695. Coff=self.morePicCollectionArr.count%CrowItemSum;
  696. if (Coff!=0) {
  697. CrowItemSum=4;
  698. Coff=self.morePicCollectionArr.count%CrowItemSum;
  699. if (Coff!=0) {
  700. CrowItemSum=3;
  701. Coff=self.morePicCollectionArr.count%CrowItemSum;
  702. if (Coff!=0) {
  703. CrowItemSum=5;
  704. Crow++;
  705. }
  706. }
  707. }
  708. Crow=self.morePicCollectionArr.count/CrowItemSum;
  709. if (Coff!=0) {
  710. Crow++;
  711. }
  712. NSInteger totalHeight = (SCREEN_WIDTH/4+offHeight)*Crow;
  713. return CGSizeMake(SCREEN_WIDTH, totalHeight);
  714. }
  715. if (indexPath.row == 1) {
  716. //猎豆头条高度
  717. return CGSizeMake(SCREEN_WIDTH, 0);
  718. }
  719. if (indexPath.row == 2) {
  720. //超级大牌高度
  721. CGFloat height = 100+(SCREEN_WIDTH-10)*36/365;
  722. return CGSizeMake(SCREEN_WIDTH, height);
  723. }
  724. }
  725. if (indexPath.section == 1) {
  726. // if (!self.morePicArr.count||self.morePicArr.count==0) {
  727. // return CGSizeMake(SCREEN_WIDTH, .1);
  728. // }
  729. // CGFloat leftWidth = SCREEN_WIDTH*0.37;
  730. // CGFloat leftHeight = leftWidth*19/14;
  731. // return CGSizeMake(SCREEN_WIDTH, leftHeight);
  732. CGFloat width = (SCREEN_WIDTH-13)/2;
  733. CGSize size = CGSizeMake(width, width*83/170);
  734. return size;
  735. }else if (indexPath.section == 2){
  736. return CGSizeMake(SCREEN_WIDTH, Fitsize(218));
  737. } else if (indexPath.section == 3) {
  738. LDTodayGoodModel *model = self.goodsArr[indexPath.row];
  739. if ([model.type integerValue] == 1) {
  740. CGFloat width = SCREEN_WIDTH;
  741. CGFloat height = 147;
  742. return CGSizeMake(width, height);
  743. }
  744. if ([model.type integerValue] == 2) {
  745. return CGSizeMake(SCREEN_WIDTH, Fitsize(215));
  746. }
  747. }
  748. return CGSizeZero;
  749. }
  750. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  751. {
  752. if (section == 0) {
  753. // CGFloat height = (bannerHeight/375.f)*SCREEN_WIDTH;
  754. // return CGSizeMake(SCREEN_WIDTH, height);
  755. return CGSizeMake(SCREEN_WIDTH, SCREEN_WIDTH * bannerScale);
  756. }else if (section == 1){
  757. if (_adDataArr.count > 0) {
  758. return CGSizeMake(SCREEN_WIDTH, ((SCREEN_WIDTH-10)*200/750)+10);
  759. }
  760. return CGSizeMake(SCREEN_WIDTH, 0);
  761. }else if (section == 2){
  762. return CGSizeMake(SCREEN_WIDTH, 0);
  763. }
  764. else {
  765. return CGSizeMake(SCREEN_WIDTH, FITSIZE(40));
  766. }
  767. }
  768. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  769. {
  770. return CGSizeMake(0, 0);
  771. }
  772. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  773. if (section == 1) {
  774. return UIEdgeInsetsMake(0, 5, 0, 5);
  775. }else {
  776. return UIEdgeInsetsMake(0, 0, 0, 0);
  777. }
  778. }
  779. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  780. {
  781. if (indexPath.section==0) {
  782. if (indexPath.row == 0) {
  783. //圆形菜单
  784. self.morePicCollectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHMorePicCollectionCell forIndexPath:indexPath];
  785. self.morePicCollectionCell.backgroundColor = [UIColor greenColor];
  786. self.morePicCollectionCell.delegate = self;
  787. [self.morePicCollectionCell setModelDatas:self.morePicCollectionArr];
  788. return self.morePicCollectionCell;
  789. }
  790. if (indexPath.row == 1) {
  791. //滚动新闻
  792. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KTodayNewsCell forIndexPath:indexPath];
  793. // [cell addSubview:self.scrollNewsView];
  794. cell.backgroundColor = [UIColor whiteColor];
  795. return cell;
  796. }
  797. if (indexPath.row == 2) {
  798. //超级大牌
  799. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KSuperBrandCell forIndexPath:indexPath];
  800. [cell addSubview:self.superBrandView];
  801. cell.backgroundColor = [UIColor whiteColor];
  802. return cell;
  803. }
  804. }
  805. if (indexPath.section == 1) {
  806. // self.morePicCell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHMorePicCell forIndexPath:indexPath];
  807. // self.morePicCell.delegate = self;
  808. // [self.morePicCell setModelDatas:self.morePicArr];
  809. // return self.morePicCell;
  810. KBTodayReatCollectionCell *reactCell = [self.collectionView dequeueReusableCellWithReuseIdentifier:KReactCollecionCell forIndexPath:indexPath];
  811. LDMorePicModel *model = self.morePicArr[indexPath.row];
  812. reactCell.model = model;
  813. return reactCell;
  814. }else if (indexPath.section == 2){
  815. LDTodayModelCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KModelCollecionCell forIndexPath:indexPath];
  816. cell.delegate = self;
  817. cell.indexPath = indexPath;
  818. LDTodayMudleModel *model = self.moduleDataArr[indexPath.row];
  819. cell.model = model;
  820. if (indexPath.row == 0) {
  821. LDCountDownView *countdown = [LDCountDownView shareInstace];
  822. countdown.y = Fitsize(15);
  823. countdown.x = Fitsize(132);
  824. countdown.delegate = self;
  825. [cell addSubview:countdown];
  826. cell.desLabel.hidden = YES;
  827. }else {
  828. cell.desLabel.hidden = NO;
  829. }
  830. return cell;
  831. }
  832. else if(indexPath.section == 3){
  833. LDTodayGoodModel *model = self.goodsArr[indexPath.item];
  834. if ([model.type integerValue] == 1) {
  835. LDTodayHorizontalGoodCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHGoodCollectionCell forIndexPath:indexPath];
  836. cell.model = model.goods;
  837. return cell;
  838. }
  839. if ([model.type integerValue] == 2) {
  840. LDTodayGroupCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KTodayGroupCell forIndexPath:indexPath];
  841. cell.moreClick = ^{
  842. //列表页
  843. LDGoodListViewController *list = [[LDGoodListViewController alloc] init];
  844. list.cate_id = model.Id;
  845. list.name = model.name;
  846. list.topRequest = 2;
  847. [self.navigationController pushViewController:list animated:YES];
  848. };
  849. [cell setGoodData:model.goodsList];
  850. [cell.bgImgView sd_setFadeImageWithURL:[NSURL URLWithString:model.adv_background_img] placeholderImage:nil options:0 progress:nil completed:nil];
  851. return cell;
  852. }
  853. }
  854. return nil;
  855. }
  856. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  857. if (indexPath.section == 0) {
  858. self.sectionOne = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionOne forIndexPath:indexPath];
  859. self.sectionOne.backgroundColor = [UIColor clearColor];
  860. [self.sectionOne addSubview:self.NewPagedFlowView];
  861. return self.sectionOne;
  862. }
  863. if (indexPath.section == 1) {
  864. UICollectionReusableView *sectionTwo = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionTwo forIndexPath:indexPath];
  865. [sectionTwo addSubview:_adView];
  866. return sectionTwo;
  867. }
  868. if (indexPath.section == 2) {
  869. UICollectionReusableView *sectionTwo = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionTwo forIndexPath:indexPath];
  870. return sectionTwo;
  871. }
  872. if (indexPath.section == 3) {
  873. self.sectionThree = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionThree forIndexPath:indexPath];
  874. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, FITSIZE(40))];
  875. imageView.image = [UIImage imageNamed:@"section_img"];
  876. [self.sectionThree addSubview:imageView];
  877. return self.sectionThree;
  878. }
  879. return nil;
  880. }
  881. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  882. if (section == 0) {
  883. return 0;
  884. }
  885. if (section == 1 || section == 2) {
  886. return 5;
  887. }
  888. if (section == 3) {
  889. return 10;
  890. }
  891. return 0;
  892. }
  893. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  894. if (indexPath.section == 1) {
  895. LDMorePicModel *model = self.morePicArr[indexPath.row];
  896. if (model.url.length > 0) {
  897. //活动页
  898. //type为2直接打开淘宝,无需访问中间网页
  899. if ([model.jump_type isEqualToString:@"2"]) {
  900. [self jumpToTaobaoWithUrl:model.url];
  901. }else{
  902. LDAdWebViewController *adWeb = [[LDAdWebViewController alloc] init];
  903. adWeb.url = model.url;
  904. [self.navigationController pushViewController:adWeb animated:YES];
  905. }
  906. }else {
  907. //列表页
  908. LDGoodListViewController *list = [[LDGoodListViewController alloc] init];
  909. list.cate_id = model.Id;
  910. list.name = model.name;
  911. list.topRequest = 2;
  912. [self.navigationController pushViewController:list animated:YES];
  913. }
  914. [MobClick event:home_recommend label:model.name];
  915. }
  916. if (indexPath.section == 0) {
  917. if (indexPath.row == 2) {
  918. FSBaseViewController *faVC= [[FSBaseViewController alloc]init];
  919. faVC.model = self.model;
  920. [self.navigationController pushViewController:faVC animated:YES];
  921. }
  922. }
  923. if (indexPath.section == 3) {
  924. LDTodayGoodModel *todayModel = self.goodsArr[indexPath.row];
  925. if ([todayModel.type integerValue] == 1) {
  926. LDChildGoodModel *model = todayModel.goods;
  927. LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:self.model.Id source:homeAction];
  928. LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
  929. detail.eventModel = evevtModel;
  930. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  931. detail.requestModel = requestModel;
  932. [self.navigationController pushViewController:detail animated:YES];
  933. [MobClick event:home_hot];
  934. }
  935. if ([todayModel.type integerValue] == 2) {
  936. //列表页
  937. LDGoodListViewController *list = [[LDGoodListViewController alloc] init];
  938. list.cate_id = todayModel.Id;
  939. list.name = todayModel.name;
  940. list.topRequest = 2;
  941. [self.navigationController pushViewController:list animated:YES];
  942. }
  943. }
  944. }
  945. - (UIColor *)todayCollectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout backgroundColorForSection:(NSInteger)section {
  946. if (section == 0) {
  947. return [UIColor clearColor];
  948. }else {
  949. return [UIColor yhGrayColor];
  950. }
  951. }
  952. #pragma mark ------
  953. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  954. {
  955. [UIView animateWithDuration:1 animations:^{
  956. redBtn.frame=CGRectMake(SCREEN_WIDTH-25, SCREEN_HEIGHT/4, 81, 59);
  957. }];
  958. }
  959. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  960. BOOL scrollToScrollStop = !scrollView.tracking && !scrollView.dragging && !scrollView.decelerating;
  961. if (scrollToScrollStop) {
  962. if ([redDic.allKeys containsObject:@"status"]&& [redDic[@"status"] integerValue]==1) {
  963. // 停止后要执行的代码
  964. [UIView animateWithDuration:1 animations:^{
  965. redBtn.frame=CGRectMake(SCREEN_WIDTH-94, SCREEN_HEIGHT/4, 81, 59);
  966. }];
  967. }
  968. }
  969. }
  970. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
  971. if (!decelerate) {
  972. BOOL dragToDragStop = scrollView.tracking && !scrollView.dragging && !scrollView.decelerating;
  973. if (dragToDragStop) {
  974. if ([redDic.allKeys containsObject:@"status"]&& [redDic[@"status"] integerValue]==1) {
  975. [UIView animateWithDuration:1 animations:^{
  976. redBtn.frame=CGRectMake(SCREEN_WIDTH-94, SCREEN_HEIGHT/4, 81, 59);
  977. }];
  978. }
  979. }
  980. }
  981. }
  982. #pragma mark - scrollView
  983. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  984. {
  985. //scrollView已经有拖拽手势,直接拿到scrollView的拖拽手势
  986. UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer;
  987. //获取到拖拽的速度 >0 向下拖动 <0 向上拖动
  988. CGFloat velocity = [pan velocityInView:scrollView].y;
  989. if (velocity <- 10) {
  990. //向上拖动,隐藏导航栏
  991. self.collectionView.height = ChildTableViewHeight+NavBarHeight-KStatusBarHeight;
  992. }else if (velocity > 10) {
  993. //向下拖动,显示导航栏
  994. self.collectionView.height = ChildTableViewHeight;
  995. }else if(velocity == 0){
  996. //停止拖拽
  997. }
  998. NSNotification *noti = [[NSNotification alloc] initWithName:ScrollDirectorNoti object:nil userInfo:@{@"director":@(velocity)}];
  999. [[NSNotificationCenter defaultCenter] postNotification:noti];
  1000. }
  1001. #pragma mark ------
  1002. - (void)jumpToTaobaoWithUrl:(NSString *)url {
  1003. id<AlibcTradePage> page = [AlibcTradePageFactory page:url];
  1004. //淘客信息
  1005. AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
  1006. taoKeParams.pid= ALTK_PID;
  1007. //打开方式
  1008. AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  1009. showParam.openType = AlibcOpenTypeAuto;
  1010. [[AlibcTradeSDK sharedInstance].tradeService openByUrl:url identity:@"trade" webView:nil parentController:self.parentViewController showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  1011. } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  1012. }];
  1013. }
  1014. #pragma mark ===================== layezer ==============
  1015. - (NSArray *)goodsArr {
  1016. if (!_goodsArr) {
  1017. _goodsArr = [NSMutableArray array];
  1018. }
  1019. return _goodsArr;
  1020. }
  1021. - (NSMutableArray *)moduleDataArr {
  1022. if (!_moduleDataArr) {
  1023. _moduleDataArr = [NSMutableArray array];
  1024. }
  1025. return _moduleDataArr;
  1026. }
  1027. - (LDTodayNewsView *)scrollNewsView {
  1028. if (!_scrollNewsView) {
  1029. _scrollNewsView = [[LDTodayNewsView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 47)];
  1030. _scrollNewsView.backgroundColor = [UIColor whiteColor];
  1031. __weak typeof(self) weakSelf = self;
  1032. _scrollNewsView.clickMessage = ^(NSInteger index) {
  1033. LDNewsListViewController *list = [[LDNewsListViewController alloc] init];
  1034. [weakSelf.navigationController pushViewController:list animated:YES];
  1035. };
  1036. }
  1037. return _scrollNewsView;
  1038. }
  1039. - (LDSuperBrandView *)superBrandView {
  1040. if (!_superBrandView) {
  1041. _superBrandView = [[LDSuperBrandView alloc] initWithFrame:CGRectMake(5, 0, SCREEN_WIDTH-10, 100+SCREEN_WIDTH*36/365)];
  1042. _superBrandView.layer.cornerRadius = 6;
  1043. _superBrandView.layer.masksToBounds = YES;
  1044. __weak typeof(self) weakSelf = self;
  1045. _superBrandView.selectedClick = ^(LDSuperBrandModel *model) {
  1046. //点击大牌商品
  1047. LDSearchCoupleWebViewController *searchCoupleWeb = [[LDSearchCoupleWebViewController alloc] init];
  1048. searchCoupleWeb.url = model.url;
  1049. searchCoupleWeb.jsString = model.ios_js_string;
  1050. searchCoupleWeb.name = model.name;
  1051. if ([[ALBBSession sharedInstance] isLogin] && [AccountTool isLogin]) {
  1052. //进入
  1053. [weakSelf.navigationController pushViewController:searchCoupleWeb animated:YES];
  1054. }else if (![AccountTool isLogin]) {
  1055. //未登录
  1056. LDNewLoginVC *login = [[LDNewLoginVC alloc] init];
  1057. login.modalPresentationStyle = UIModalPresentationFullScreen;
  1058. [weakSelf presentViewController:login animated:YES completion:nil];
  1059. }else if (![[ALBBSession sharedInstance] isLogin]) {
  1060. //淘宝未授权
  1061. ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
  1062. [albbSDK setAppkey:ALBC_APP_KEY];
  1063. [albbSDK setAuthOption:NormalAuth];
  1064. [albbSDK auth:weakSelf successCallback:^(ALBBSession *session){
  1065. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeTaoBaoAuthor object:nil];
  1066. [weakSelf.navigationController pushViewController:searchCoupleWeb animated:YES];
  1067. } failureCallback:^(ALBBSession *session,NSError *error){
  1068. NSLog(@"session == %@,error == %@",session,error);
  1069. }];
  1070. }
  1071. };
  1072. _superBrandView.moreClick = ^{
  1073. //点击更多
  1074. FSBaseViewController *faVC= [[FSBaseViewController alloc]init];
  1075. faVC.model=weakSelf.model;
  1076. [weakSelf.navigationController pushViewController:faVC animated:YES];
  1077. };
  1078. }
  1079. return _superBrandView;
  1080. }
  1081. @end