// // HSQCommunityLeftController.m // YouHuiProject // // Created by 小花 on 2018/5/16. // Copyright © 2018年 kuxuan. All rights reserved. // #import "HSQCommunityRightController.h" #import "HSQCommunityCell.h" #import "UITableView+SDAutoTableViewCellHeight.h" #import "HSQCommunityModel.h" #import "HSQCommunityDetailModel.h" #import "HSQShareGetFriendsModel.h" #import "HSQShareGetFriendsView.h" #import "HSQLoginViewController.h" #import "HSQCommunityRightCell.h" #import "HSQCommunityRightModel.h" #import "HSQGoodDetailViewController.h" #import "shareView.h" #import "HSQShareGoodsTempModel.h" #import "HSQShareGoodsModel.h" #import #import "HSQPopShareGoodView.h" #import "HSQShareManager.h" #import "HYUMShareManager.h" #import "WXApi.h" #import "HSQShareImgPopView.h" #import "CCAlertShowView.h" #import "HSQGoodDetailModel.h" @interface HSQCommunityRightController () < 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)HSQShareGoodsModel *model; @property (nonatomic, strong) HSQPopShareGoodView *shareGoodView; @property (nonatomic, assign) BOOL imgSuccFlag; @property (nonatomic, strong) HSQCommunityRightModel *rightModel; @end @implementation HSQCommunityRightController - (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) }; [HSQHttp post:url params:dic success:^(id json) { if ([self.tableView.mj_header isRefreshing]) { [self.dataArr removeAllObjects]; } NSArray *arr=[NSArray yy_modelArrayWithClass:[HSQCommunityRightModel 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 { HSQCommunityRightModel *model = self.dataArr[indexPath.row]; HSQCommunityRightCell *cell = [HSQCommunityRightCell 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 { HSQCommunityRightModel *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]; HSQGoodDetailViewController *detail = [[HSQGoodDetailViewController alloc] init]; detail.requestModel = requestModel; [self.navigationController pushViewController:detail animated:YES]; [MobClick event:ComunityGoodClick label:@"小编推荐"]; } - (void)showShareView:(HSQCommunityRightModel *)model { self.rightModel = model; HSQGoodDetailModel *detailModel = [[HSQGoodDetailModel alloc] init]; [detailModel changeDetailModelWithComunityRightModel:model]; HSQShareImgPopView *shareView = [[HSQShareImgPopView 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:(HSQCommunityRightModel *)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 // }; // // [HSQHttp post:url params:dic success:^(id json) { // HSQShareGoodsTempModel *tmpModel=[HSQShareGoodsTempModel yy_modelWithJSON:json[@"data"]]; // HSQShareGoodsModel *shreModel = [HSQShareGoodsModel createShareGoodsModelByShareGoodsTempModel:tmpModel]; // shreModel.commissionPrice = model.commission_price;//佣金价格 // shreModel.commission_rate = model.commission_rate; // shreModel.discount_price = model.discount_price; // shreModel.userinfo = tmpModel.userinfo; // // HSQPopShareGoodView *shareGoodView = [[HSQPopShareGoodView 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:(HSQCommunityModel *)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}; // [HSQHttp post:url params:dic success:^(id json) { // NSArray *arr=[NSArray yy_modelArrayWithClass:[HSQCommunityDetailModel 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