YOUPAIZYUserDynamicVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. //
  2. // YOUPAIZYUserDynamicVC.m
  3. // VQU
  4. //
  5. // Created by Elaine on 2020/11/16.
  6. // Copyright © 2020 leo. All rights reserved.
  7. //
  8. #import "YOUPAIZYUserDynamicVC.h"
  9. #import "YOUPAILCDynamicCell.h"
  10. #import "YOUPAILCReportVC.h"
  11. #import "YOUPAILZUserShowVC.h"
  12. #import "YOUPAILCGiftSendView.h"
  13. @interface YOUPAIZYUserDynamicVC ()<UITableViewDelegate,UITableViewDataSource,LCDynamicCellDelegate>
  14. @property(nonatomic,assign)NSInteger youpaipcurrentPage;
  15. @property(nonatomic,assign)NSInteger youpaiptotalPage;
  16. @property(nonatomic,strong)NSMutableArray* youpaipdynamicArray;
  17. @property(nonatomic,strong)NSMutableArray* youpaipdynamicIdArray;
  18. @property (nonatomic,strong) NSMutableDictionary *youpaipheightDict;
  19. @end
  20. @implementation YOUPAIZYUserDynamicVC
  21. - (NSMutableDictionary *)youpaipheightDict{
  22. if (_youpaipheightDict == nil) {
  23. _youpaipheightDict = [NSMutableDictionary dictionary];
  24. }
  25. return _youpaipheightDict;
  26. }
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. self.title = @"动态";
  30. self.youpaipdynamicArray = [NSMutableArray array];
  31. self.youpaipdynamicIdArray = [NSMutableArray array];
  32. [self youpaifsetupTableView];
  33. }
  34. - (void)youpaifsetupTableView{
  35. CGFloat height = 72+SafeHeight;
  36. if([self.youpaipuserId isEqualToString:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]){
  37. height = 0;
  38. }
  39. // self.tableView.frame = CGRectMake(0,0, KScreenWidth,KScreenHeight-(height+NavBarHeight+48));
  40. // self.tableView.frame = CGRectMake(0,0, KScreenWidth,KScreenHeight-30);
  41. self.tableView.showsVerticalScrollIndicator = NO;
  42. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  43. self.tableView.estimatedRowHeight = 100;
  44. self.tableView.delegate = self;
  45. self.tableView.dataSource= self;
  46. self.tableView.backgroundColor = LZFAFAFCColor;
  47. self.tableView.estimatedSectionHeaderHeight = 0.0f;
  48. self.tableView.estimatedSectionFooterHeight = 0.0f;
  49. // self.tableView.contentInset = UIEdgeInsetsMake(NavBarHeight, 0, 0, 0);
  50. self.isAllowScroll = YES;
  51. [self.view addSubview:self.tableView];
  52. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.mas_equalTo(0);
  54. make.right.mas_equalTo(0);
  55. make.bottom.mas_equalTo(0);
  56. make.top.mas_equalTo(NavBarHeight);
  57. }];
  58. }
  59. -(void)setYoupaipuserId:(NSString *)userId
  60. {
  61. _youpaipuserId = userId;
  62. [self youpaifinitData];
  63. }
  64. - (void)youpaifinitData{
  65. self.youpaipcurrentPage = 1;
  66. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  67. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)];
  68. [LCHttpHelper requestWithURLString:DynamicUser parameters:@{@"page":@(self.youpaipcurrentPage),@"user_id":self.youpaipuserId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  69. NSDictionary* dict = (NSDictionary*)responseObject;
  70. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  71. if (code==0) {//成功
  72. [self.youpaipheightDict removeAllObjects];
  73. [self.youpaipdynamicArray removeAllObjects];
  74. [self.youpaipdynamicIdArray removeAllObjects];
  75. NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"];
  76. NSMutableArray* modelArray = [YOUPAILCDynamicModel mj_objectArrayWithKeyValuesArray:array];
  77. NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray];
  78. for (YOUPAILCDynamicModel* model in modelArray) {
  79. if ([self.youpaipdynamicIdArray containsObject:model.youpaipdynamicId]) {
  80. [tempArray removeObject:model];
  81. }else{
  82. [self.youpaipdynamicIdArray addObject:model.youpaipdynamicId];
  83. }
  84. }
  85. [self.youpaipdynamicArray addObjectsFromArray:tempArray];
  86. self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue];
  87. self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue];
  88. [self.tableView reloadData];
  89. if (self.youpaipcurrentPage>=self.youpaiptotalPage) {
  90. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  91. self.tableView.mj_footer.hidden = YES;
  92. }
  93. if (self.youpaipdynamicArray.count != 0) {
  94. [self.tableView lz_hideEmptyView];
  95. }else{
  96. [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_dynamic_data"] content:@"暂无发布动态"];
  97. }
  98. [self.tableView.mj_header endRefreshing];
  99. }
  100. [self.tableView.mj_footer endRefreshing];
  101. } failure:^(NSError *error) {
  102. [self.tableView.mj_footer endRefreshing];
  103. }];
  104. }
  105. - (void)youpaifloadMoreData{
  106. self.youpaipcurrentPage+=1;
  107. [LCHttpHelper requestWithURLString:DynamicUser parameters:@{@"page":@(self.youpaipcurrentPage),@"user_id":self.youpaipuserId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  108. NSDictionary* dict = (NSDictionary*)responseObject;
  109. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  110. if (code==0) {//成功
  111. NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"];
  112. NSMutableArray* modelArray = [YOUPAILCDynamicModel mj_objectArrayWithKeyValuesArray:array];
  113. NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray];
  114. for (YOUPAILCDynamicModel* model in modelArray) {
  115. if ([self.youpaipdynamicIdArray containsObject:model.youpaipdynamicId]) {
  116. [tempArray removeObject:model];
  117. }else{
  118. [self.youpaipdynamicIdArray addObject:model.youpaipdynamicId];
  119. }
  120. }
  121. [self.youpaipdynamicArray addObjectsFromArray:tempArray];
  122. self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue];
  123. self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue];
  124. [self.tableView reloadData];
  125. if (self.youpaipcurrentPage>=self.youpaiptotalPage) {
  126. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  127. self.tableView.mj_footer.hidden = YES;
  128. }
  129. [self.tableView.mj_header endRefreshing];
  130. }
  131. [self.tableView.mj_footer endRefreshing];
  132. } failure:^(NSError *error) {
  133. [self.tableView.mj_footer endRefreshing];
  134. }];
  135. }
  136. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
  137. return 150;
  138. }
  139. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  140. CGFloat height;
  141. YOUPAILCDynamicModel* model =self.youpaipdynamicArray[indexPath.section];
  142. NSNumber* number =[self.youpaipheightDict objectForKey:model.youpaipdynamicId];
  143. if (number && [number floatValue]>0) {
  144. height = [number floatValue];
  145. }else{
  146. height = [YOUPAILCDynamicCell youpaifcellHeightWithModel:self.youpaipdynamicArray[indexPath.section]];
  147. [self.youpaipheightDict setObject:[NSNumber numberWithFloat:(float)height] forKey:model.youpaipdynamicId];
  148. }
  149. return height;
  150. }
  151. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  152. return 1;
  153. }
  154. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  155. return self.youpaipdynamicArray.count;
  156. }
  157. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  158. YOUPAILCDynamicCell* cell = [[YOUPAILCDynamicCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YOUPAILCDynamicCell"];
  159. YOUPAILCDynamicModel* model = self.youpaipdynamicArray[indexPath.section];
  160. cell.youpaipdelegate = self;
  161. cell.youpaipcurrentIndex = indexPath.section;
  162. cell.youpaipdynamicModel = model;
  163. cell.backgroundColor = [UIColor whiteColor];
  164. return cell;
  165. }
  166. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  167. //动态无响应事件
  168. }
  169. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  170. CGFloat height = 9.0f;
  171. return height;
  172. }
  173. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  174. return CGFLOAT_MIN;
  175. }
  176. - (void)youpaifclickReward:(YOUPAILCDynamicModel*)model{
  177. if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id isEqualToString:model.youpaipuser_id]) {
  178. [ZCHUDHelper showTitle:@"不能赠送自己"];
  179. }else{
  180. YOUPAILCGiftSendView* sendView = [[YOUPAILCGiftSendView alloc]initWithModel:nil type:1];
  181. //modify by leo fix bug 20191009
  182. sendView.youpaipalertWindow.hidden = NO;
  183. // sendView.alertWindow.rootViewController = self;
  184. sendView.youpaipsendMultiGift = ^(NSString *giftId, NSInteger count) {
  185. [LCHttpHelper requestWithURLString:DynamicSendGift parameters:@{@"num":@(count),@"dynamic_id":model.youpaipdynamicId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  186. NSDictionary* dict = (NSDictionary*)responseObject;
  187. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  188. if (code==0) {//成功
  189. [ZCHUDHelper showTitle:@"赠送成功"];
  190. }
  191. } failure:^(NSError *error) {
  192. }];
  193. };
  194. [sendView youpaifshow];
  195. }
  196. }
  197. - (void)youpaifclickAvatar:(YOUPAILCDynamicModel*)model{
  198. // LCUserShowVC* userShow = [[LCUserShowVC alloc]init];
  199. YOUPAILZUserShowVC *userShow = [[YOUPAILZUserShowVC alloc] init];
  200. userShow.youpaipuserId = model.youpaipuser_id;
  201. [self.navigationController pushViewController:userShow animated:YES];
  202. }
  203. - (void)youpaifclickMoreBtn:(YOUPAILCDynamicModel*)model index:(NSInteger)index{
  204. NSMutableArray* actionArray = [NSMutableArray array];
  205. if ([model.youpaipuser_id isEqualToString:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  206. @weakify(self);
  207. ZCAlertAction* action = [ZCAlertAction actionWithTitle:@"删除" andblock:^{//删除动态
  208. @strongify(self);
  209. [LCHttpHelper requestWithURLString:DynamicDelete parameters:@{@"dynamic_id":model.youpaipdynamicId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  210. NSDictionary* dict = (NSDictionary*)responseObject;
  211. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  212. if (code==0) {//成功
  213. [self.youpaipdynamicArray removeObject:model];
  214. [self.youpaipdynamicIdArray removeObject:model.youpaipdynamicId];
  215. [self.tableView reloadData];
  216. // [self.heightDict removeObjectForKey:model.dynamicId];
  217. // NSIndexPath *reloadIndexPath = [NSIndexPath indexPathForRow:index inSection:0];
  218. // [self.tableView deleteRowsAtIndexPaths:@[reloadIndexPath] withRowAnimation:(UITableViewRowAnimationNone)];
  219. }
  220. } failure:^(NSError *error) {
  221. }];
  222. }];
  223. [actionArray addObject:action];
  224. }else{
  225. // ZCAlertAction* hasFollowAction = [ZCAlertAction actionWithTitle:@"已关注" andblock:^{//关注
  226. // [LCCommonHttp followUserId:model.user_id];
  227. // model.is_follow = 0;
  228. // }];
  229. // ZCAlertAction* followAction = [ZCAlertAction actionWithTitle:@"关注" andblock:^{//关注
  230. // [LCCommonHttp followUserId:model.user_id];
  231. // model.is_follow = 1;
  232. // }];
  233. @weakify(self);
  234. ZCAlertAction* reportAction = [ZCAlertAction actionWithTitle:@"举报" andblock:^{//举报
  235. @strongify(self);
  236. YOUPAILCReportVC* report = [[YOUPAILCReportVC alloc]init];
  237. report.youpaipreport_uid = model.youpaipuser_id;
  238. report.youpaiptype = 3;
  239. [self.navigationController pushViewController:report animated:YES];
  240. }];
  241. // if (model.is_follow == 1) {
  242. // [actionArray addObject:hasFollowAction];
  243. // }else{
  244. // [actionArray addObject:followAction];
  245. // }
  246. [actionArray addObject:reportAction];
  247. }
  248. ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:actionArray];
  249. //modify by leo --fix bug ios13 20191009
  250. //alertSheet.alertWindow.rootViewController = self;
  251. alertSheet.alertWindow.hidden = NO;
  252. [alertSheet show];
  253. }
  254. - (void)youpaifneedUpdateCellHeight:(NSInteger)index cell:(YOUPAILCDynamicCell *)cell{
  255. NSIndexPath *reloadIndexPath = [NSIndexPath indexPathForRow:0 inSection:index];
  256. [self.youpaipheightDict setObject:[NSNumber numberWithFloat:cell.youpaipcellHeight] forKey:cell.youpaipdynamicModel.youpaipdynamicId];
  257. // [self.tableView reloadData];
  258. [self.tableView beginUpdates];
  259. [self.tableView reloadRowsAtIndexPaths:@[reloadIndexPath] withRowAnimation:(UITableViewRowAnimationNone)];
  260. [self.tableView endUpdates];
  261. }
  262. #pragma -mark NestedDelegate
  263. -(UIScrollView *)youpaifgetNestedScrollView{
  264. return self.tableView;
  265. }
  266. @end