// // DRCommunityLeftController.m // YouHuiProject // // Created by 小花 on 2018/5/16. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRCommunityLeftController.h" #import "DRCommunityCell.h" #import "UITableView+SDAutoTableViewCellHeight.h" #import "DRCommunityModel.h" #import "DRCommunityDetailModel.h" #import "DRShareGoodsModel.h" #import "DRShareGoodsView.h" #import "DRGoodDetailViewController.h" #import "DRLoginViewController.h" #import "DRPopShareGoodView.h" #import "DRCommunityTopModel.h" #import "DRCommunityShareCell.h" #import "DRGoodDetailModel.h" #import "DRShareImgPopView.h" #import "DRCommunityRightController.h" #import "DRCommunityCell.h" #import "UITableView+SDAutoTableViewCellHeight.h" #import "DRCommunityModel.h" #import "DRCommunityDetailModel.h" #import "DRShareGetFriendsModel.h" #import "DRShareGetFriendsView.h" #import "DRLoginViewController.h" #import "DRCommunityRightCell.h" #import "DRCommunityRightModel.h" #import "DRGoodDetailViewController.h" #import "shareView.h" #import "DRShareGoodsTempModel.h" #import "DRShareGoodsModel.h" #import #import "DRPopShareGoodView.h" #import "DRShareManager.h" #import "HYUMShareManager.h" #import "WXApi.h" #import "DRShareImgPopView.h" #import "CCAlertShowView.h" #import "DRGoodDetailModel.h" #import "DRLinkFansController.h" #import "AccountTool.h" @interface DRCommunityLeftController () < UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UITableViewDelegate, UITableViewDataSource, YHCommunityDelegate, PhotoContainerViewDelegate > { ActivityIndicatorView *_indicatorView; } @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSMutableArray *dataArr;//分享前十 @property(nonatomic,strong)NSMutableArray *recommendListArray;//优选推荐 //@property (nonatomic,strong ) UIView *backgroudView; @property(nonatomic,strong)UICollectionView *collections; @property (nonatomic ) NSInteger page; @end @implementation DRCommunityLeftController - (void)viewDidLoad { [super viewDidLoad]; [self initHUD]; self.page=1; [self configTableView]; } - (void)initHUD { ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; _indicatorView = indicatorView; [_indicatorView startAnimating]; } - (void)configTableView { self.view.backgroundColor = [UIColor backgroudColor]; [self.view addSubview:self.tableView]; // [[UIApplication sharedApplication].keyWindow addSubview:self.backgroudView]; } - (void)requestData { NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/todayHotGoodsList",BaseURL]; NSDictionary *dic=@{ @"page":@(self.page) }; [DRHttp post:url params:dic success:^(id json) { [_indicatorView stopAnimating]; [self.dataArr removeAllObjects]; if ([self.tableView.mj_header isRefreshing]) { [self.recommendListArray removeAllObjects]; } NSArray *arr=[NSArray yy_modelArrayWithClass:[DRCommunityDetailModel class] json:json[@"recommendList"]]; NSArray *dataA =[NSArray yy_modelArrayWithClass:[DRCommunityDetailModel class] json:json[@"top10"]]; [self.dataArr addObjectsFromArray:dataA]; [self.recommendListArray addObjectsFromArray:arr]; if (self.dataArr.count != 0) { [self addTableViewHeader]; [self.collections reloadData]; } [self setNoDataView:arr]; [self.tableView reloadData]; [self.tableView.mj_header endRefreshing]; } failure:^(NSError *error) { [self.tableView.mj_header endRefreshing]; [self.tableView.mj_footer endRefreshing]; [_indicatorView stopAnimating]; }]; } - (void)setNoDataView:(NSArray *)array { self.tableView.showNoDataView = YES; self.tableView.defaultNoDataText = @"暂无数据"; self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"]; if (array.count > 0) { [self.tableView.mj_footer endRefreshing]; }else { [self.tableView.mj_footer endRefreshingWithNoMoreData]; } } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.dataArr.count; } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { DRCommunityShareCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath]; if (!cell ) { cell = [[DRCommunityShareCell alloc] init]; } cell.model=self.dataArr[indexPath.row]; switch (indexPath.row) { case 0: cell.tipeImg.image =[UIImage imageNamed:@"comm_one"]; break; case 1: cell.tipeImg.image =[UIImage imageNamed:@"comm_two"]; break; case 2: cell.tipeImg.image =[UIImage imageNamed:@"comm_three"]; break; default: cell.tipeImg.image =[UIImage imageNamed:@""]; break; } cell.backgroundColor = [UIColor yellowColor]; return cell; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { DRCommunityDetailModel *model=self.dataArr[indexPath.row]; [self otherOPByModel:model isTop:YES]; [MobClick event:FaddishTopItemClick]; } #pragma mark ============ UITableView Delegate && DataSource ========== - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0); } } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return FITSIZE(10); } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.recommendListArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { DRCommunityDetailModel *model = self.recommendListArray[indexPath.section]; DRCommunityCell *cell = [DRCommunityCell cellWithTableView:tableView]; cell.model = model; cell.picContainerView.delegate=self; cell.delegate=self; cell.layer.cornerRadius=5; cell.layer.masksToBounds=YES; cell.shareClick = ^{ if (![AccountTool isLogin]) { DRLoginViewController *login = [[DRLoginViewController alloc] init]; [self presentViewController:login animated:YES completion:nil]; }else{ [self showShareView:model]; } }; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { DRCommunityDetailModel *model=self.recommendListArray[indexPath.section]; if (model.texts.length ==0) { return FITSIZE(155); } return FITSIZE(270); } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { DRCommunityDetailModel *model=self.recommendListArray[indexPath.section]; [self otherOPByModel:model isTop:NO]; [MobClick event:FaddishNormalItemClick]; } #pragma mark -代理 PhotoContainerViewDelegate - (void)otherOPByModel:(DRCommunityDetailModel *)model isTop:(BOOL)isTop{ DREventModel *eventModel; if (isTop) { eventModel = [[DREventModel alloc] initWithOrigin:model.origin category_id:@"0" source:TodayFaddishTopAction]; }else { eventModel = [[DREventModel alloc] initWithOrigin:model.origin category_id:@"0" source:TodayFaddishAction]; } DRGoodDetailViewController *detailVC = [[DRGoodDetailViewController alloc] init]; DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithCommunityDetailModel:model]; detailVC.requestModel = requestModel; detailVC.eventModel = eventModel; [self.navigationController pushViewController:detailVC animated:YES]; [MobClick event:ComunityGoodClick label:@"今日爆款"]; } - (void)showShareView:(DRCommunityDetailModel *)model { DRGoodDetailModel *detailModel = [[DRGoodDetailModel alloc] init]; [detailModel changeDetailModelWithComunityModel:model]; DRShareImgPopView *shareView = [[DRShareImgPopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) goodModel:detailModel]; CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:shareView backgroundDismissEnable:YES]; shareView.closeAction = ^{ [showView dismiss]; }; shareView.shareResult = ^(id result, NSError *error) { if (!error) { [self shareSuccManagerWithModel:model]; }else { [MBProgressHUD showMessage:@"分享失败"]; } }; showView.backgroundView.backgroundColor = [UIColor clearColor]; [showView show]; } - (void)shareSuccManagerWithModel:(DRCommunityDetailModel *)model { NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/shareCount",BaseURL]; NSDictionary *para = @{@"goods_id":model.goods_id}; [DRHttp post:url params:para success:^(id json) { [MBProgressHUD showMessage:@"分享成功"]; } failure:^(NSError *error) { }]; } #pragma mark -代理 YHCommunityDelegate -(void)oneTouchShareWithModel:(DRCommunityModel *)model{ // NSArray *arr=model.detail; [MobClick event:OneKeyShareRecommend label:@"优选商品"]; if([AccountTool isLogin]){ // UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; // pasteboard.string=model.note; NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/oneKeySharing",BaseURL]; NSDictionary *dic=@{@"id":model.Id}; [SVProgressHUD showWithStatus:@"生成分享中"]; [DRHttp post:url params:dic success:^(id json) { NSArray *arr=[NSArray yy_modelArrayWithClass:[DRCommunityDetailModel class] json:json[@"data"]]; NSDictionary *userInfo = json[@"userinfo"]; if (arr.count>0) { __block NSInteger count=0; NSMutableArray *imgArr=[NSMutableArray array]; __block NSInteger max=(arr.count<9?arr.count:9); // self.backgroudView.hidden=NO; for (int i=0;i