省钱达人

DRTodayViewController.m 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. //
  2. // DRTodayViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/17.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRTodayViewController.h"
  9. #import "SDCycleScrollView.h"
  10. #import "DROnePicCell.h"
  11. #import "DRCountHeaderView.h"
  12. #import "DRMorePicCell.h"
  13. #import "DRTodayBannerModel.h"
  14. #import "DRChildGoodModel.h"
  15. #import "DRMorePicModel.h"
  16. #import "DRGoodsInfo.h"
  17. #import "DRAdversementCell.h"
  18. #import "DRGoodDetailViewController.h"
  19. #import "DRGoodListCidViewController.h"
  20. #import "DRAdWebViewController.h"
  21. #import "DRGoodListViewController.h"
  22. #import "DRNineNineMainViewController.h"
  23. #import "DRMorePicCollectionCell.h"
  24. #import "DRMorePicCollectionModel.h"
  25. #import "DRGoodCollectionCell.h"
  26. #import "DRShareGoodsModel.h"
  27. #import "DRShareGoodsViewController.h"
  28. #import "DRPrivilegeReferralViewController.h"
  29. #import "NSNumber+YHExpanded.h"
  30. #import "DRTodayModelCollectionCell.h"
  31. #import "DRRankListViewController.h"
  32. #import "DRTodayMudleModel.h"
  33. #import <AlibcTradeSDK/AlibcTradeSDK.h>
  34. #import <AlibabaAuthSDK/ALBBSession.h>
  35. #import <AlibabaAuthSDK/ALBBSDK.h>
  36. #import "DRGetMoneyViewController.h"
  37. #import "DRBuyLimitMainController.h"
  38. #import "DRTodayReatCollectionCell.h"
  39. static NSString *KYHMorePicCollectionCell = @"KYHMorePicCollectionCell";
  40. static NSString *KYHMorePicCell = @"KYHMorePicCell";
  41. static NSString *KYHGoodCollectionCell = @"KYHGoodCollectionCell";
  42. static NSString *KModelCollecionCell = @"modelCollecionCell";
  43. static NSString *KReactCollecionCell = @"ReactCollecionCell";
  44. static NSString *KSectionOne = @"KSectionOne";
  45. static NSString *KSectionTwo = @"KSectionTwo";
  46. static NSString *KSectionThree = @"KSectionThree";
  47. static CGFloat bannerHeight = 150;
  48. @interface DRTodayViewController ()
  49. <
  50. UICollectionViewDelegate,
  51. UICollectionViewDataSource,
  52. UICollectionViewDelegateFlowLayout,
  53. SDCycleScrollViewDelegate,
  54. YHMorePicCellDelegate,
  55. YHMorePicCollectionCellDelegate,
  56. LDTodayModelCollectionCellDelegate,
  57. YHCountDownViewDelegate
  58. >
  59. {
  60. NSInteger _page;
  61. }
  62. @property (nonatomic, strong) UICollectionView *collectionView;
  63. @property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
  64. @property (nonatomic, strong) NSArray *bannerList;
  65. @property (nonatomic, strong) NSMutableArray *goodsArr;
  66. @property (nonatomic, strong) DRMorePicCell *morePicCell;
  67. @property (nonatomic, strong) DRMorePicCollectionCell *morePicCollectionCell;
  68. @property (nonatomic, strong) NSArray *morePicArr;
  69. @property (nonatomic, strong) NSArray *morePicCollectionArr;
  70. @property (nonatomic, strong) NSMutableArray *moduleDataArr;
  71. @property (nonatomic, strong) DRGoodsInfo *goodsInfo; //商品信息,包括刷新事件
  72. /**组头*/
  73. @property (nonatomic, strong) UICollectionReusableView *sectionOne;
  74. @property (nonatomic, strong) UICollectionReusableView *sectionThree;
  75. @end
  76. @implementation DRTodayViewController
  77. - (void)viewDidLoad {
  78. [super viewDidLoad];
  79. [self configCollectionView];
  80. [self request];
  81. [self.collectionView reloadData];
  82. }
  83. - (void)request {
  84. [self loadBannerData];
  85. [self loadHotRecomPicCollectionData];
  86. [self loadHotRecomPicData];
  87. [self loadModelCellData];
  88. [self loadCategoryGoodsList];
  89. }
  90. - (void)configCollectionView {
  91. _page = 1;
  92. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  93. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ChildTableViewHeight+40) collectionViewLayout:flowLayout];
  94. flowLayout.minimumLineSpacing = 5;
  95. flowLayout.minimumInteritemSpacing = 0;
  96. [self.collectionView registerClass:[DRMorePicCollectionCell class] forCellWithReuseIdentifier:KYHMorePicCollectionCell];
  97. [self.collectionView registerClass:[DRMorePicCell class] forCellWithReuseIdentifier:KYHMorePicCell];
  98. [self.collectionView registerClass:[DRGoodCollectionCell class] forCellWithReuseIdentifier:KYHGoodCollectionCell];
  99. [self.collectionView registerClass:[DRTodayModelCollectionCell class] forCellWithReuseIdentifier:KModelCollecionCell];
  100. [self.collectionView registerClass:[DRTodayReatCollectionCell class] forCellWithReuseIdentifier:KReactCollecionCell];
  101. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionOne];
  102. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionTwo];
  103. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionThree];
  104. // self.collectionView.backgroundColor = [UIColor YHColorWithHex:0xf6f6f6];
  105. self.collectionView.backgroundColor = [UIColor yhGrayColor];
  106. self.collectionView.showsVerticalScrollIndicator = NO;
  107. self.collectionView.delegate = self;
  108. self.collectionView.dataSource = self;
  109. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  110. [self refreshData];
  111. }];
  112. // header.lastUpdatedTimeLabel.hidden = YES;
  113. // header.stateLabel.hidden = YES;
  114. //正在刷新的图片
  115. // NSArray *imgArr = @[[UIImage imageNamed:@"ant1"],[UIImage imageNamed:@"ant2"]];
  116. // [header setImages:imgArr duration:0.3 forState:MJRefreshStateRefreshing];
  117. // [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStateWillRefresh];
  118. // [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStatePulling];
  119. self.collectionView.mj_header = header;
  120. self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  121. [self loadMoreData];
  122. }];
  123. [self.collectionView.mj_footer beginRefreshing];
  124. if (@available(iOS 11.0, *)) {
  125. self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用
  126. }else {
  127. self.automaticallyAdjustsScrollViewInsets = NO;
  128. }
  129. [self.view addSubview:self.collectionView];
  130. CGFloat height = (bannerHeight/375.f)*SCREEN_WIDTH;
  131. CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, height);
  132. self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:rect delegate:self placeholderImage:nil];
  133. self.cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"page_sel"];
  134. self.cycleScrollView.pageDotImage = [UIImage imageNamed:@"page_nor"];
  135. self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleToFill;
  136. }
  137. - (void)loadBannerData {
  138. [DRCacheHttp get:Banner_list params:nil success:^(id json, BOOL isCache) {
  139. self.bannerList = [NSArray yy_modelArrayWithClass:[DRTodayBannerModel class] json:json[@"data"]];
  140. [self creatCycleScrollView];
  141. } failure:^(NSError *error) {
  142. }];
  143. }
  144. - (void)creatCycleScrollView {
  145. NSMutableArray *imgArr = [NSMutableArray array];
  146. for (DRTodayBannerModel *model in self.bannerList) {
  147. [imgArr addObject:model.photo];
  148. }
  149. self.cycleScrollView.imageURLStringsGroup = imgArr;
  150. }
  151. /**
  152. 加载下部商品列表
  153. */
  154. - (void)loadCategoryGoodsList {
  155. NSDictionary *para = @{@"sort":@"1",
  156. @"page":@(_page),
  157. @"category_id":self.model.Id,
  158. @"stype":@"0"};
  159. [DRCacheHttp post:StocklistByCategoryId params:para success:^(id json, BOOL isCache) {
  160. if ([self.collectionView.mj_header isRefreshing]) [self.goodsArr removeAllObjects];
  161. //清空缓存数据,展示真正的数据(如果page是1,且不是缓存数据,说明是真正的数据)
  162. if (_page == 1 && !isCache) [self.goodsArr removeAllObjects];
  163. self.goodsInfo = [DRGoodsInfo yy_modelWithJSON:json];
  164. NSArray *list = [NSArray yy_modelArrayWithClass:[DRChildGoodModel class] json:json[@"data"]];
  165. [self noMoreDataWithArray:list];
  166. [self.goodsArr addObjectsFromArray:list];
  167. [self.collectionView reloadData];
  168. } failure:^(NSError *error) {
  169. [self endRefreshing];
  170. [self.collectionView.mj_footer endRefreshing];
  171. }];
  172. }
  173. - (void)noMoreDataWithArray:(NSArray *)array {
  174. if (array.count <= 0) {
  175. [self.collectionView.mj_footer endRefreshingWithNoMoreData];
  176. }else {
  177. [self.collectionView.mj_footer endRefreshing];
  178. }
  179. }
  180. - (void)endRefreshing {
  181. [self.collectionView.mj_header endRefreshing];
  182. }
  183. - (void)refreshData {
  184. _page = 1;
  185. [self loadBannerData];
  186. [self loadModelCellData];
  187. [self loadHotRecomPicData];
  188. [self loadHotRecomPicCollectionData];
  189. [self loadCategoryGoodsList];
  190. }
  191. /**
  192. 上拉加载
  193. */
  194. - (void)loadMoreData {
  195. _page++;
  196. [self loadCategoryGoodsList];
  197. }
  198. /**
  199. 多图推荐
  200. */
  201. - (void)loadHotRecomPicData {
  202. [DRCacheHttp get:Goldgroups params:nil success:^(id json, BOOL isCache) {
  203. self.morePicArr = [NSArray yy_modelArrayWithClass:[DRMorePicModel class] json:json[@"data"]];
  204. if (self.morePicArr.count==0) {
  205. [self.collectionView reloadData];
  206. }
  207. // [self.morePicCell setModelDatas:self.morePicArr];
  208. [self.collectionView reloadData];
  209. } failure:^(NSError *error) {
  210. }];
  211. }
  212. /**
  213. 加载菜单栏目
  214. */
  215. - (void)loadHotRecomPicCollectionData {
  216. [DRCacheHttp get:GoldCollectiongroups params:nil success:^(id json, BOOL isCache) {
  217. self.morePicCollectionArr = [NSArray yy_modelArrayWithClass:[DRMorePicCollectionModel class] json:json[@"data"]];
  218. [self.morePicCollectionCell setModelDatas:self.morePicCollectionArr];
  219. [self.collectionView reloadData];
  220. } failure:^(NSError *error) {
  221. }];
  222. }
  223. /**
  224. 加载分类模块数据
  225. */
  226. - (void)loadModelCellData {
  227. NSString *url = [NSString stringWithFormat:@"%@/api/v2/channel/advFourList",BaseURL];
  228. [DRCacheHttp post:url params:@{@"platform":@"2"} success:^(id json, BOOL isCache) {
  229. NSArray *list = [NSArray yy_modelArrayWithClass:[DRTodayMudleModel class] json:json[@"list"]];
  230. if (list.count > 0) {
  231. [self countDownViewSetCount:list.firstObject];
  232. }
  233. [self.moduleDataArr removeAllObjects];
  234. [self.moduleDataArr addObjectsFromArray:list];
  235. [self.collectionView reloadData];
  236. [self endRefreshing];
  237. } failure:^(NSError *error) {
  238. [self endRefreshing];
  239. }];
  240. }
  241. - (void)countDownViewSetCount:(DRTodayMudleModel *)model {
  242. NSString *endTime = [NSString stringWithFormat:@"%@000",model.remainTime];
  243. [[DRCountDownView shareInstace] setEndTimer:endTime];
  244. }
  245. #pragma mark ------ YHCountDownViewDelegate -------
  246. - (void)countViewTimeOutAction {
  247. [self.collectionView.mj_header beginRefreshing];
  248. [self refreshData];
  249. }
  250. #pragma mark ====================== YHMorePicCellDelegate==========
  251. /**
  252. 点击推荐位多图
  253. */
  254. - (void)YHMorePicCellDidSelectedItem:(NSInteger)index {
  255. DRMorePicModel *model = self.morePicArr[index];
  256. if (model.url.length > 0) {
  257. //活动页
  258. //type为2直接打开淘宝,无需访问中间网页
  259. if ([model.jump_type isEqualToString:@"2"]) {
  260. [self jumpToTaobaoWithUrl:model.url];
  261. }else{
  262. DRAdWebViewController *adWeb = [[DRAdWebViewController alloc] init];
  263. adWeb.url = model.url;
  264. [self.navigationController pushViewController:adWeb animated:YES];
  265. }
  266. }else {
  267. //列表页
  268. DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
  269. list.cate_id = model.Id;
  270. list.name = model.name;
  271. list.topRequest = 2;
  272. [self.navigationController pushViewController:list animated:YES];
  273. }
  274. [MobClick event:home_recommend label:model.name];
  275. }
  276. #pragma mark ====================== YHMorePicCollectionCellDelegate==========
  277. - (void)YHMorePicCollectionCellDidSelectedItem:(NSInteger)index{
  278. DRMorePicCollectionModel *model = self.morePicCollectionArr[index];
  279. if (model.url.length > 0) {
  280. //活动页
  281. //type为2直接打开淘宝,无需访问中间网页
  282. if ([model.jump_type isEqualToString:@"2"]) {
  283. [self jumpToTaobaoWithUrl:model.url];
  284. }else{
  285. DRAdWebViewController *adWeb = [[DRAdWebViewController alloc] init];
  286. adWeb.url = model.url;
  287. [self.navigationController pushViewController:adWeb animated:YES];
  288. }
  289. }else {
  290. DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
  291. list.cate_id = model.Id;
  292. list.name = model.name;
  293. list.topRequest = 2;
  294. [self.navigationController pushViewController:list animated:YES];
  295. }
  296. [MobClick event:Home_Items label:model.name];
  297. }
  298. #pragma mark ============ SDCycleScrollViewDelegate ==========
  299. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  300. DRTodayBannerModel *model = self.bannerList[index];
  301. if (model.url.length > 0) {
  302. //活动页
  303. //type为2直接打开淘宝,无需访问中间网页
  304. if ([model.type isEqualToString:@"2"]) {
  305. [self jumpToTaobaoWithUrl:model.url];
  306. }else{
  307. DRAdWebViewController *adWeb = [[DRAdWebViewController alloc] init];
  308. adWeb.url = model.url;
  309. [self.navigationController pushViewController:adWeb animated:YES];
  310. }
  311. }else {
  312. //列表页
  313. DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
  314. list.cate_id = model.group_id;
  315. list.name = model.note;
  316. list.topRequest = 2;
  317. [self.navigationController pushViewController:list animated:YES];
  318. }
  319. [MobClick event:home_banner label:model.photo];
  320. }
  321. #pragma mark ------- LDTodayModelCollectionCellDelegate -----
  322. - (void)modelCollectionCellMoreButtonClick:(DRTodayModelCollectionCell *)cell{
  323. DRTodayMudleModel *model = cell.model;
  324. if ([model.type isEqualToString:@"1"]) {
  325. DRBuyLimitMainController *buyLimit = [[DRBuyLimitMainController alloc] init];
  326. [self.navigationController pushViewController:buyLimit animated:YES];
  327. }else if ([model.type isEqualToString:@"2"]){
  328. DRRankListViewController *rankList = [[DRRankListViewController alloc] init];
  329. rankList.name = model.name;
  330. [self.navigationController pushViewController:rankList animated:YES];
  331. }else {
  332. //列表页
  333. DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
  334. list.cate_id = model.Id;
  335. list.name = model.name;
  336. list.topRequest = 2;
  337. [self.navigationController pushViewController:list animated:YES];
  338. }
  339. [MobClick event:TodayClickTop label:model.name];
  340. }
  341. #pragma mark ============ UICollectionView Delegate && DataSource ==========
  342. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  343. {
  344. if (section == 0 ) {
  345. return 1;
  346. }else if (section == 1){
  347. return self.morePicArr.count;
  348. }else if (section == 2){
  349. return self.moduleDataArr.count;
  350. }else if(section == 3){
  351. return self.goodsArr.count;
  352. }
  353. return 0;
  354. }
  355. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  356. return 4;
  357. }
  358. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  359. if (indexPath.section == 0) {
  360. if (self.morePicCollectionArr==nil||self.morePicCollectionArr.count==0) {
  361. return CGSizeMake(SCREEN_WIDTH, .1);
  362. }
  363. NSInteger offHeight=0;
  364. if (iPhone5) {
  365. offHeight=10;
  366. }
  367. NSInteger Crow=1;
  368. NSInteger Coff=-1;
  369. NSInteger CrowItemSum=5;
  370. Coff=self.morePicCollectionArr.count%CrowItemSum;
  371. if (Coff!=0) {
  372. CrowItemSum=4;
  373. Coff=self.morePicCollectionArr.count%CrowItemSum;
  374. if (Coff!=0) {
  375. CrowItemSum=3;
  376. Coff=self.morePicCollectionArr.count%CrowItemSum;
  377. if (Coff!=0) {
  378. CrowItemSum=5;
  379. Crow++;
  380. }
  381. }
  382. }
  383. Crow=self.morePicCollectionArr.count/CrowItemSum;
  384. if (Coff!=0) {
  385. Crow++;
  386. }
  387. CGFloat totalHeight = (SCREEN_WIDTH/4+offHeight)*Crow;
  388. return CGSizeMake(SCREEN_WIDTH, totalHeight);
  389. }
  390. if (indexPath.section == 1) {
  391. if (!self.morePicArr.count||self.morePicArr.count==0) {
  392. return CGSizeMake(SCREEN_WIDTH, .1);
  393. }
  394. // CGFloat leftWidth = SCREEN_WIDTH*0.37;
  395. // CGFloat leftHeight = leftWidth*19/14;
  396. // return CGSizeMake(SCREEN_WIDTH, leftHeight);
  397. CGFloat width = (SCREEN_WIDTH-13)/2;
  398. CGSize size = CGSizeMake(width, width*83/170);
  399. return size;
  400. }else if (indexPath.section == 2){
  401. return CGSizeMake(SCREEN_WIDTH, Fitsize(218));
  402. } else if (indexPath.section == 3) {
  403. CGFloat width = (SCREEN_WIDTH-5)/2;
  404. CGFloat height = width + 102;
  405. return CGSizeMake(width, height);
  406. }
  407. return CGSizeZero;
  408. }
  409. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  410. {
  411. if (section == 0) {
  412. CGFloat height = (bannerHeight/375.f)*SCREEN_WIDTH;
  413. return CGSizeMake(SCREEN_WIDTH, height);
  414. }else if (section == 1 || section == 2){
  415. return CGSizeMake(SCREEN_WIDTH, 5);
  416. }else {
  417. return CGSizeMake(SCREEN_WIDTH, FITSIZE(40));
  418. }
  419. }
  420. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  421. {
  422. return CGSizeMake(0, 0);
  423. }
  424. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  425. {
  426. if (indexPath.section==0) {
  427. self.morePicCollectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHMorePicCollectionCell forIndexPath:indexPath];
  428. self.morePicCollectionCell.delegate = self;
  429. [self.morePicCollectionCell setModelDatas:self.morePicCollectionArr];
  430. return self.morePicCollectionCell;
  431. }
  432. if (indexPath.section == 1) {
  433. // self.morePicCell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHMorePicCell forIndexPath:indexPath];
  434. // self.morePicCell.delegate = self;
  435. // [self.morePicCell setModelDatas:self.morePicArr];
  436. // return self.morePicCell;
  437. DRTodayReatCollectionCell *reactCell = [self.collectionView dequeueReusableCellWithReuseIdentifier:KReactCollecionCell forIndexPath:indexPath];
  438. DRMorePicModel *model = self.morePicArr[indexPath.row];
  439. reactCell.model = model;
  440. return reactCell;
  441. }else if (indexPath.section == 2){
  442. DRTodayModelCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KModelCollecionCell forIndexPath:indexPath];
  443. cell.delegate = self;
  444. cell.indexPath = indexPath;
  445. DRTodayMudleModel *model = self.moduleDataArr[indexPath.row];
  446. cell.model = model;
  447. if (indexPath.row == 0) {
  448. DRCountDownView *countdown = [DRCountDownView shareInstace];
  449. countdown.y = Fitsize(15);
  450. countdown.x = Fitsize(132);
  451. countdown.delegate = self;
  452. [cell addSubview:countdown];
  453. cell.desLabel.hidden = YES;
  454. }else {
  455. cell.desLabel.hidden = NO;
  456. }
  457. return cell;
  458. }
  459. else if(indexPath.section == 3){
  460. DRChildGoodModel *model = self.goodsArr[indexPath.item];
  461. DRGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHGoodCollectionCell forIndexPath:indexPath];
  462. cell.model = model;
  463. return cell;
  464. }
  465. return nil;
  466. }
  467. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  468. if (indexPath.section == 0) {
  469. if (self.sectionOne) return self.sectionOne;
  470. self.sectionOne = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionOne forIndexPath:indexPath];
  471. [self.sectionOne addSubview:self.cycleScrollView];
  472. return self.sectionOne;
  473. }
  474. if (indexPath.section == 1 || indexPath.section == 2) {
  475. UICollectionReusableView *sectionTwo = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionTwo forIndexPath:indexPath];
  476. return sectionTwo;
  477. }
  478. if (indexPath.section == 3) {
  479. self.sectionThree = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionThree forIndexPath:indexPath];
  480. UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, Fitsize(40))];
  481. title.text = @"精选好物";
  482. title.textColor = [UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0x47FFDA] toColor:[UIColor YHColorWithHex:0x38D4FB] withWidth:SCREEN_WIDTH];
  483. title.font = [UIFont systemFontOfSize:Fitsize(19)];
  484. [title sizeToFit];
  485. title.centerX = SCREEN_WIDTH/2+Fitsize(10);
  486. title.centerY = Fitsize(20);
  487. [self.sectionThree addSubview:title];
  488. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(title.x-Fitsize(25), 0, Fitsize(23), FITSIZE(21))];
  489. imageView.centerY = Fitsize(20);
  490. imageView.image = [UIImage imageNamed:@"good_gs"];
  491. [self.sectionThree addSubview:imageView];
  492. return self.sectionThree;
  493. }
  494. return nil;
  495. }
  496. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  497. if (section == 1) {
  498. return UIEdgeInsetsMake(0, 5, 0, 5);
  499. }else {
  500. return UIEdgeInsetsMake(0, 0, 0, 0);
  501. }
  502. }
  503. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  504. if (section == 1) {
  505. return 3;
  506. }else {
  507. return 5;
  508. }
  509. }
  510. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  511. if (indexPath.section == 1) {
  512. DRMorePicModel *model = self.morePicArr[indexPath.row];
  513. if (model.url.length > 0) {
  514. //活动页
  515. //type为2直接打开淘宝,无需访问中间网页
  516. if ([model.jump_type isEqualToString:@"2"]) {
  517. [self jumpToTaobaoWithUrl:model.url];
  518. }else{
  519. DRAdWebViewController *adWeb = [[DRAdWebViewController alloc] init];
  520. adWeb.url = model.url;
  521. [self.navigationController pushViewController:adWeb animated:YES];
  522. }
  523. }else {
  524. //列表页
  525. DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
  526. list.cate_id = model.Id;
  527. list.name = model.name;
  528. list.topRequest = 2;
  529. [self.navigationController pushViewController:list animated:YES];
  530. }
  531. [MobClick event:home_recommend label:model.name];
  532. }
  533. if (indexPath.section == 3) {
  534. DRChildGoodModel *model = self.goodsArr[indexPath.row];
  535. DREventModel *evevtModel = [[DREventModel alloc] initWithOrigin:model.origin category_id:self.model.Id source:homeAction];
  536. DRGoodDetailViewController *detail = [[DRGoodDetailViewController alloc] init];
  537. detail.eventModel = evevtModel;
  538. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  539. detail.requestModel = requestModel;
  540. [self.navigationController pushViewController:detail animated:YES];
  541. [MobClick event:home_hot];
  542. }
  543. }
  544. #pragma mark ------
  545. #pragma mark - scrollView
  546. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  547. {
  548. //scrollView已经有拖拽手势,直接拿到scrollView的拖拽手势
  549. UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer;
  550. //获取到拖拽的速度 >0 向下拖动 <0 向上拖动
  551. CGFloat velocity = [pan velocityInView:scrollView].y;
  552. if (velocity <- 10) {
  553. //向上拖动,隐藏导航栏
  554. self.collectionView.height = ChildTableViewHeight+NavBarHeight-KStatusBarHeight;
  555. }else if (velocity > 10) {
  556. //向下拖动,显示导航栏
  557. self.collectionView.height = ChildTableViewHeight;
  558. }else if(velocity == 0){
  559. //停止拖拽
  560. }
  561. NSNotification *noti = [[NSNotification alloc] initWithName:ScrollDirectorNoti object:nil userInfo:@{@"director":@(velocity)}];
  562. [[NSNotificationCenter defaultCenter] postNotification:noti];
  563. }
  564. #pragma mark ------
  565. - (void)jumpToTaobaoWithUrl:(NSString *)url {
  566. id<AlibcTradePage> page = [AlibcTradePageFactory page:url];
  567. //淘客信息
  568. AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
  569. taoKeParams.pid= ALTK_PID;
  570. //打开方式
  571. AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  572. showParam.openType = AlibcOpenTypeAuto;
  573. [[AlibcTradeSDK sharedInstance].tradeService show:self.parentViewController page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  574. } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  575. }];
  576. }
  577. #pragma mark ===================== layezer ==============
  578. - (NSArray *)goodsArr {
  579. if (!_goodsArr) {
  580. _goodsArr = [NSMutableArray array];
  581. }
  582. return _goodsArr;
  583. }
  584. - (NSMutableArray *)moduleDataArr {
  585. if (!_moduleDataArr) {
  586. _moduleDataArr = [NSMutableArray array];
  587. }
  588. return _moduleDataArr;
  589. }
  590. - (void)didReceiveMemoryWarning {
  591. [super didReceiveMemoryWarning];
  592. // Dispose of any resources that can be recreated.
  593. }
  594. /*
  595. #pragma mark - Navigation
  596. // In a storyboard-based application, you will often want to do a little preparation before navigation
  597. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  598. // Get the new view controller using [segue destinationViewController].
  599. // Pass the selected object to the new view controller.
  600. }
  601. */
  602. @end