// // YOUPAIZYUserDynamicVC.m // VQU // // Created by Elaine on 2020/11/16. // Copyright © 2020 leo. All rights reserved. // #import "YOUPAIZYUserDynamicVC.h" #import "YOUPAILCDynamicCell.h" #import "YOUPAILCReportVC.h" #import "YOUPAILZUserShowVC.h" #import "YOUPAILCGiftSendView.h" @interface YOUPAIZYUserDynamicVC () @property(nonatomic,assign)NSInteger youpaipcurrentPage; @property(nonatomic,assign)NSInteger youpaiptotalPage; @property(nonatomic,strong)NSMutableArray* youpaipdynamicArray; @property(nonatomic,strong)NSMutableArray* youpaipdynamicIdArray; @property (nonatomic,strong) NSMutableDictionary *youpaipheightDict; @end @implementation YOUPAIZYUserDynamicVC - (NSMutableDictionary *)youpaipheightDict{ if (_youpaipheightDict == nil) { _youpaipheightDict = [NSMutableDictionary dictionary]; } return _youpaipheightDict; } - (void)viewDidLoad { [super viewDidLoad]; self.title = @"动态"; self.youpaipdynamicArray = [NSMutableArray array]; self.youpaipdynamicIdArray = [NSMutableArray array]; [self youpaifsetupTableView]; } - (void)youpaifsetupTableView{ CGFloat height = 72+SafeHeight; if([self.youpaipuserId isEqualToString:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]){ height = 0; } // self.tableView.frame = CGRectMake(0,0, KScreenWidth,KScreenHeight-(height+NavBarHeight+48)); // self.tableView.frame = CGRectMake(0,0, KScreenWidth,KScreenHeight-30); self.tableView.showsVerticalScrollIndicator = NO; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.estimatedRowHeight = 100; self.tableView.delegate = self; self.tableView.dataSource= self; self.tableView.backgroundColor = LZFAFAFCColor; self.tableView.estimatedSectionHeaderHeight = 0.0f; self.tableView.estimatedSectionFooterHeight = 0.0f; // self.tableView.contentInset = UIEdgeInsetsMake(NavBarHeight, 0, 0, 0); self.isAllowScroll = YES; [self.view addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.top.mas_equalTo(NavBarHeight); }]; } -(void)setYoupaipuserId:(NSString *)userId { _youpaipuserId = userId; [self youpaifinitData]; } - (void)youpaifinitData{ self.youpaipcurrentPage = 1; [self.tableView.mj_footer endRefreshingWithNoMoreData]; self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)]; [LCHttpHelper requestWithURLString:DynamicUser parameters:@{@"page":@(self.youpaipcurrentPage),@"user_id":self.youpaipuserId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [self.youpaipheightDict removeAllObjects]; [self.youpaipdynamicArray removeAllObjects]; [self.youpaipdynamicIdArray removeAllObjects]; NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"]; NSMutableArray* modelArray = [YOUPAILCDynamicModel mj_objectArrayWithKeyValuesArray:array]; NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray]; for (YOUPAILCDynamicModel* model in modelArray) { if ([self.youpaipdynamicIdArray containsObject:model.youpaipdynamicId]) { [tempArray removeObject:model]; }else{ [self.youpaipdynamicIdArray addObject:model.youpaipdynamicId]; } } [self.youpaipdynamicArray addObjectsFromArray:tempArray]; self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue]; self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue]; [self.tableView reloadData]; if (self.youpaipcurrentPage>=self.youpaiptotalPage) { [self.tableView.mj_footer endRefreshingWithNoMoreData]; self.tableView.mj_footer.hidden = YES; } if (self.youpaipdynamicArray.count != 0) { [self.tableView lz_hideEmptyView]; }else{ [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_dynamic_data"] content:@"暂无发布动态"]; } [self.tableView.mj_header endRefreshing]; } [self.tableView.mj_footer endRefreshing]; } failure:^(NSError *error) { [self.tableView.mj_footer endRefreshing]; }]; } - (void)youpaifloadMoreData{ self.youpaipcurrentPage+=1; [LCHttpHelper requestWithURLString:DynamicUser parameters:@{@"page":@(self.youpaipcurrentPage),@"user_id":self.youpaipuserId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"]; NSMutableArray* modelArray = [YOUPAILCDynamicModel mj_objectArrayWithKeyValuesArray:array]; NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray]; for (YOUPAILCDynamicModel* model in modelArray) { if ([self.youpaipdynamicIdArray containsObject:model.youpaipdynamicId]) { [tempArray removeObject:model]; }else{ [self.youpaipdynamicIdArray addObject:model.youpaipdynamicId]; } } [self.youpaipdynamicArray addObjectsFromArray:tempArray]; self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue]; self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue]; [self.tableView reloadData]; if (self.youpaipcurrentPage>=self.youpaiptotalPage) { [self.tableView.mj_footer endRefreshingWithNoMoreData]; self.tableView.mj_footer.hidden = YES; } [self.tableView.mj_header endRefreshing]; } [self.tableView.mj_footer endRefreshing]; } failure:^(NSError *error) { [self.tableView.mj_footer endRefreshing]; }]; } - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 150; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ CGFloat height; YOUPAILCDynamicModel* model =self.youpaipdynamicArray[indexPath.section]; NSNumber* number =[self.youpaipheightDict objectForKey:model.youpaipdynamicId]; if (number && [number floatValue]>0) { height = [number floatValue]; }else{ height = [YOUPAILCDynamicCell youpaifcellHeightWithModel:self.youpaipdynamicArray[indexPath.section]]; [self.youpaipheightDict setObject:[NSNumber numberWithFloat:(float)height] forKey:model.youpaipdynamicId]; } return height; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return self.youpaipdynamicArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILCDynamicCell* cell = [[YOUPAILCDynamicCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YOUPAILCDynamicCell"]; YOUPAILCDynamicModel* model = self.youpaipdynamicArray[indexPath.section]; cell.youpaipdelegate = self; cell.youpaipcurrentIndex = indexPath.section; cell.youpaipdynamicModel = model; cell.backgroundColor = [UIColor whiteColor]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //动态无响应事件 } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ CGFloat height = 9.0f; return height; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return CGFLOAT_MIN; } - (void)youpaifclickReward:(YOUPAILCDynamicModel*)model{ if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id isEqualToString:model.youpaipuser_id]) { [ZCHUDHelper showTitle:@"不能赠送自己"]; }else{ YOUPAILCGiftSendView* sendView = [[YOUPAILCGiftSendView alloc]initWithModel:nil type:1]; //modify by leo fix bug 20191009 sendView.youpaipalertWindow.hidden = NO; // sendView.alertWindow.rootViewController = self; sendView.youpaipsendMultiGift = ^(NSString *giftId, NSInteger count) { [LCHttpHelper requestWithURLString:DynamicSendGift parameters:@{@"num":@(count),@"dynamic_id":model.youpaipdynamicId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [ZCHUDHelper showTitle:@"赠送成功"]; } } failure:^(NSError *error) { }]; }; [sendView youpaifshow]; } } - (void)youpaifclickAvatar:(YOUPAILCDynamicModel*)model{ // LCUserShowVC* userShow = [[LCUserShowVC alloc]init]; YOUPAILZUserShowVC *userShow = [[YOUPAILZUserShowVC alloc] init]; userShow.youpaipuserId = model.youpaipuser_id; [self.navigationController pushViewController:userShow animated:YES]; } - (void)youpaifclickMoreBtn:(YOUPAILCDynamicModel*)model index:(NSInteger)index{ NSMutableArray* actionArray = [NSMutableArray array]; if ([model.youpaipuser_id isEqualToString:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) { @weakify(self); ZCAlertAction* action = [ZCAlertAction actionWithTitle:@"删除" andblock:^{//删除动态 @strongify(self); [LCHttpHelper requestWithURLString:DynamicDelete parameters:@{@"dynamic_id":model.youpaipdynamicId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [self.youpaipdynamicArray removeObject:model]; [self.youpaipdynamicIdArray removeObject:model.youpaipdynamicId]; [self.tableView reloadData]; // [self.heightDict removeObjectForKey:model.dynamicId]; // NSIndexPath *reloadIndexPath = [NSIndexPath indexPathForRow:index inSection:0]; // [self.tableView deleteRowsAtIndexPaths:@[reloadIndexPath] withRowAnimation:(UITableViewRowAnimationNone)]; } } failure:^(NSError *error) { }]; }]; [actionArray addObject:action]; }else{ // ZCAlertAction* hasFollowAction = [ZCAlertAction actionWithTitle:@"已关注" andblock:^{//关注 // [LCCommonHttp followUserId:model.user_id]; // model.is_follow = 0; // }]; // ZCAlertAction* followAction = [ZCAlertAction actionWithTitle:@"关注" andblock:^{//关注 // [LCCommonHttp followUserId:model.user_id]; // model.is_follow = 1; // }]; @weakify(self); ZCAlertAction* reportAction = [ZCAlertAction actionWithTitle:@"举报" andblock:^{//举报 @strongify(self); YOUPAILCReportVC* report = [[YOUPAILCReportVC alloc]init]; report.youpaipreport_uid = model.youpaipuser_id; report.youpaiptype = 3; [self.navigationController pushViewController:report animated:YES]; }]; // if (model.is_follow == 1) { // [actionArray addObject:hasFollowAction]; // }else{ // [actionArray addObject:followAction]; // } [actionArray addObject:reportAction]; } ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:actionArray]; //modify by leo --fix bug ios13 20191009 //alertSheet.alertWindow.rootViewController = self; alertSheet.alertWindow.hidden = NO; [alertSheet show]; } - (void)youpaifneedUpdateCellHeight:(NSInteger)index cell:(YOUPAILCDynamicCell *)cell{ NSIndexPath *reloadIndexPath = [NSIndexPath indexPathForRow:0 inSection:index]; [self.youpaipheightDict setObject:[NSNumber numberWithFloat:cell.youpaipcellHeight] forKey:cell.youpaipdynamicModel.youpaipdynamicId]; // [self.tableView reloadData]; [self.tableView beginUpdates]; [self.tableView reloadRowsAtIndexPaths:@[reloadIndexPath] withRowAnimation:(UITableViewRowAnimationNone)]; [self.tableView endUpdates]; } #pragma -mark NestedDelegate -(UIScrollView *)youpaifgetNestedScrollView{ return self.tableView; } @end