YOUPAILZSessionDetailVC.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //
  2. // YOUPAILZSessionDetailVC.m
  3. // MSYOUPAI
  4. //
  5. // Created by CY on 2022/3/8.
  6. // Copyright © 2022 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZSessionDetailVC.h"
  9. #import "NTESSessionUtil.h"
  10. #import "YOUPAIZYSettingCell.h"
  11. #import "YOUPAIZYUpdateRemarkWindow.h"
  12. #import "UIViewController+TFPresent.h"
  13. #import "YOUPAILZSessionUserInfoCell.h"
  14. #import "YOUPAILZUserShowVC.h"
  15. @interface YOUPAILZSessionDetailVC ()<UITableViewDelegate,UITableViewDataSource>
  16. @property (nonatomic, weak) UITableView *youpaiptableView;
  17. @property (nonatomic, strong) NSArray *youpaipdataSource;
  18. @property (nonatomic, assign)NSInteger youpaipis_follow; //是否关注
  19. @property (nonatomic, assign)NSInteger youpaipis_black; //是否拉黑
  20. @property (nonatomic, strong)NSDictionary *youpaipinfo; //
  21. @end
  22. @implementation YOUPAILZSessionDetailVC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.title = @"好友设置";
  26. [self youpaifgetData];
  27. }
  28. - (void)youpaifinitUI{
  29. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  30. tableView.dataSource = self;
  31. tableView.delegate = self;
  32. tableView.estimatedSectionHeaderHeight = 0.0f;
  33. tableView.estimatedSectionFooterHeight = 0.0f;
  34. tableView.backgroundColor = [UIColor clearColor];
  35. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  36. [self.view addSubview:tableView];
  37. self.youpaiptableView = tableView;
  38. [tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  39. make.left.bottom.right.offset(0.0f);
  40. make.top.offset(NavBarHeight);
  41. }];
  42. }
  43. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  44. return self.youpaipdataSource.count;
  45. }
  46. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  47. NSArray *rows = self.youpaipdataSource[section];
  48. return rows.count;
  49. }
  50. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  51. // NSString *cellID = @"GameListCell";
  52. // YOUPAILZGameAccompanyListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  53. // if (cell == nil) {
  54. // cell = [[YOUPAILZGameAccompanyListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  55. // }
  56. // cell.delegate = self;
  57. // [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.section]];
  58. NSArray *rows = self.youpaipdataSource[indexPath.section];
  59. NSDictionary *rowModel = rows[indexPath.row];
  60. NSString *cellName = rowModel[@"cellName"];
  61. if ([cellName isEqual:@"YOUPAIZYSettingCell"]) {
  62. YOUPAIZYSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  63. if (cell == nil) {
  64. cell = [[YOUPAIZYSettingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
  65. }
  66. NSString *title = rowModel[@"title"];
  67. cell.youpaipheadLabel.text = title;
  68. if ([rowModel[@"type"] isEqual:@"Switch"]) {
  69. cell.youpaiprightSwitch.hidden = NO;
  70. cell.youpaiparrowImgView.hidden = YES;
  71. if ([title isEqual:@"置顶聊天"]) {
  72. NIMRecentSession *recent = [[NIMSDK sharedSDK].conversationManager recentSessionBySession:self.youpaipsession];
  73. BOOL isTop = [NTESSessionUtil recentSessionIsMark:recent type:NTESRecentSessionMarkTypeTop];
  74. cell.youpaiprightSwitch.selected = isTop;
  75. [cell.youpaiprightSwitch addTarget:self action:@selector(youpaiftopBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  76. }else if ([title isEqual:@"加入黑名单"]){
  77. cell.youpaiprightSwitch.selected = self.youpaipis_black;
  78. [cell.youpaiprightSwitch addTarget:self action:@selector(youpaifblackBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  79. }
  80. }else{
  81. cell.youpaiprightSwitch.hidden = YES;
  82. cell.youpaiparrowImgView.hidden = NO;
  83. }
  84. return cell;
  85. }else if ([cellName isEqual:@"YOUPAILZSessionUserInfoCell"]){
  86. YOUPAILZSessionUserInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  87. if (cell == nil) {
  88. cell = [[YOUPAILZSessionUserInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
  89. }
  90. [cell youpaifreloadWithModel:self.youpaipinfo];
  91. return cell;
  92. }
  93. return [UITableViewCell new];
  94. }
  95. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  96. NSArray *rows = self.youpaipdataSource[indexPath.section];
  97. NSDictionary *rowModel = rows[indexPath.row];
  98. return [rowModel[@"cellHeight"] floatValue];
  99. }
  100. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  101. return 8.0f;
  102. }
  103. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  104. return CGFLOAT_MIN;
  105. }
  106. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  107. NSArray *rows = self.youpaipdataSource[indexPath.section];
  108. NSDictionary *rowModel = rows[indexPath.row];
  109. if([@"设置备注名" isEqual:rowModel[@"title"]]){
  110. if (self.youpaipis_follow == 0) {
  111. [ZCHUDHelper showTitle:@"未关注对方不能设置备注名"];
  112. return;
  113. }
  114. YOUPAIZYUpdateRemarkWindow *VC= [[YOUPAIZYUpdateRemarkWindow alloc]init];
  115. VC.vWidth = KScreenWidth -68;
  116. VC.vHeight = ScaleHeight(187)+10;
  117. VC.youpaipsession = self.youpaipsession;
  118. VC.isTouchDismiss = NO;
  119. [self TFPresentVC:VC completion:^{}];
  120. }else if([@"YOUPAILZSessionUserInfoCell" isEqual:rowModel[@"cellName"]]){
  121. // YOUPAILZUserShowVC *userShow = [[YOUPAILZUserShowVC alloc] init];
  122. // userShow.youpaipuserId = self.youpaipsession.sessionId;
  123. // [self.navigationController pushViewController:userShow animated:YES];
  124. YMPersonalPageViewModel *personalPageVM = [[YMPersonalPageViewModel alloc]initWithParams:@{
  125. ParamsId:@([self.youpaipsession.sessionId intValue])
  126. }];
  127. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_PERSONAL_PAGE) withUserInfo:@{
  128. RouterViewModel:personalPageVM
  129. } completion:nil];
  130. }
  131. }
  132. -(void)youpaiftopBtnClick:(UIButton *)sender{
  133. sender.selected = !sender.selected;
  134. if (sender.selected) {
  135. [NTESSessionUtil addRecentSessionMark:self.youpaipsession type:NTESRecentSessionMarkTypeTop];
  136. }else{
  137. [NTESSessionUtil removeRecentSessionMark:self.youpaipsession type:NTESRecentSessionMarkTypeTop];
  138. }
  139. }
  140. - (void)youpaifblackBtnClick:(UIButton *)sender{
  141. sender.selected = !sender.selected;
  142. [LCCommonHttp blackUserId:self.youpaipsession.sessionId];
  143. }
  144. - (void)youpaifgetData{
  145. @weakify(self);
  146. [LCHttpHelper requestWithURLString:ChatSetting parameters:@{@"user_id":self.youpaipsession.sessionId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  147. @strongify(self);
  148. NSDictionary* dict = (NSDictionary*)responseObject;
  149. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  150. if (code==0) {//成功
  151. self.youpaipis_black = [[[dict objectForKey:@"data"]objectForKey:@"is_black"]integerValue];
  152. self.youpaipis_follow = [[[dict objectForKey:@"data"]objectForKey:@"is_follow"]integerValue];
  153. self.youpaipinfo = [[dict objectForKey:@"data"] objectForKey:@"info"];
  154. self.youpaipdataSource = @[
  155. @[@{@"cellName":@"YOUPAILZSessionUserInfoCell",@"cellHeight":@(96.0f),@"model":@""}],
  156. @[
  157. @{@"cellName":@"YOUPAIZYSettingCell",@"cellHeight":@(54.0f),@"title":@"置顶聊天",@"type":@"Switch"},
  158. @{@"cellName":@"YOUPAIZYSettingCell",@"cellHeight":@(54.0f),@"title":@"设置备注名",@"type":@"Indicator"}
  159. ],
  160. @[@{@"cellName":@"YOUPAIZYSettingCell",@"cellHeight":@(54.0f),@"title":@"加入黑名单",@"type":@"Switch"}]
  161. ];
  162. [self youpaifinitUI];
  163. }
  164. } failure:^(NSError *error) {
  165. }];
  166. }
  167. @end