123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491 |
- //
- // KDPTopViewController.m
- // KuDianProject
- //
- // Created by 学丽 on 2019/7/4.
- // Copyright © 2019 KDP. All rights reserved.
- //
- #import "KDPTopViewController.h"
- #define liveEarningCell @"liveEarningCell"
- #define bannerCell @"bannerCell"
- #define recommendCell @"recommendCell"
- #define recommendHead @"recommendHead"
- @interface KDPTopViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
- {
- NSTimer *order_timer;
- NSInteger addNum;
-
- }
- @property(nonatomic,strong)NSMutableArray *dataArray;
- @property(nonatomic,strong)NSArray *bannerArray;
- @property(nonatomic,copy)NSString *orderNumber;
- @property(nonatomic,copy)NSString *order_rebate_money;
- @property(nonatomic,strong)UIButton *headImgBtn;//左侧头像按钮
- @property(nonatomic,strong)UIButton *messageButton;//右侧消息按钮
- @property(nonatomic,strong)UICollectionView *dataCollectionView;
- @property(nonatomic,strong)KDPServiceView *serviceView;
- //服务端传参
- @property(nonatomic,strong)NSString *pageNum;
- @property(nonatomic,strong)NSString *selection_page;
- @property(nonatomic,strong)NSString *selection_id;
- @property(nonatomic,strong)NSString *selection_id_count;
- @property(nonatomic,strong)NSString *selection_id_page;
- @end
- @implementation KDPTopViewController
- -(void)initialieValues
- {
- self.pageNum =@"1";
- self.selection_id=@"0";
- self.selection_id_count=@"0";
- self.selection_id_page=@"0";
- self.selection_page=@"0";
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self initialieValues];
- [self initUI];
-
-
-
- }
- #pragma makr---首页收益
- -(void)getUserTodayIncom
- {
- [KDPNetworkRequestHTTP postURL:topIncomeUrl params:nil success:^(id _Nonnull json) {
-
- //相差的金额,需要减去上次显示的数量
- NSInteger newnum=[json[@"num"] integerValue];
- addNum= newnum-self.orderNumber.integerValue;
-
- self.orderNumber =json[@"num"];//总数量;
- self.order_rebate_money = json[@"total_rebate"];
-
- [self.dataCollectionView reloadData];
- } failure:^(NSError * _Nonnull error) {
- }];
- }
- #pragma makr---首页banner
- -(void)getBanner
- {
- // [LoadingView show];
- [KDPNetworkRequestHTTP getURL:bannerURL params:nil success:^(id _Nonnull json) {
- [LoadingView dismiss];
- self.bannerArray=[NSArray yy_modelArrayWithClass:[KDPBannerModel class] json:json[@"data"]];
- [self.dataCollectionView reloadData];
-
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- }];
- }
- #pragma makr---获取首页数据
- -(void)getRecommendGood
- {
- // [LoadingView show];
-
- NSDictionary *dic=@{@"page":self.pageNum,@"selection_page":self.selection_page,@"selection_id":self.selection_id,@"selection_id_page":self.selection_id_page,@"selection_id_count":self.selection_id_count};
- [KDPNetworkRequestHTTP postURL:topGoodRecommURL params:dic success:^(id _Nonnull json) {
-
- [LoadingView dismiss];
- self.selection_id_page = json[@"selection_id_count"];
- self.selection_id = json[@"selection_id"];
- self.selection_page = json[@"selection_page"];
- self.selection_id_count = json[@"selection_id_count"];
- if (self.pageNum.integerValue == 1) {
- [self.dataArray removeAllObjects];
-
- }
- NSArray *currentA=[NSArray yy_modelArrayWithClass:[KDPGoodsModel class] json:json[@"data"]];
- [self.dataCollectionView.mj_header endRefreshing];
- [self.dataCollectionView.mj_footer endRefreshing];
- if (currentA.count == 0) {
- [self.dataCollectionView.mj_footer endRefreshingWithNoMoreData];
- }
-
- [self.dataArray addObjectsFromArray:currentA];
-
- [self.dataCollectionView reloadData];
-
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- [self.dataCollectionView.mj_header endRefreshing];
- [self.dataCollectionView.mj_footer endRefreshing];
- }];
- }
- -(void)initUI
- {
- self.navBar.navTitleLabel.text=@"酷店";
- [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;
-
-
- [self.navBar addSubview:self.headImgBtn];
- [self.navBar addSubview:self.messageButton];
- [self.headImgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.top.mas_equalTo(KDStatusHeight+4);
- make.height.width.mas_equalTo(32);
- }];
- // UIImageView *imgV=[[UIImageView alloc]init];
- // imgV.image=[UIImage imageNamed:@"LIVE"];
- // [self.navBar addSubview:imgV];
- // [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.left.mas_equalTo(self.headImgBtn.mas_left).offset(5);
- // make.width.mas_equalTo(22);
- // make.height.mas_equalTo(9);
- // make.top.mas_equalTo(self.headImgBtn.mas_bottom).offset(-7);
- // }];
- [self.messageButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(-10);
- make.top.mas_equalTo(KDStatusHeight+10);
- make.width.height.mas_equalTo(22);
- }];
- [_messageButton ba_moveBadgeWithX:22 Y:2];
-
- [self.view addSubview:self.dataCollectionView];
- [self.dataCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.mas_equalTo(0);
- make.top.mas_equalTo(KDNavBarHeight);
- }];
-
-
-
- }
- #pragma mark---collectionDelegate&&DataSource
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == 1) {
- KDPBannerCell *bannerC=[collectionView dequeueReusableCellWithReuseIdentifier:bannerCell forIndexPath:indexPath];
- bannerC.bannerArr = self.bannerArray;
- bannerC.bannerBlock = ^(KDPBannerModel * _Nonnull model) {
- if (model.click_type.integerValue == 1) {//h5
- KDPWebInteractionVC *web=[[KDPWebInteractionVC alloc]init];
- web.url=model.click_param;
- [self.navigationController pushViewController:web animated:YES];
- }else if (model.click_type.integerValue == 2){//商品详情
- KDPGoodDetailVC *goodD=[[KDPGoodDetailVC alloc]init];
- KDPGoodsModel *models=[[KDPGoodsModel alloc]init];
- models.goods_id=model.click_param;
- goodD.model=models;
- [self.navigationController pushViewController:goodD animated:YES];
- }else if (model.click_type.integerValue == 3)
- {//x专题列表
- KDPProjectListVC *listV=[[KDPProjectListVC alloc]init];
- listV.navBar.navTitleLabel.text=model.title;
- listV.projectID=model.click_param;
- if (model.type.length == 0) {
- listV.type = @"module";
- }else{
- listV.type = model.type;
- }
- [self.navigationController pushViewController:listV animated:YES];
- }
- };
- return bannerC;
- }
- if (indexPath.section == 2) {
- KDPRecommendGoodCell *goodC=[collectionView dequeueReusableCellWithReuseIdentifier:recommendCell forIndexPath:indexPath];
- goodC.model=self.dataArray[indexPath.row];
- return goodC;
- }
- KDPLiveEarningCell *earinCell =[collectionView dequeueReusableCellWithReuseIdentifier:liveEarningCell forIndexPath:indexPath];
- if (addNum>0) {
- earinCell.addNumL.text=[NSString stringWithFormat:@"+%ld",addNum];
- }else{
- earinCell.addNumL.text=@"";
- }
- earinCell.orderNumgL.text=self.orderNumber;
- earinCell.rebet_money=self.order_rebate_money;
- return earinCell;
-
- }
- -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- {
- return 3;
- }
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- if (section == 2) {
- return self.dataArray.count;
- }
- if (section == 1&& self.bannerArray.count==1) {
- return 0;
- }
- return 1;
- }
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == 1) {
- if (self.bannerArray.count==0 ) {
- return CGSizeMake(SCREEN_WIDTH, 0.1);
- }
- return CGSizeMake(SCREEN_WIDTH, 113);
- }
- if (indexPath.section == 2) {
- return CGSizeMake(SCREEN_WIDTH, 121);
- }
- return CGSizeMake(SCREEN_WIDTH, 116);
- }
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == 0) {
- KDPTodayLiveDataVC *todayV=[[KDPTodayLiveDataVC alloc]init];
- [self.navigationController pushViewController:todayV animated:YES];
- }
- if (indexPath.section == 2) {
- KDPGoodDetailVC *goodDetail=[[KDPGoodDetailVC alloc]init];
- KDPGoodsModel *models=self.dataArray[indexPath.row];
-
- goodDetail.model=models;
- [self.navigationController pushViewController:goodDetail animated:YES];
- }
- }
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
- {
- if (section == 2) {
- return CGSizeMake(SCREEN_WIDTH, 60);
-
- }
- return CGSizeMake(0, 0 );
- }
- -(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.section == 2) {
- KDPRecommendHeadView *headV=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:recommendHead forIndexPath:indexPath];
- return headV;
- }
-
-
- return nil;
- }
- -(NSMutableArray *)dataArray
- {
- if (!_dataArray) {
- _dataArray=[NSMutableArray array];
- }
- return _dataArray;
- }
- #pragma mark---页面布局
- -(UIButton *)headImgBtn
- {
- if (!_headImgBtn) {
- _headImgBtn=[[UIButton alloc]init];
- _headImgBtn.backgroundColor=[UIColor colorWithHexString:ThemeColor];
- _headImgBtn.layer.cornerRadius=16;
- _headImgBtn.layer.masksToBounds=YES;
- _headImgBtn.layer.borderColor=[UIColor colorWithHexString:@"#FFB444"].CGColor;
-
- UIImageView *imgv=[[UIImageView alloc]initWithFrame:CGRectMake(2, 2, 28, 28)];
- imgv.layer.cornerRadius=14;
- imgv.layer.masksToBounds=YES;
- imgv.image=[UIImage imageNamed:placholderImg];
- imgv.tag=1000;
- [_headImgBtn addSubview:imgv];
-
-
- _headImgBtn.layer.borderWidth=1;
- [_headImgBtn addTarget:self action:@selector(drawerClickButton) forControlEvents:UIControlEventTouchUpInside];
- _headImgBtn.adjustsImageWhenHighlighted=NO;
-
-
-
- }
- return _headImgBtn;
- }
- -(UIButton *)messageButton
- {
- if (!_messageButton) {
- _messageButton=[[UIButton alloc]init];
- [_messageButton setImage:[UIImage imageNamed:@"message_icon"] forState:UIControlStateNormal];
- _messageButton.adjustsImageWhenHighlighted=NO;
- [_messageButton addTarget:self action:@selector(messageclickButton) forControlEvents:UIControlEventTouchUpInside];
- [_messageButton ba_setBadgeLabelAttributes:^(BABadgeLabel *badgeLabel) {
- UILabel *label = (UILabel *)badgeLabel;
- label.width=10;
- label.textColor = [UIColor baseColor];
- label.backgroundColor = [UIColor redColor];
- label.height = label.width;
- label.font = [UIFont systemFontOfSize:8];
- }];
-
- [_messageButton ba_hiddenBadge];
- }
- return _messageButton;
- }
- -(UICollectionView *)dataCollectionView
- {
- if (!_dataCollectionView) {
- UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
- layout.minimumLineSpacing=0;
- layout.minimumInteritemSpacing=0;
- _dataCollectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0, KDNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight-KDTabBarHeight) collectionViewLayout:layout];
- _dataCollectionView.backgroundColor=[UIColor colorWithHexString:LineColor];
- [_dataCollectionView registerClass:[KDPLiveEarningCell class] forCellWithReuseIdentifier:liveEarningCell];
- [_dataCollectionView registerClass:[KDPBannerCell class] forCellWithReuseIdentifier:bannerCell];
- [_dataCollectionView registerClass:[KDPRecommendGoodCell class] forCellWithReuseIdentifier:recommendCell];
- [_dataCollectionView registerClass:[KDPRecommendHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:recommendHead];
- [_dataCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"];
- _dataCollectionView.showsVerticalScrollIndicator=NO;
- _dataCollectionView.delegate=self;
- _dataCollectionView.dataSource=self;
- _dataCollectionView.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [self getBanner];
- [self initialieValues];
- [self getRecommendGood];
- }];
- _dataCollectionView.emptyDataSetDelegate = self;
- _dataCollectionView.emptyDataSetSource = self;
- if (@available(iOS 11.0, *)) {
- _dataCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- } _dataCollectionView.mj_footer=[MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- self.pageNum=[NSString stringWithFormat:@"%ld",self.pageNum.integerValue+1];
- [self getRecommendGood];
- }];
- }
- return _dataCollectionView;
- }
- #pragma mark---侧滑
- -(void)drawerClickButton
- {
- KDPDrawerVC *vcFrame =[[KDPDrawerVC alloc]init];
-
- CWLateralSlideConfiguration *con =[CWLateralSlideConfiguration defaultConfiguration];
- con.distance=SCREEN_WIDTH/3*2;
- [self cw_showDrawerViewController:vcFrame animationType:0 configuration:con];
- }
- #pragma mark---消息中心
- -(void)messageclickButton
- {
- KDPNoticeViewController *noticeV=[[KDPNoticeViewController alloc]init];
- [self.navigationController pushViewController:noticeV animated:YES];
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- self.tabBarController.tabBar.hidden=NO;
- [self updateData];
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
-
- [order_timer invalidate];
- }
- #pragma mark---更新数据
- -(void)updateData
- {
- if ([KDPAccountTool isLogin]) {
- [self getUserTodayIncom];
- [self isOpenService];
- if (self.pageNum.integerValue ==1) {
- [self initialieValues];
- }
- [self getRecommendGood];
- [self getBanner];
- [self messageUnreadNumData];
- order_timer = [NSTimer timerWithTimeInterval:30 target:self selector:@selector(order_timerAction) userInfo:nil repeats:YES];
- [[NSRunLoop mainRunLoop] addTimer:order_timer forMode:NSDefaultRunLoopMode];
- [self setUserHeadImg];
- }
-
- }
- -(void)order_timerAction
- {
- if ([KDPAccountTool isLogin]) {
- [self getUserTodayIncom];
- }
- }
- #pragma mark----设置头像
- -(void)setUserHeadImg
- {
- KDPAccountModel *model=[KDPAccountTool account];
- UIImageView *imgv=[self.headImgBtn viewWithTag:1000];
- [imgv sd_setImageWithURL:[NSURL URLWithString:model.img]placeholderImage:[UIImage imageNamed:placholderImg]];
- }
- #pragma mark---打开服务提示页面
- -(KDPServiceView *)serviceView
- {
- if (!_serviceView) {
- _serviceView=[[KDPServiceView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- __weak KDPTopViewController *weakself=self;
- _serviceView.serviceBlock = ^{
- KDPWebInteractionVC *pidV=[[KDPWebInteractionVC alloc]init];
- pidV.url=custSerURL;
- [weakself cw_pushViewController:pidV];
- [weakself.serviceView removeFromSuperview];
- };
- }
- return _serviceView;
- }
- #pragma mark---获取未读消息个数
- -(void)messageUnreadNumData
- {
- if ([KDPAccountTool isLogin]) {
- [KDPNetworkRequestHTTP postURL:message_numURL params:nil success:^(id _Nonnull json) {
- if ([json[@"data"][@"message_new"] integerValue] == 1) {//是否有新消息 0:无 1:有
- [self.messageButton ba_showBadge];
-
- }else{
- [self.messageButton ba_hiddenBadge];
- }
-
- } failure:^(NSError * _Nonnull error) {
-
- }];
- }
- }
- #pragma mark---判断是否打开客服页面
- -(void)isOpenService
- {
- //存储第一次打开APP,是否显示客服页面,
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- NSString *oneStep =[defaults objectForKey:@"step"];
- if (oneStep.integerValue == 0) {
- [UIView animateWithDuration:0.3 animations:^{
- [[UIApplication sharedApplication].keyWindow addSubview:self.serviceView];
-
- }];
-
- [defaults setValue:@"1" forKey:@"step"];
- [defaults synchronize];
- }
-
- }
- - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
- return [UIImage imageNamed:@"no_order"];
- }
- - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
- return YES;
- }
- - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
- return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
- }
- - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
- return 30;
- }
- @end
|