1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180 |
- //
- // DRTodayViewController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/1/17.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "DRTodayViewController.h"
- #import "SDCycleScrollView.h"
- #import "DROnePicCell.h"
- #import "DRCountHeaderView.h"
- #import "DRMorePicCell.h"
- #import "DRTodayBannerModel.h"
- #import "DRChildGoodModel.h"
- #import "DRMorePicModel.h"
- #import "DRGoodsInfo.h"
- #import "DRAdversementCell.h"
- #import "DRGoodDetailViewController.h"
- #import "DRAdWebViewController.h"
- #import "DRGoodListViewController.h"
- #import "FSBaseViewController.h"
- #import "DRMorePicCollectionCell.h"
- #import "DRMorePicCollectionModel.h"
- #import "DRGoodCollectionCell.h"
- #import "DRSearchCoupleWebViewController.h"
- #import "DRShareGoodsModel.h"
- #import "DRShareGoodsViewController.h"
- #import "DRPrivilegeReferralViewController.h"
- #import "NSNumber+YHExpanded.h"
- #import "DRTodayModelCollectionCell.h"
- #import "DRRankListViewController.h"
- #import "DRTodayMudleModel.h"
- #import "FSBaseViewController.h"
- #import <AlibcTradeSDK/AlibcTradeSDK.h>
- #import <AlibabaAuthSDK/ALBBSession.h>
- #import <AlibabaAuthSDK/ALBBSDK.h>
- #import "KBTodayReatCollectionCell.h"
- #import "DRBuyLimitMainController.h"
- #import "NewPagedFlowView.h"
- #import "DRSearchCoupleWebViewController.h"
- #import "DRLoginViewController.h"
- #import "FSBaseViewController.h"
- #import "DRTodayAdView.h"
- #import "AdJumpManager.h"
- #import "DRHomeMainViewController.h"
- #import "DRTodayNewsView.h"
- #import "DRSuperBrandView.h"
- #import "DRTodayHorizontalGoodCell.h"
- #import "DRSuperBrandModel.h"
- #import "DRTodayGoodModel.h"
- #import "DRTodayGroupCell.h"
- #import "DRTodayFlowLayout.h"
- #import "DRNewsListViewController.h"
- #import "DRScrollNewsModel.h"
- static NSString *KYHMorePicCollectionCell = @"KYHMorePicCollectionCell";
- static NSString *KYHMorePicCell = @"KYHMorePicCell";
- static NSString *KYHGoodCollectionCell = @"KYHGoodCollectionCell";
- static NSString *KModelCollecionCell = @"modelCollecionCell";
- static NSString *KTodayNewsCell = @"KTodayNewsCell";
- static NSString *KSuperBrandCell = @"KSuperBrandCell";
- static NSString *KTodayGroupCell = @"KTodayGroupCell";
- static NSString *KSectionOne = @"KSectionOne";
- static NSString *KSectionTwo = @"KSectionTwo";
- static NSString *KSectionThree = @"KSectionThree";
- static NSString *KReactCollecionCell = @"ReactCollecionCell";
- static CGFloat bannerScale = 117.f/355.f;
- @interface DRTodayViewController ()
- <
- UICollectionViewDelegate,
- UICollectionViewDataSource,
- TodayCollectionViewDelegateFlowLayout,
- SDCycleScrollViewDelegate,
- YHMorePicCellDelegate,
- YHMorePicCollectionCellDelegate,
- LDTodayModelCollectionCellDelegate,
- YHCountDownViewDelegate,
- NewPagedFlowViewDelegate,
- NewPagedFlowViewDataSource
- >
- {
- NSInteger _page;
- DRTodayAdView *_adView;
- NSArray *_adDataArr;
- }
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
- @property (nonatomic, strong) NSArray *bannerList;
- @property (nonatomic, strong) NSArray *superBrandList;
- @property (nonatomic, strong) NSMutableArray *goodsArr;
- @property (nonatomic, strong) DRMorePicCell *morePicCell;
- @property (nonatomic, strong) DRMorePicCollectionCell *morePicCollectionCell;
- @property (nonatomic, strong) NSArray *morePicArr;
- @property (nonatomic, strong) NSArray *morePicCollectionArr;
- @property (nonatomic, strong) NSMutableArray *moduleDataArr;
- @property (nonatomic, strong) DRGoodsInfo *goodsInfo; //商品信息,包括刷新事件
- @property (nonatomic, strong) NewPagedFlowView *NewPagedFlowView;
- @property (nonatomic, strong) DRTodayNewsView *scrollNewsView;
- @property (nonatomic, strong) DRSuperBrandView *superBrandView;
- /**组头*/
- @property (nonatomic, strong) UICollectionReusableView *sectionOne;
- @property (nonatomic, strong) UICollectionReusableView *sectionThree;
- @end
- @implementation DRTodayViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self configCollectionView];
- [self request];
- [self.collectionView reloadData];
- }
- - (void)request {
- [self loadBannerData];
- [self loadHotRecomPicCollectionData];
- [self loadCategoryGoodsList];
- [self loadAdData];
- [self loadSuperBrand];
- // [self loadTodayScollNews];
- }
- - (void)configCollectionView {
-
- _page = 1;
-
- DRTodayFlowLayout *flowLayout = [[DRTodayFlowLayout alloc]init];
- self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 5, SCREEN_WIDTH, ChildTableViewHeight+40) collectionViewLayout:flowLayout];
- flowLayout.minimumLineSpacing = 0;
- flowLayout.minimumInteritemSpacing = 0;
- [self.collectionView registerClass:[DRMorePicCollectionCell class] forCellWithReuseIdentifier:KYHMorePicCollectionCell];
- [self.collectionView registerClass:[DRMorePicCell class] forCellWithReuseIdentifier:KYHMorePicCell];
- [self.collectionView registerClass:[DRTodayHorizontalGoodCell class] forCellWithReuseIdentifier:KYHGoodCollectionCell];
- [self.collectionView registerClass:[DRTodayModelCollectionCell class] forCellWithReuseIdentifier:KModelCollecionCell];
- [self.collectionView registerClass:[KBTodayReatCollectionCell class] forCellWithReuseIdentifier:KReactCollecionCell];
- [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:KTodayNewsCell];
- [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:KSuperBrandCell];
- [self.collectionView registerClass:[DRTodayGroupCell class] forCellWithReuseIdentifier:KTodayGroupCell];
-
- [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionOne];
- [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionTwo];
- [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionThree];
- self.collectionView.backgroundColor = [UIColor clearColor];
- self.collectionView.showsVerticalScrollIndicator = NO;
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- MJRefreshStateHeader *header = [MJRefreshStateHeader headerWithRefreshingBlock:^{
- [self refreshData];
- }];
- header.lastUpdatedTimeLabel.hidden = YES;
- header.stateLabel.textColor = [UIColor whiteColor];
- self.collectionView.mj_header = header;
-
-
- self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
- [self loadMoreData];
- }];
- [self.collectionView.mj_footer beginRefreshing];
-
-
- if (@available(iOS 11.0, *)) {
- self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用
- }else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- [self.view addSubview:self.collectionView];
-
-
-
- // CGFloat height = (bannerHeight/375.f)*SCREEN_WIDTH;
- // CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, height);
- //
- // self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:rect delegate:self placeholderImage:nil];
- // self.cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"page_sel"];
- // self.cycleScrollView.pageDotImage = [UIImage imageNamed:@"page_nor"];
- // self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleToFill;
- self.NewPagedFlowView = [[NewPagedFlowView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH * bannerScale)];
- self.NewPagedFlowView.backgroundColor = [UIColor clearColor];
- self.NewPagedFlowView.delegate = self;
- self.NewPagedFlowView.dataSource = self;
- self.NewPagedFlowView.minimumPageAlpha = 0.1;
- self.NewPagedFlowView.isCarousel = YES;
- self.NewPagedFlowView.orientation = NewPagedFlowViewOrientationHorizontal;
- self.NewPagedFlowView.isOpenAutoScroll = YES;
- // self.NewPagedFlowView.layer.shadowOffset = CGSizeMake(2, 5);
- // self.NewPagedFlowView.layer.shadowOpacity = 0.3;
- // self.NewPagedFlowView.layer.shadowColor = [UIColor blackColor].CGColor;
-
-
-
- // [self.loginBackView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.width.mas_equalTo(SCREEN_WIDTH);
- // make.height.mas_equalTo(FITSIZE(45));
- // make.bottom.mas_equalTo(200);
- // }];
- }
- - (void)loadAdData {
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/adv/advByType",BaseURL];
- NSDictionary *para = @{@"adv_type":@"1"};
- [DRHttp get:url params:para success:^(id json) {
-
- _adDataArr = [NSArray yy_modelArrayWithClass:[AdPopModel class] json:json[@"data"]];
- if (_adDataArr.count > 0) {
- [self creatAdView:_adDataArr];
- }
- [self.collectionView reloadData];
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)creatAdView:(NSArray *)list {
- // DRTodayAdView *adView = [[DRTodayAdView alloc] initWithFrame:CGRectMake(Fitsize(10), Fitsize(3), SCREEN_WIDTH-Fitsize(20), (SCREEN_WIDTH-Fitsize(20))*200/750)];
- DRTodayAdView *adView = [[DRTodayAdView alloc] initWithFrame:CGRectMake(5, 5, SCREEN_WIDTH-10, (SCREEN_WIDTH-10)*200/750)];
- _adView.tag=2002;
- _adView = adView;
- _adView.model = list.firstObject;
- adView.tapAdBlock = ^{
- [MobClick event:AdvClick label:@"1"];
- [AdJumpManager jumpToPageWithModel:list.firstObject ParentViewControll:self];
- };
- }
- - (void)loadBannerData {
-
- [DRCacheHttp get:Banner_list params:nil success:^(id json, BOOL isCache) {
- self.bannerList = [NSArray yy_modelArrayWithClass:[DRTodayBannerModel class] json:json[@"data"]];
- NSLog(@"%@",json[@"data"]);
- [self creatCycleScrollView];
- } failure:^(NSError *error) {
-
- }];
-
- }
- /**
- 加载超级大牌
- */
- - (void)loadSuperBrand {
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/channel/SuperBrand",BaseURL];
- NSDictionary *para = @{@"position":@"1",
- @"category_id":self.model.Id
- };
- [DRCacheHttp post:url params:para success:^(id json, BOOL isCache) {
- self.superBrandList = [NSArray yy_modelArrayWithClass:[DRSuperBrandModel class] json:json[@"data"]];
- [self.superBrandView setSuperBrandData:self.superBrandList];
- [self.collectionView reloadData];
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)creatCycleScrollView {
- NSMutableArray *imgArr = [NSMutableArray array];
- for (DRTodayBannerModel *model in self.bannerList) {
- [imgArr addObject:model.photo];
- }
- // self.cycleScrollView.imageURLStringsGroup = imgArr;
- [self.NewPagedFlowView reloadData];
- }
- /**
- 加载下部商品列表
- */
- - (void)loadCategoryGoodsList {
-
- NSDictionary *para = @{@"sort":@"1",
- @"page":@(_page),
- @"category_id":self.model.Id,
- @"stype":@"0"};
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/goodsAndStockList",BaseURL];
- [DRCacheHttp post:url params:para success:^(id json, BOOL isCache) {
-
- if ([self.collectionView.mj_header isRefreshing]) [self.goodsArr removeAllObjects];
-
- //清空缓存数据,展示真正的数据(如果page是1,且不是缓存数据,说明是真正的数据)
- if (_page == 1 && !isCache) [self.goodsArr removeAllObjects];
- NSArray *list = [NSArray yy_modelArrayWithClass:[DRTodayGoodModel class] json:json];
- [self noMoreDataWithArray:list];
- [self.goodsArr addObjectsFromArray:list];
- [self.collectionView reloadData];
- [self.collectionView.mj_header endRefreshing];
- } failure:^(NSError *error) {
- [self endRefreshing];
- [self.collectionView.mj_footer endRefreshing];
- }];
-
- }
- - (void)noMoreDataWithArray:(NSArray *)array {
- if (array.count <= 0) {
- [self.collectionView.mj_footer endRefreshingWithNoMoreData];
- }else {
- [self.collectionView.mj_footer endRefreshing];
- }
- }
- - (void)endRefreshing {
- [self.collectionView.mj_header endRefreshing];
- }
- - (void)refreshData {
- _page = 1;
- [self loadBannerData];
- // [self loadModelCellData];
- // [self loadHotRecomPicData];
- [self loadAdData];
- [self loadHotRecomPicCollectionData];
- [self loadCategoryGoodsList];
- [self loadSuperBrand];
- // [self loadTodayScollNews];
-
- }
- /**
- 上拉加载
- */
- - (void)loadMoreData {
- _page++;
- [self loadCategoryGoodsList];
- }
- /**
- 多图推荐
- */
- - (void)loadHotRecomPicData {
-
- [DRCacheHttp get:Goldgroups params:nil success:^(id json, BOOL isCache) {
- self.morePicArr = [NSArray yy_modelArrayWithClass:[DRMorePicModel class] json:json[@"data"]];
- if (self.morePicArr.count==0) {
- [self.collectionView reloadData];
- }
- [self.morePicCell setModelDatas:self.morePicArr];
- [self.collectionView reloadData];
- } failure:^(NSError *error) {
-
- }];
-
- }
- /**
- 加载菜单栏目
- */
- - (void)loadHotRecomPicCollectionData {
-
- [DRCacheHttp post:GoldCollectiongroups params:nil success:^(id json, BOOL isCache) {
- self.morePicCollectionArr = [NSArray yy_modelArrayWithClass:[DRMorePicCollectionModel class] json:json[@"data"]];
- [self.morePicCollectionCell setModelDatas:self.morePicCollectionArr];
- [self.collectionView reloadData];
- } failure:^(NSError *error) {
-
- }];
-
- }
- /**
- 加载滚动头条
- */
- - (void)loadTodayScollNews {
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/message_push/LieDouHeadlines",BaseURL];
- [DRHttp post:url params:nil success:^(id json) {
-
- NSArray *list = [NSArray yy_modelArrayWithClass:[DRScrollNewsModel class] json:json[@"data"]];
- [self.scrollNewsView setDataList:list];
-
- } failure:^(NSError *error) {
-
- }];
- }
- /**
- 加载分类模块数据
- */
- - (void)loadModelCellData {
-
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/channel/advFourList",BaseURL];
- [DRCacheHttp post:url params:@{@"platform":@"2"} success:^(id json, BOOL isCache) {
- NSArray *list = [NSArray yy_modelArrayWithClass:[DRTodayMudleModel class] json:json[@"list"]];
- if (list.count > 0) {
- [self countDownViewSetCount:list.firstObject];
- }
- [self.moduleDataArr removeAllObjects];
- [self.moduleDataArr addObjectsFromArray:list];
- [self.collectionView reloadData];
-
- [self endRefreshing];
- } failure:^(NSError *error) {
- [self endRefreshing];
- }];
- }
- - (void)countDownViewSetCount:(DRTodayMudleModel *)model {
- NSString *endTime = [NSString stringWithFormat:@"%@000",model.remainTime];
- [[DRCountDownView shareInstace] setEndTimer:endTime];
- }
- #pragma mark ------ YHCountDownViewDelegate -------
- - (void)countViewTimeOutAction {
- [self.collectionView.mj_header beginRefreshing];
- }
- #pragma mark NewPagedFlowView Datasource
- - (NSInteger)numberOfPagesInFlowView:(NewPagedFlowView *)flowView {
-
- return self.bannerList.count;
-
- }
- - (PGIndexBannerSubiew *)flowView:(NewPagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{
- PGIndexBannerSubiew *bannerView = [flowView dequeueReusableCell];
- if (!bannerView) {
- bannerView = [[PGIndexBannerSubiew alloc] init];
- bannerView.tag = index;
- bannerView.layer.cornerRadius = 4;
- bannerView.layer.masksToBounds = YES;
- }
- if (self.bannerList.count > 0 && self.bannerList.count>index) {
- DRTodayBannerModel *model = self.bannerList[index];
- //在这里下载网络图片
- [bannerView.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.photo] placeholderImage:[UIImage imageNamed:@""]];
- }
-
-
- return bannerView;
- }
- - (CGSize)sizeForPageInFlowView:(NewPagedFlowView *)flowView {
- return CGSizeMake(SCREEN_WIDTH - 20, (SCREEN_WIDTH - 20) * bannerScale);
- }
- - (void)didSelectCell:(UIView *)subView withSubViewIndex:(NSInteger)subIndex {
-
-
- DRTodayBannerModel *model = self.bannerList[subIndex];
- switch (model.click_type.integerValue) {
- case 1:
- {//h5跳转
- DRAdWebViewController *adWeb = [[DRAdWebViewController alloc] init];
- adWeb.url = model.click_param;
- [self.navigationController pushViewController:adWeb animated:YES];
- }
- break;
- case 2://商品详情
- {
- DRGoodDetailViewController *detailVC = [[DRGoodDetailViewController alloc] init];
-
- DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithDTodayBannerModels:model];
- detailVC.requestModel = requestModel;
- detailVC.requestModel.goods_id = model.click_param;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- break;
- case 3://专题列表
- //列表页
- {
- DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
- list.cate_id = model.click_param;
- list.name = model.groupTitle;
- list.topRequest = 2;
- [self.navigationController pushViewController:list animated:YES];
- }
- break;
- case 4://淘宝链接
- {
- [self jumpToTaobaoWithUrl:model.click_param];
- }
- break;
- case 5://天猫超市\国际\聚划算\天猫大牌
- {
- DRSearchCoupleWebViewController *searchCoupleWeb = [[DRSearchCoupleWebViewController alloc] init];
-
- searchCoupleWeb.url = model.click_param;
- searchCoupleWeb.jsString = model.ios_js_string;
- searchCoupleWeb.name = model.note;
- if ([[ALBBSession sharedInstance] isLogin]) {
- //进入
- [self.navigationController pushViewController:searchCoupleWeb animated:YES];
- }else {
- //淘宝未授权
- ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
- [albbSDK setAppkey:ALBC_APP_KEY];
- [albbSDK setAuthOption:NormalAuth];
-
- [albbSDK auth:self successCallback:^(ALBBSession *session){
- [[NSNotificationCenter defaultCenter] postNotificationName:ChangeTaoBaoAuthor object:nil];
- [self.navigationController pushViewController:searchCoupleWeb animated:YES];
- } failureCallback:^(ALBBSession *session,NSError *error){
- NSLog(@"session == %@,error == %@",session,error);
- }];
- }
-
-
- }
- break;
- default:
- break;
- }
-
- [MobClick event:home_banner label:model.photo];
-
- }
- - (void)didScrollToPage:(NSInteger)pageNumber inFlowView:(NewPagedFlowView *)flowView {
- if (flowView == self.NewPagedFlowView) {
- DRHomeMainViewController *superVc = (DRHomeMainViewController *)self.parentViewController;
- //仅在今日精选时改变
- if (superVc.showIndex == 0) {
- UIImageView *bgImgView = superVc.bgImageView;
- DRTodayBannerModel *model = self.bannerList[pageNumber];
- [bgImgView sd_setImageWithURL:[NSURL URLWithString:model.photo_bg]];
- }
- }
-
-
-
- }
- #pragma mark ====================== YHMorePicCellDelegate==========
- /**
- 点击推荐位多图
- */
- - (void)YHMorePicCellDidSelectedItem:(NSInteger)index {
- DRMorePicModel *model = self.morePicArr[index];
- if (model.url.length > 0) {
- //活动页
- //type为2直接打开淘宝,无需访问中间网页
- if ([model.jump_type isEqualToString:@"2"]) {
- [self jumpToTaobaoWithUrl:model.url];
- }else{
- DRAdWebViewController *adWeb = [[DRAdWebViewController alloc] init];
- adWeb.url = model.url;
- [self.navigationController pushViewController:adWeb animated:YES];
- }
- }else {
- //列表页
- DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
- list.cate_id = model.Id;
- list.name = model.name;
- list.topRequest = 2;
- [self.navigationController pushViewController:list animated:YES];
- }
-
-
- [MobClick event:home_recommend label:model.name];
- }
- #pragma mark ====================== YHMorePicCollectionCellDelegate==========
- - (void)YHMorePicCollectionCellDidSelectedItem:(NSInteger)index{
- DRMorePicCollectionModel *model = self.morePicCollectionArr[index];
- switch ([model.show_type integerValue]) {
- case 1:
- {
- DRAdWebViewController *adWeb = [[DRAdWebViewController alloc] init];
- adWeb.url = model.url;
- [self.navigationController pushViewController:adWeb animated:YES];
- }
- break;
- case 2:
- {
- DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
- list.cate_id = model.Id;
- list.name = model.name;
- list.topRequest = 2;
- [self.navigationController pushViewController:list animated:YES];
- }
- break;
- case 3:
- {
- [self jumpToTaobaoWithUrl:model.url];
- }
- break;
- case 4:
- {
- DRSearchCoupleWebViewController *searchCoupleWeb = [[DRSearchCoupleWebViewController alloc] init];
-
- searchCoupleWeb.url = model.url;
- searchCoupleWeb.jsString = model.ios_js_string;
- searchCoupleWeb.name = model.name;
- if ([[ALBBSession sharedInstance] isLogin]) {
- //进入
- [self.navigationController pushViewController:searchCoupleWeb animated:YES];
- }else{
- //淘宝未授权
- ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
- [albbSDK setAppkey:ALBC_APP_KEY];
- [albbSDK setAuthOption:NormalAuth];
-
- [albbSDK auth:self successCallback:^(ALBBSession *session){
- [[NSNotificationCenter defaultCenter] postNotificationName:ChangeTaoBaoAuthor object:nil];
- [self.navigationController pushViewController:searchCoupleWeb animated:YES];
- } failureCallback:^(ALBBSession *session,NSError *error){
- NSLog(@"session == %@,error == %@",session,error);
- }];
- }
-
-
- }
- break;
-
- case 5:
- {
- DRGoodDetailViewController *detailVC = [[DRGoodDetailViewController alloc] init];
-
- DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithLDMorePicCollectionModels:model];
- detailVC.requestModel = requestModel;
-
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- break;
- default:
- break;
- }
- [MobClick event:Home_Items label:model.name];
- }
- #pragma mark ============ SDCycleScrollViewDelegate ==========
- - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
- DRTodayBannerModel *model = self.bannerList[index];
-
- if (model.url.length > 0) {
- //活动页
- //type为2直接打开淘宝,无需访问中间网页
- if ([model.type isEqualToString:@"2"]) {
- [self jumpToTaobaoWithUrl:model.url];
- }else{
- DRAdWebViewController *adWeb = [[DRAdWebViewController alloc] init];
- adWeb.url = model.url;
- [self.navigationController pushViewController:adWeb animated:YES];
- }
-
-
-
- }else {
- //列表页
- DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
- list.cate_id = model.group_id;
- list.name = model.note;
- list.topRequest = 2;
- [self.navigationController pushViewController:list animated:YES];
-
- }
-
- [MobClick event:home_banner label:model.photo];
- }
- #pragma mark ------- LDTodayModelCollectionCellDelegate -----
- - (void)modelCollectionCellMoreButtonClick:(DRTodayModelCollectionCell *)cell{
-
- DRTodayMudleModel *model = cell.model;
- NSInteger type = model.type.integerValue;
- switch (type) {
- case 1:
- {
- DRBuyLimitMainController *buyLimit = [[DRBuyLimitMainController alloc] init];
- [self.navigationController pushViewController:buyLimit animated:YES];
- }
- break;
- case 2:
- {
- DRRankListViewController *rankList = [[DRRankListViewController alloc] init];
- rankList.name = model.name;
- [self.navigationController pushViewController:rankList animated:YES];
- }
-
- break;
- case 3:
- {
- //列表页
- DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
- list.cate_id = model.Id;
- list.name = model.name;
- list.topRequest = 2; //2为通用列表,1为大额券
- [self.navigationController pushViewController:list animated:YES];
- }
-
- break;
- case 4:
- {
- //列表页
- DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
- list.cate_id = model.Id;
- list.name = model.name;
- list.topRequest = 1;
- [self.navigationController pushViewController:list animated:YES];
- }
-
- break;
- default:
- break;
- }
-
-
- [MobClick event:TodayClickTop label:model.name];
- }
- #pragma mark ============ UICollectionView Delegate && DataSource ==========
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
-
- if (section == 0 ) {
- if (self.superBrandList.count == 0) {
- //没有拿到超级大牌数据
- return 2;
- }
- return 3;
- }else if (section == 1){
- return self.morePicArr.count;
- }else if (section == 2){
- return self.moduleDataArr.count;
- }else if(section == 3){
- return self.goodsArr.count;
- }
- return 0;
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 4;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
-
- if (indexPath.section == 0) {
- //圆形菜单高度
- if (indexPath.row == 0) {
- if (self.morePicCollectionArr==nil||self.morePicCollectionArr.count==0) {
- return CGSizeMake(SCREEN_WIDTH, .1);
- }
- NSInteger offHeight=0;
- if (iPhone5) {
- offHeight=10;
- }
- NSInteger Crow=1;
- NSInteger Coff=-1;
- NSInteger CrowItemSum=5;
- Coff=self.morePicCollectionArr.count%CrowItemSum;
- if (Coff!=0) {
- CrowItemSum=4;
- Coff=self.morePicCollectionArr.count%CrowItemSum;
- if (Coff!=0) {
- CrowItemSum=3;
- Coff=self.morePicCollectionArr.count%CrowItemSum;
- if (Coff!=0) {
- CrowItemSum=5;
- Crow++;
- }
- }
- }
- Crow=self.morePicCollectionArr.count/CrowItemSum;
- if (Coff!=0) {
- Crow++;
- }
- NSInteger totalHeight = (SCREEN_WIDTH/4+offHeight)*Crow;
- return CGSizeMake(SCREEN_WIDTH, totalHeight);
- }
- if (indexPath.row == 1) {
- //猎豆头条高度
- return CGSizeMake(SCREEN_WIDTH, 0);
- }
- if (indexPath.row == 2) {
- //超级大牌高度
- CGFloat height = 200+(SCREEN_WIDTH-10)*60/365;
- return CGSizeMake(SCREEN_WIDTH, height);
- }
-
- }
-
- if (indexPath.section == 1) {
- // if (!self.morePicArr.count||self.morePicArr.count==0) {
- // return CGSizeMake(SCREEN_WIDTH, .1);
- // }
- // CGFloat leftWidth = SCREEN_WIDTH*0.37;
- // CGFloat leftHeight = leftWidth*19/14;
- // return CGSizeMake(SCREEN_WIDTH, leftHeight);
- CGFloat width = (SCREEN_WIDTH-13)/2;
- CGSize size = CGSizeMake(width, width*83/170);
- return size;
- }else if (indexPath.section == 2){
-
- return CGSizeMake(SCREEN_WIDTH, Fitsize(218));
- } else if (indexPath.section == 3) {
- DRTodayGoodModel *model = self.goodsArr[indexPath.row];
- if ([model.type integerValue] == 1) {
- CGFloat width = SCREEN_WIDTH;
- CGFloat height = 147;
- return CGSizeMake(width, height);
- }
- if ([model.type integerValue] == 2) {
- return CGSizeMake(SCREEN_WIDTH, Fitsize(215));
- }
-
- }
- return CGSizeZero;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
- {
- if (section == 0) {
- // CGFloat height = (bannerHeight/375.f)*SCREEN_WIDTH;
- // return CGSizeMake(SCREEN_WIDTH, height);
- return CGSizeMake(SCREEN_WIDTH, SCREEN_WIDTH * bannerScale);
- }else if (section == 1){
- if (_adDataArr.count > 0) {
- return CGSizeMake(SCREEN_WIDTH, ((SCREEN_WIDTH-10)*200/750)+10);
- }
- return CGSizeMake(SCREEN_WIDTH, 0);
- }else if (section == 2){
- return CGSizeMake(SCREEN_WIDTH, 0);
- }
- else {
- return CGSizeMake(SCREEN_WIDTH, FITSIZE(40));
- }
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
- {
- return CGSizeMake(0, 0);
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
- if (section == 1) {
- return UIEdgeInsetsMake(0, 5, 0, 5);
- }else {
- return UIEdgeInsetsMake(0, 0, 0, 0);
- }
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
-
- if (indexPath.section==0) {
- if (indexPath.row == 0) {
- //圆形菜单
- self.morePicCollectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHMorePicCollectionCell forIndexPath:indexPath];
- self.morePicCollectionCell.backgroundColor = [UIColor greenColor];
- self.morePicCollectionCell.delegate = self;
- [self.morePicCollectionCell setModelDatas:self.morePicCollectionArr];
- return self.morePicCollectionCell;
- }
- if (indexPath.row == 1) {
- //滚动新闻
- UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KTodayNewsCell forIndexPath:indexPath];
- // [cell addSubview:self.scrollNewsView];
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
-
- if (indexPath.row == 2) {
- //超级大牌
- UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KSuperBrandCell forIndexPath:indexPath];
- [cell addSubview:self.superBrandView];
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
-
- }
- if (indexPath.section == 1) {
-
- // self.morePicCell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHMorePicCell forIndexPath:indexPath];
- // self.morePicCell.delegate = self;
- // [self.morePicCell setModelDatas:self.morePicArr];
- // return self.morePicCell;
- KBTodayReatCollectionCell *reactCell = [self.collectionView dequeueReusableCellWithReuseIdentifier:KReactCollecionCell forIndexPath:indexPath];
- DRMorePicModel *model = self.morePicArr[indexPath.row];
- reactCell.model = model;
- return reactCell;
-
- }else if (indexPath.section == 2){
- DRTodayModelCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KModelCollecionCell forIndexPath:indexPath];
- cell.delegate = self;
- cell.indexPath = indexPath;
- DRTodayMudleModel *model = self.moduleDataArr[indexPath.row];
- cell.model = model;
- if (indexPath.row == 0) {
- DRCountDownView *countdown = [DRCountDownView shareInstace];
- countdown.y = Fitsize(15);
- countdown.x = Fitsize(132);
- countdown.delegate = self;
- [cell addSubview:countdown];
- cell.desLabel.hidden = YES;
- }else {
- cell.desLabel.hidden = NO;
- }
-
- return cell;
- }
- else if(indexPath.section == 3){
- DRTodayGoodModel *model = self.goodsArr[indexPath.item];
- if ([model.type integerValue] == 1) {
- DRTodayHorizontalGoodCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KYHGoodCollectionCell forIndexPath:indexPath];
- cell.model = model.goods;
- return cell;
- }
- if ([model.type integerValue] == 2) {
- DRTodayGroupCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KTodayGroupCell forIndexPath:indexPath];
- cell.moreClick = ^{
- //列表页
- DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
- list.cate_id = model.Id;
- list.name = model.name;
- list.topRequest = 2;
- [self.navigationController pushViewController:list animated:YES];
- };
- [cell setGoodData:model.goodsList];
- [cell.bgImgView sd_setFadeImageWithURL:[NSURL URLWithString:model.adv_background_img] placeholderImage:nil options:0 progress:nil completed:nil];
- return cell;
- }
-
- }
- return nil;
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
- if (indexPath.section == 0) {
- self.sectionOne = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionOne forIndexPath:indexPath];
- self.sectionOne.backgroundColor = [UIColor clearColor];
- [self.sectionOne addSubview:self.NewPagedFlowView];
- return self.sectionOne;
- }
-
- if (indexPath.section == 1) {
- UICollectionReusableView *sectionTwo = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionTwo forIndexPath:indexPath];
- [sectionTwo addSubview:_adView];
- return sectionTwo;
- }
- if (indexPath.section == 2) {
- UICollectionReusableView *sectionTwo = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionTwo forIndexPath:indexPath];
- return sectionTwo;
- }
-
- if (indexPath.section == 3) {
- self.sectionThree = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionThree forIndexPath:indexPath];
- UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, FITSIZE(40))];
- imageView.image = [UIImage imageNamed:@"section_img"];
- [self.sectionThree addSubview:imageView];
- return self.sectionThree;
- }
-
- return nil;
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
-
- if (section == 0) {
- return 0;
- }
- if (section == 1 || section == 2) {
- return 5;
- }
- if (section == 3) {
- return 10;
- }
- return 0;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
-
-
- if (indexPath.section == 1) {
- DRMorePicModel *model = self.morePicArr[indexPath.row];
- if (model.url.length > 0) {
- //活动页
- //type为2直接打开淘宝,无需访问中间网页
- if ([model.jump_type isEqualToString:@"2"]) {
- [self jumpToTaobaoWithUrl:model.url];
- }else{
- DRAdWebViewController *adWeb = [[DRAdWebViewController alloc] init];
- adWeb.url = model.url;
- [self.navigationController pushViewController:adWeb animated:YES];
- }
- }else {
- //列表页
- DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
- list.cate_id = model.Id;
- list.name = model.name;
- list.topRequest = 2;
- [self.navigationController pushViewController:list animated:YES];
- }
-
- [MobClick event:home_recommend label:model.name];
- }
- if (indexPath.section == 0) {
- if (indexPath.row == 2) {
- FSBaseViewController *faVC= [[FSBaseViewController alloc]init];
- faVC.model = self.model;
- [self.navigationController pushViewController:faVC animated:YES];
- }
- }
-
- if (indexPath.section == 3) {
- DRTodayGoodModel *todayModel = self.goodsArr[indexPath.row];
- if ([todayModel.type integerValue] == 1) {
- DRChildGoodModel *model = todayModel.goods;
- DREventModel *evevtModel = [[DREventModel alloc] initWithOrigin:model.origin category_id:self.model.Id source:homeAction];
-
- DRGoodDetailViewController *detail = [[DRGoodDetailViewController alloc] init];
- detail.eventModel = evevtModel;
- DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
- detail.requestModel = requestModel;
- [self.navigationController pushViewController:detail animated:YES];
-
- [MobClick event:home_hot];
- }
-
- if ([todayModel.type integerValue] == 2) {
- //列表页
- DRGoodListViewController *list = [[DRGoodListViewController alloc] init];
- list.cate_id = todayModel.Id;
- list.name = todayModel.name;
- list.topRequest = 2;
- [self.navigationController pushViewController:list animated:YES];
- }
-
- }
-
- }
- - (UIColor *)todayCollectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout backgroundColorForSection:(NSInteger)section {
- if (section == 0) {
- return [UIColor clearColor];
- }else {
- return [UIColor yhGrayColor];
- }
- }
- #pragma mark ------
- #pragma mark - scrollView
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
- //scrollView已经有拖拽手势,直接拿到scrollView的拖拽手势
- UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer;
- //获取到拖拽的速度 >0 向下拖动 <0 向上拖动
- CGFloat velocity = [pan velocityInView:scrollView].y;
- if (velocity <- 10) {
- //向上拖动,隐藏导航栏
-
- self.collectionView.height = ChildTableViewHeight+NavBarHeight-KStatusBarHeight;
- }else if (velocity > 10) {
- //向下拖动,显示导航栏
-
- self.collectionView.height = ChildTableViewHeight;
- }else if(velocity == 0){
- //停止拖拽
- }
-
- NSNotification *noti = [[NSNotification alloc] initWithName:ScrollDirectorNoti object:nil userInfo:@{@"director":@(velocity)}];
- [[NSNotificationCenter defaultCenter] postNotification:noti];
- }
- #pragma mark ------
- - (void)jumpToTaobaoWithUrl:(NSString *)url {
-
- id<AlibcTradePage> page = [AlibcTradePageFactory page:url];
- //淘客信息
- AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
- taoKeParams.pid= ALTK_PID;
- //打开方式
- AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
-
- showParam.openType = AlibcOpenTypeAuto;
-
-
- [[AlibcTradeSDK sharedInstance].tradeService show:self.parentViewController page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
-
- } tradeProcessFailedCallback:^(NSError * _Nullable error) {
-
- }];
- }
- #pragma mark ===================== layezer ==============
- - (NSArray *)goodsArr {
- if (!_goodsArr) {
- _goodsArr = [NSMutableArray array];
- }
- return _goodsArr;
- }
- - (NSMutableArray *)moduleDataArr {
- if (!_moduleDataArr) {
- _moduleDataArr = [NSMutableArray array];
- }
- return _moduleDataArr;
- }
- - (DRTodayNewsView *)scrollNewsView {
- if (!_scrollNewsView) {
- _scrollNewsView = [[DRTodayNewsView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 47)];
- _scrollNewsView.backgroundColor = [UIColor whiteColor];
- __weak typeof(self) weakSelf = self;
- _scrollNewsView.clickMessage = ^(NSInteger index) {
- DRNewsListViewController *list = [[DRNewsListViewController alloc] init];
- [weakSelf.navigationController pushViewController:list animated:YES];
- };
- }
- return _scrollNewsView;
- }
- - (DRSuperBrandView *)superBrandView {
- if (!_superBrandView) {
- _superBrandView = [[DRSuperBrandView alloc] initWithFrame:CGRectMake(5, 0, SCREEN_WIDTH-10, 200+SCREEN_WIDTH*60/365)];
- _superBrandView.layer.cornerRadius = 6;
- _superBrandView.layer.masksToBounds = YES;
- __weak typeof(self) weakSelf = self;
- _superBrandView.selectedClick = ^(DRSuperBrandModel *model) {
- //点击大牌商品
- DRSearchCoupleWebViewController *searchCoupleWeb = [[DRSearchCoupleWebViewController alloc] init];
-
- searchCoupleWeb.url = model.url;
- searchCoupleWeb.jsString = model.ios_js_string;
- searchCoupleWeb.name = model.name;
- if ([[ALBBSession sharedInstance] isLogin]) {
- //进入
- [weakSelf.navigationController pushViewController:searchCoupleWeb animated:YES];
- }else {
- //淘宝未授权
- ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
- [albbSDK setAppkey:ALBC_APP_KEY];
- [albbSDK setAuthOption:NormalAuth];
-
- [albbSDK auth:weakSelf successCallback:^(ALBBSession *session){
- [[NSNotificationCenter defaultCenter] postNotificationName:ChangeTaoBaoAuthor object:nil];
- [weakSelf.navigationController pushViewController:searchCoupleWeb animated:YES];
- } failureCallback:^(ALBBSession *session,NSError *error){
- NSLog(@"session == %@,error == %@",session,error);
- }];
- }
- };
- _superBrandView.moreClick = ^{
- //点击更多
- FSBaseViewController *faVC= [[FSBaseViewController alloc]init];
- faVC.model=weakSelf.model;
- [weakSelf.navigationController pushViewController:faVC animated:YES];
-
- };
- }
- return _superBrandView;
- }
- @end
|