// // LZMCommunityLeftController.m // YouHuiProject // // Created by 小花 on 2018/5/16. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LZMCommunityLeftController.h" #import "LZMCommunityCell.h" #import "UITableView+SDAutoTableViewCellHeight.h" #import "LZMCommunityModel.h" #import "LZMCommunityDetailModel.h" #import "LZMShareGoodsModel.h" #import "LZMShareGoodsView.h" #import "LZMGoodDetailViewController.h" #import "LZMLoginViewController.h" #import "LZMPopShareGoodView.h" @interface LZMCommunityLeftController () < UITableViewDelegate, UITableViewDataSource, YHCommunityDelegate, PhotoContainerViewDelegate > @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSMutableArray *dataArr; @property (nonatomic ) NSInteger page; @property (nonatomic,strong ) UIView *backgroudView; @end @implementation LZMCommunityLeftController - (void)viewDidLoad { [super viewDidLoad]; self.page=0; [self configNavigationBar]; [self configTableView]; [self requestData]; } - (void)configNavigationBar{ [self.navigationBar setNavTitle:@"优选商品"]; self.view.backgroundColor = [UIColor whiteColor]; self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; self.navigationBar.backgroundColor = [UIColor baseColor]; self.navigationBar.showNavigationBarBottomLine = YES; } - (void)configTableView { self.view.backgroundColor = [UIColor yhGrayColor]; [self.view addSubview:self.tableView]; [[UIApplication sharedApplication].keyWindow addSubview:self.backgroudView]; } - (void)requestData { NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/dailyRecommendation",BaseURL]; self.page++; NSDictionary *dic=@{ @"page":@(self.page) }; [LZMHttp post:url params:dic success:^(id json) { NSArray *arr=[NSArray yy_modelArrayWithClass:[LZMCommunityModel class] json:json[@"data"]]; if (arr.count>0) { if (self.page==1) { [self.dataArr removeAllObjects]; } [self.dataArr addObjectsFromArray:arr]; } [self setNoDataView:arr]; [self.tableView reloadData]; [self.tableView.mj_header endRefreshing]; } failure:^(NSError *error) { [self.tableView.mj_header endRefreshing]; [self.tableView.mj_footer endRefreshing]; }]; } - (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]; } } #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 { LZMCommunityModel *model = self.dataArr[indexPath.row]; LZMCommunityCell *cell = [LZMCommunityCell cellWithTableView:tableView]; cell.model = model; cell.picContainerView.delegate=self; cell.delegate=self; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { CGFloat a=[self cellHeightForIndexPath:indexPath cellContentViewWidth:SCREEN_WIDTH tableView:tableView]; NSLog(@"---%@--%@",@(indexPath.row),@(a)); return a; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } #pragma mark -代理 PhotoContainerViewDelegate - (void)otherOPByModel:(LZMCommunityDetailModel *)model{ LZMGoodDetailViewController *detailVC = [[LZMGoodDetailViewController alloc] init]; DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithCommunityDetailModel:model]; detailVC.requestModel = requestModel; [self.navigationController pushViewController:detailVC animated:YES]; } #pragma mark -代理 YHCommunityDelegate -(void)oneTouchShareWithModel:(LZMCommunityModel *)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}; [LZMHttp post:url params:dic success:^(id json) { NSArray *arr=[NSArray yy_modelArrayWithClass:[LZMCommunityDetailModel 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