123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489 |
- //
- // 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 <SDWebImageDownloader.h>
- #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<max;i++) {
- DRCommunityDetailModel *model=arr[i];
- NSLog(@"model.img--%@",model.img);
- DRShareGoodsModel *goodsModel=[[DRShareGoodsModel alloc]init];
- goodsModel.mainImageUrl=model.img;
- goodsModel.commission_price = model.commission_price;
- if([model.shop_type integerValue]==0){
- goodsModel.shareGoodsFromType=YHShareGoodsFromTypeTaoBao;
- }else if([model.shop_type integerValue]==1){
- goodsModel.shareGoodsFromType=YHShareGoodsFromTypeTianMao;
- }else{
- goodsModel.shareGoodsFromType=YHShareGoodsFromTypeOriginal;
- }
- goodsModel.title=model.title;
- goodsModel.ticketAfterPrice=model.discount_price;
- goodsModel.ticketPrice=model.coupon_price;
- goodsModel.originalPrice=model.price;
- goodsModel.QRcodeImageUrl=model.url;
- if ([model.is_coupon integerValue]==0) {//进入折扣
- goodsModel.shareGoodsPurchaseType=YHShareGoodsPurchaseTypePrice;
- }
-
- DRShareGoodsView *view1=[[DRShareGoodsView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)];
- __weak __typeof(view1) weakView1 = view1;
- view1.imgSuccBlock = ^{
- count++;
- [imgArr addObject: [weakView1 changeToImage]];
- if (count==max) {
- count=0;
- [SVProgressHUD dismiss];
- // self.backgroudView.hidden=YES;
- UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:imgArr applicationActivities:nil];
- [self presentViewController:activityVC animated:YES completion:nil];
- }
- };
- view1.model=goodsModel;
- view1.userInfo = userInfo;
-
-
- }
- }else{
- [SVProgressHUD dismiss];
- [MBProgressHUD showMessage:@"没有商品可以分享"];
-
- }
-
- } failure:^(NSError *error) {
- [SVProgressHUD dismiss];
- [MBProgressHUD showMessage:@"加载失败,请稍后再试"];
- }];
- }else{
- DRLoginViewController *login = [[DRLoginViewController alloc] init];
- login.loginSucc = ^{
-
- [self requestData];
- };
- [self.navigationController presentViewController:login animated:YES completion:nil];
- }
-
-
-
-
-
- }
- #pragma mark ------- layzer ---------
- -(UICollectionView *)collections
- {
- if (!_collections) {
- CGRect collectionViewFrame= CGRectMake(0, FITSIZE(10), [UIScreen mainScreen].bounds.size.width-FITSIZE(20), FITSIZE(182));
-
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
- // 设置UICollectionView为横向滚动
- flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
-
- // 每一行cell之间的间距
- flowLayout.minimumLineSpacing = FITSIZE(10);
- // 每一列cell之间的间距
- // flowLayout.minimumInteritemSpacing = 10;
- // 设置第一个cell和最后一个cell,与父控件之间的间距
- flowLayout.sectionInset = UIEdgeInsetsMake(FITSIZE(40), FITSIZE(10), 0, FITSIZE(10));
- flowLayout.itemSize = CGSizeMake(FITSIZE(106), FITSIZE(140));// 该行代码就算不写,item也会有默认尺寸
- UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:flowLayout];
- collectionView.backgroundColor = [UIColor whiteColor];
- collectionView.dataSource = self;
- collectionView.delegate = self;
- _collections = collectionView;
- _collections.showsVerticalScrollIndicator=NO;
- _collections.showsHorizontalScrollIndicator=NO;
- self.collections.hidden=YES;
- _collections.layer.cornerRadius=5;
- _collections.layer.masksToBounds=YES;
-
- [self.collections registerClass:[DRCommunityShareCell class] forCellWithReuseIdentifier:@"cellId"];
-
-
-
-
- }
- return _collections;
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(FITSIZE(10), 0, SCREEN_WIDTH-FITSIZE(20), ChildTableViewHeight+40) style:UITableViewStyleGrouped];
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.sectionFooterHeight = 0;
- _tableView.sectionHeaderHeight = 0;
- _tableView.estimatedRowHeight = 0;
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.bounces = YES;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.separatorColor = [UIColor lineColor];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- self.page = 1;
- [_tableView.mj_footer resetNoMoreData];
- [self requestData];
- }];
- MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- _page++;
- [self requestData];
- }];
- _tableView.mj_footer = footer;
- [_tableView.mj_header beginRefreshing];
-
-
- }
- return _tableView;
- }
- #pragma mark-添加区头
- -(void)addTableViewHeader
- {
- UIView *bakck =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-FITSIZE(20), FITSIZE(200))];
-
- [bakck addSubview:self.collections];
- UIImageView *imgV =[[UIImageView alloc]initWithFrame:CGRectMake(FITSIZE(10), FITSIZE(20), FITSIZE(20), FITSIZE(20))];
- imgV.image=[UIImage imageNamed:@"paihang"];
- [bakck addSubview:imgV];
- self.collections.hidden=NO;
- UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(40), FITSIZE(10), FITSIZE(85), FITSIZE(40))];
- label.text=@"分享排行榜";
- label.textColor=[UIColor homeRedColor];
- [bakck addSubview:label];
- label.font =[UIFont systemFontOfSize:FITSIZE(15)];
-
- UILabel *tiplabel =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(130), FITSIZE(10), FITSIZE(120), FITSIZE(40))];
- tiplabel.text=@"那些值得分享的好物";
- tiplabel.textColor=[UIColor YHColorWithHex:0x9B9B9B];
- [bakck addSubview:tiplabel];
- tiplabel.font =[UIFont systemFontOfSize:FITSIZE(13)];
-
- self.tableView.tableHeaderView =bakck;
- }
- - (NSMutableArray *)dataArr {
- if (!_dataArr) {
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- -(NSMutableArray *)recommendListArray
- {
- if (!_recommendListArray) {
- _recommendListArray =[NSMutableArray array];
-
- }
- return _recommendListArray;
- }
- //-(UIView *)backgroudView{
- // if (!_backgroudView) {
- // _backgroudView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- // _backgroudView.backgroundColor=[[UIColor grayColor] colorWithAlphaComponent:0.2];
- // _backgroudView.hidden=YES;
- // }
- // return _backgroudView;
- //}
- @end
|