123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- //
- // LDCommunityLeftController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/16.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDCommunityRightController.h"
- #import "LDCommunityCell.h"
- #import "UITableView+SDAutoTableViewCellHeight.h"
- #import "LDCommunityModel.h"
- #import "LDCommunityDetailModel.h"
- #import "LDShareGetFriendsModel.h"
- #import "LDShareGetFriendsView.h"
- #import "LDLoginViewController.h"
- #import "LDCommunityRightCell.h"
- #import "LDCommunityRightModel.h"
- #import "shareView.h"
- #import "LDShareGoodsTempModel.h"
- #import "LDShareGoodsModel.h"
- #import <SDWebImageDownloader.h>
- #import "LDPopShareGoodView.h"
- #import "LDShareManager.h"
- #import "HYUMShareManager.h"
- #import "WXApi.h"
- #import "LDShareImgPopView.h"
- #import "CCAlertShowView.h"
- #import "LDGoodDetailModel.h"
- @interface LDCommunityRightController ()
- <
- UITableViewDelegate,
- UITableViewDataSource,
- YHCommunityDelegate
- >
- {
- __block BOOL _imgSuccFlag;
- }
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray *dataArr;
- @property (nonatomic ) NSInteger page;
- @property(nonatomic,strong)UIView *backShareView;
- @property (nonatomic,strong ) UIView *backgroudView;
- @property(nonatomic,strong) shareView *shareView;
- @property(nonatomic,strong)LDShareGoodsModel *model;
- @property (nonatomic, strong) LDPopShareGoodView *shareGoodView;
- @property (nonatomic, assign) BOOL imgSuccFlag;
- @property (nonatomic, strong) LDCommunityRightModel *rightModel;
- @end
- @implementation LDCommunityRightController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.page=1;
- [self configTableView];
- }
- - (void)configTableView {
- self.view.backgroundColor = [UIColor yhGrayColor];
- [self.view addSubview:self.tableView];
-
- [[UIApplication sharedApplication].keyWindow addSubview:self.backgroudView];
- [[UIApplication sharedApplication].keyWindow addSubview:self.backShareView];
- [[UIApplication sharedApplication].keyWindow addSubview:self.shareView];
- }
- - (void)requestData {
- NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/editorRecommendation",BaseURL];
- NSDictionary *dic=@{
- @"page":@(self.page)
- };
- [LDHttp post:url params:dic success:^(id json) {
- if ([self.tableView.mj_header isRefreshing]) {
- [self.dataArr removeAllObjects];
- }
- NSArray *arr=[NSArray yy_modelArrayWithClass:[LDCommunityRightModel class] json:json[@"data"]];
- [self setNoDataView:arr];
- [self.dataArr addObjectsFromArray:arr];
-
- [self.tableView reloadData];
- } failure:^(NSError *error) {
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshing];
- }];
-
- }
- - (void)setNoDataView:(NSArray *)array {
- if (array.count > 0) {
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshing];
- }else {
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- self.tableView.showNoDataView = YES;
- self.tableView.defaultNoDataText = @"暂无数据";
- self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
- }
- #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 heightForHeaderInSection:(NSInteger)section {
- return 0.1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.dataArr.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- LDCommunityRightModel *model = self.dataArr[indexPath.row];
- LDCommunityRightCell *cell = [LDCommunityRightCell cellWithTableView:tableView];
- cell.model = model;
- cell.shareClick = ^{
- // [self loadShareData:model];
- [self showShareView:model];
- };
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- // return [self cellHeightForIndexPath:indexPath cellContentViewWidth:SCREEN_WIDTH tableView:tableView];
- return Fitsize(177);
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- LDCommunityRightModel *model = self.dataArr[indexPath.row];
- DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id is_coupon:model.is_coupon coupon_price:model.coupon_price price:model.price discount_price:model.discount_price commission_rate:model.commission_rate coupon_start_time:model.start_time coupon_end_time:model.end_time coupon_id:model.coupon_id];
- LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
- detail.requestModel = requestModel;
- [self.navigationController pushViewController:detail animated:YES];
-
- [MobClick event:ComunityGoodClick label:@"小编推荐"];
- }
- - (void)showShareView:(LDCommunityRightModel *)model {
- self.rightModel = model;
- LDGoodDetailModel *detailModel = [[LDGoodDetailModel alloc] init];
- [detailModel changeDetailModelWithComunityRightModel:model];
- LDShareImgPopView *shareView = [[LDShareImgPopView 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 shareSuccManager];
- }else {
- [MBProgressHUD showMessage:@"分享失败"];
- }
- };
- showView.backgroundView.backgroundColor = [UIColor clearColor];
- [showView show];
- }
- //- (void)loadShareData:(LDCommunityRightModel *)model {
- //
- // self.rightModel = model;
- //
- // NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/shareCommonGoods",BaseURL];
- // NSString *coupon_start_time = [model.is_coupon boolValue] ? model.start_time : @"";
- // NSString *coupon_end_time = [model.is_coupon boolValue] ? model.end_time : @"";
- // if (!coupon_start_time) coupon_start_time = @"";
- // if (!coupon_end_time) coupon_end_time = @"";
- // NSDictionary *dic=@{
- // @"goods_id":model.goods_id,
- // @"is_coupon":model.is_coupon,
- // @"coupon_price":model.coupon_price,
- // @"price":model.price,
- // @"discount_price":model.discount_price,
- // @"commission_rate":model.commission_rate,
- // @"coupon_end_time":coupon_end_time,
- // @"coupon_start_time":coupon_start_time
- // };
- //
- // [LDHttp post:url params:dic success:^(id json) {
- // LDShareGoodsTempModel *tmpModel=[LDShareGoodsTempModel yy_modelWithJSON:json[@"data"]];
- // LDShareGoodsModel *shreModel = [LDShareGoodsModel createShareGoodsModelByShareGoodsTempModel:tmpModel];
- // shreModel.commissionPrice = model.commission_price;//佣金价格
- // shreModel.commission_rate = model.commission_rate;
- // shreModel.discount_price = model.discount_price;
- // shreModel.userinfo = tmpModel.userinfo;
- //
- // LDPopShareGoodView *shareGoodView = [[LDPopShareGoodView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, Fitsize(254), Fitsize(455))];
- // self.shareGoodView = shareGoodView;
- // shareGoodView.backgroundColor = [UIColor whiteColor];
- // shareGoodView.imgSuccBlock = ^{
- // _imgSuccFlag = YES;
- // };
- // shareGoodView.model = shreModel;
- // [self.view addSubview:shareGoodView];
- //
- // } failure:^(NSError *error) {
- //
- // }];
- //
- // //分享图片
- // self.backShareView.hidden = NO;
- // [UIView animateWithDuration:0.2f animations:^{
- // self.shareView.frame=CGRectMake(0, SCREEN_HEIGHT-200-SafeBottomHeight, SCREEN_WIDTH, 200+SafeBottomHeight);
- // }];
- //
- //}
- #pragma mark -代理 YHCommunityDelegate
- //-(void)oneTouchShareWithModel:(LDCommunityModel *)model{
- //// NSArray *arr=model.detail;
- //// /api/v2/adzoneCreate/secretOneSharing
- // [MobClick event:OneKeyShareCheats label:@"优选素材"];
- // if([AccountTool isLogin]){
- // UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- // pasteboard.string=model.note;
- // NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/secretOneSharing",BaseURL];
- // NSDictionary *dic=@{@"id":model.Id};
- // [LDHttp post:url params:dic success:^(id json) {
- // NSArray *arr=[NSArray yy_modelArrayWithClass:[LDCommunityDetailModel 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;
- // [SVProgressHUD showWithStatus:@"生成分享中"];
- // for (int i=0;i<max;i++) {
- // LDCommunityDetailModel *model=arr[i];
- // LDShareGetFriendsModel *friendModel=[[LDShareGetFriendsModel alloc]init];
- // friendModel.getFriendCode=@"";
- // friendModel.QRcodeUrl=model.url;
- // friendModel.imgUrl=model.img;
- // LDShareGetFriendsView *view1=[[LDShareGetFriendsView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- // view1.model=friendModel;
- // view1.userinfo = userinfo;
- // __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];
- // }
- // };
- //
- // }
- // }else{
- //
- // [SVProgressHUD dismiss];
- // [MBProgressHUD showMessage:@"没有商品可以分享"];
- // }
- // } failure:^(NSError *error) {
- //
- // }];
- //
- //
- //
- //
- // }else{
- // LDLoginViewController *login = [[LDLoginViewController alloc] init];
- // login.loginSucc = ^{
- // self.page=0;
- // [self requestData];
- // };
- // [self.navigationController presentViewController:login animated:YES completion:nil];
- // }
- //}
- - (void)shareSuccManager {
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/shareCount",BaseURL];
- NSDictionary *para = @{@"goods_id":self.rightModel.goods_id};
- [LDHttp post:url params:para success:^(id json) {
- [MBProgressHUD showMessage:@"分享成功"];
- } failure:^(NSError *error) {
-
- }];
- }
- -(void)doTapChange{
- self.backShareView.hidden=YES;
- [UIView animateWithDuration:0.2f animations:^{
- self.shareView.frame=CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 200+SafeBottomHeight);
- } completion:^(BOOL finished) {
- }];
- }
- #pragma mark ------- layzer ---------
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 1, SCREEN_WIDTH, ChildTableViewHeight) 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 backgroudColor];
- _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;
- }
- - (NSMutableArray *)dataArr {
- if (!_dataArr) {
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- -(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;
- }
- -(UIView *)shareView{
- if (!_shareView) {
- _shareView=[[[NSBundle mainBundle] loadNibNamed:@"shareView" owner:self options:nil] lastObject];
- _shareView.frame=CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH,SCREEN_HEIGHT);
- [_shareView.cancelButton addTarget:self action:@selector(doTapChange) forControlEvents:UIControlEventTouchUpInside];
- WeakSelf(weakSelf)
- _shareView.shareToFriend = ^{
-
- if (weakSelf.imgSuccFlag) {
- [weakSelf doTapChange];
- _imgSuccFlag = NO;
- [LDShareManager shareImageWithplatformType:UMSocialPlatformType_WechatSession withImg:[weakSelf.shareGoodView changeToImage] complete:^(id result, NSError *error) {
- if (!error) {
- [weakSelf shareSuccManager];
- }else {
- [MBProgressHUD showMessage:@"分享失败"];
- }
- }];
- }else {
- [MBProgressHUD showMessage:@"海报生成中,请稍后再试"];
- }
- };
- _shareView.shareToSession = ^{
-
- if (weakSelf.imgSuccFlag) {
- [weakSelf doTapChange];
- _imgSuccFlag = NO;
- [LDShareManager shareImageWithplatformType:UMSocialPlatformType_WechatTimeLine withImg:[weakSelf.shareGoodView changeToImage] complete:^(id result, NSError *error) {
- if (!error) {
- [weakSelf shareSuccManager];
- }else {
- [MBProgressHUD showMessage:@"分享失败"];
- }
- }];
- }else {
- [MBProgressHUD showMessage:@"海报生成中,请稍后再试"];
- }
- };
- // _shareView.shareButtonTwoBlock=^(void){
- // __strong typeof(self) strongSelf=weakSelf;
- // [strongSelf doTapChange];
- // };
- // _shareView.shareButtonOneBlock=^(void){
- // __strong typeof(self) strongSelf=weakSelf;
- // [strongSelf doTapChange];
- // };
- }
- return _shareView;
- }
- -(UIView *)backShareView{
- if (!_backShareView) {
- _backShareView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- _backShareView.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.3f];
- _backShareView.hidden=YES;
- UITapGestureRecognizer *r5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doTapChange)];
- r5.numberOfTapsRequired = 1;
- [_backShareView addGestureRecognizer:r5];
- }
- return _backShareView;
- }
- @end
|