// // YOUPAILZSessionDetailVC.m // MSYOUPAI // // Created by CY on 2022/3/8. // Copyright © 2022 MS. All rights reserved. // #import "YOUPAILZSessionDetailVC.h" #import "NTESSessionUtil.h" #import "YOUPAIZYSettingCell.h" #import "YOUPAIZYUpdateRemarkWindow.h" #import "UIViewController+TFPresent.h" #import "YOUPAILZSessionUserInfoCell.h" #import "YOUPAILZUserShowVC.h" @interface YOUPAILZSessionDetailVC () @property (nonatomic, weak) UITableView *youpaiptableView; @property (nonatomic, strong) NSArray *youpaipdataSource; @property (nonatomic, assign)NSInteger youpaipis_follow; //是否关注 @property (nonatomic, assign)NSInteger youpaipis_black; //是否拉黑 @property (nonatomic, strong)NSDictionary *youpaipinfo; // @end @implementation YOUPAILZSessionDetailVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"好友设置"; [self youpaifgetData]; } - (void)youpaifinitUI{ UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped]; tableView.dataSource = self; tableView.delegate = self; tableView.estimatedSectionHeaderHeight = 0.0f; tableView.estimatedSectionFooterHeight = 0.0f; tableView.backgroundColor = [UIColor clearColor]; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self.view addSubview:tableView]; self.youpaiptableView = tableView; [tableView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.bottom.right.offset(0.0f); make.top.offset(NavBarHeight); }]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return self.youpaipdataSource.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ NSArray *rows = self.youpaipdataSource[section]; return rows.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ // NSString *cellID = @"GameListCell"; // YOUPAILZGameAccompanyListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; // if (cell == nil) { // cell = [[YOUPAILZGameAccompanyListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; // } // cell.delegate = self; // [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.section]]; NSArray *rows = self.youpaipdataSource[indexPath.section]; NSDictionary *rowModel = rows[indexPath.row]; NSString *cellName = rowModel[@"cellName"]; if ([cellName isEqual:@"YOUPAIZYSettingCell"]) { YOUPAIZYSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName]; if (cell == nil) { cell = [[YOUPAIZYSettingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName]; } NSString *title = rowModel[@"title"]; cell.youpaipheadLabel.text = title; if ([rowModel[@"type"] isEqual:@"Switch"]) { cell.youpaiprightSwitch.hidden = NO; cell.youpaiparrowImgView.hidden = YES; if ([title isEqual:@"置顶聊天"]) { NIMRecentSession *recent = [[NIMSDK sharedSDK].conversationManager recentSessionBySession:self.youpaipsession]; BOOL isTop = [NTESSessionUtil recentSessionIsMark:recent type:NTESRecentSessionMarkTypeTop]; cell.youpaiprightSwitch.selected = isTop; [cell.youpaiprightSwitch addTarget:self action:@selector(youpaiftopBtnClick:) forControlEvents:UIControlEventTouchUpInside]; }else if ([title isEqual:@"加入黑名单"]){ cell.youpaiprightSwitch.selected = self.youpaipis_black; [cell.youpaiprightSwitch addTarget:self action:@selector(youpaifblackBtnClick:) forControlEvents:UIControlEventTouchUpInside]; } }else{ cell.youpaiprightSwitch.hidden = YES; cell.youpaiparrowImgView.hidden = NO; } return cell; }else if ([cellName isEqual:@"YOUPAILZSessionUserInfoCell"]){ YOUPAILZSessionUserInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName]; if (cell == nil) { cell = [[YOUPAILZSessionUserInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName]; } [cell youpaifreloadWithModel:self.youpaipinfo]; return cell; } return [UITableViewCell new]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ NSArray *rows = self.youpaipdataSource[indexPath.section]; NSDictionary *rowModel = rows[indexPath.row]; return [rowModel[@"cellHeight"] floatValue]; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 8.0f; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return CGFLOAT_MIN; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSArray *rows = self.youpaipdataSource[indexPath.section]; NSDictionary *rowModel = rows[indexPath.row]; if([@"设置备注名" isEqual:rowModel[@"title"]]){ if (self.youpaipis_follow == 0) { [ZCHUDHelper showTitle:@"未关注对方不能设置备注名"]; return; } YOUPAIZYUpdateRemarkWindow *VC= [[YOUPAIZYUpdateRemarkWindow alloc]init]; VC.vWidth = KScreenWidth -68; VC.vHeight = ScaleHeight(187)+10; VC.youpaipsession = self.youpaipsession; VC.isTouchDismiss = NO; [self TFPresentVC:VC completion:^{}]; }else if([@"YOUPAILZSessionUserInfoCell" isEqual:rowModel[@"cellName"]]){ // YOUPAILZUserShowVC *userShow = [[YOUPAILZUserShowVC alloc] init]; // userShow.youpaipuserId = self.youpaipsession.sessionId; // [self.navigationController pushViewController:userShow animated:YES]; YMPersonalPageViewModel *personalPageVM = [[YMPersonalPageViewModel alloc]initWithParams:@{ ParamsId:@([self.youpaipsession.sessionId intValue]) }]; [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_PERSONAL_PAGE) withUserInfo:@{ RouterViewModel:personalPageVM } completion:nil]; } } -(void)youpaiftopBtnClick:(UIButton *)sender{ sender.selected = !sender.selected; if (sender.selected) { [NTESSessionUtil addRecentSessionMark:self.youpaipsession type:NTESRecentSessionMarkTypeTop]; }else{ [NTESSessionUtil removeRecentSessionMark:self.youpaipsession type:NTESRecentSessionMarkTypeTop]; } } - (void)youpaifblackBtnClick:(UIButton *)sender{ sender.selected = !sender.selected; [LCCommonHttp blackUserId:self.youpaipsession.sessionId]; } - (void)youpaifgetData{ @weakify(self); [LCHttpHelper requestWithURLString:ChatSetting parameters:@{@"user_id":self.youpaipsession.sessionId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 self.youpaipis_black = [[[dict objectForKey:@"data"]objectForKey:@"is_black"]integerValue]; self.youpaipis_follow = [[[dict objectForKey:@"data"]objectForKey:@"is_follow"]integerValue]; self.youpaipinfo = [[dict objectForKey:@"data"] objectForKey:@"info"]; self.youpaipdataSource = @[ @[@{@"cellName":@"YOUPAILZSessionUserInfoCell",@"cellHeight":@(96.0f),@"model":@""}], @[ @{@"cellName":@"YOUPAIZYSettingCell",@"cellHeight":@(54.0f),@"title":@"置顶聊天",@"type":@"Switch"}, @{@"cellName":@"YOUPAIZYSettingCell",@"cellHeight":@(54.0f),@"title":@"设置备注名",@"type":@"Indicator"} ], @[@{@"cellName":@"YOUPAIZYSettingCell",@"cellHeight":@(54.0f),@"title":@"加入黑名单",@"type":@"Switch"}] ]; [self youpaifinitUI]; } } failure:^(NSError *error) { }]; } @end