FriendController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. //
  2. // FriendController.m
  3. // AIIM
  4. //
  5. // Created by gan on 2025/4/20.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "FriendController.h"
  9. #import "config.h"
  10. #import <SDWebImage/UIImageView+WebCache.h>
  11. #import "ChatController.h"
  12. #import "ChatListStore.h"
  13. #import "UserNetApi.h"
  14. #import "ChatHistoryController.h"
  15. #import "ReportViewController.h"
  16. #import "FriendNetApi.h"
  17. @interface FriendController()<UITableViewDelegate,UITableViewDataSource>
  18. @property (weak, nonatomic) IBOutlet UIImageView *avatar;
  19. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  20. @property (weak, nonatomic) IBOutlet UIButton *gotochatBt;
  21. @property(nonatomic, strong) NSMutableArray *cellDatas;
  22. @property(nonatomic, strong) NSDictionary * noDisturbDict;
  23. @property(nonatomic, assign) BOOL isfriend;
  24. @end
  25. @implementation FriendController
  26. -(void)viewDidLoad{
  27. [super viewDidLoad];
  28. [self.navigationController setNavigationBarHidden:YES animated:NO];
  29. NSLog(@"FriendController:%@",self.friendMsg);
  30. if(self.friendMsg){
  31. _isfriend=YES;
  32. [self initCelldata];
  33. [self getNoDiturbSettingData];
  34. }
  35. else{
  36. _gotochatBt.alpha = 0;
  37. [self getnetFriendMsg];
  38. [self chetRelation];
  39. }
  40. [self initsubView];
  41. }
  42. -(void)initsubView{
  43. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellA"];
  44. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellB"];
  45. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellC"];
  46. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  47. _tableView.backgroundColor = [UIColor clearColor];
  48. _tableView.delegate =self;
  49. _tableView.dataSource = self;
  50. _avatar.layer.cornerRadius = 25.0f;
  51. _gotochatBt.layer.borderWidth = 0.5f;
  52. // _gotochatBt.layer.borderColor = [UIColor lightGrayColor].CGColor; //globalColor(GCTypeGreen);
  53. _gotochatBt.layer.cornerRadius = 8.0f; // 可选,设置圆角
  54. _gotochatBt.backgroundColor=globalColor(GCTypeGreen);
  55. _gotochatBt.tintColor = [UIColor blackColor];
  56. }
  57. -(void)initCelldata{
  58. NSString *stravatar = self.friendMsg[@"avatar"]?:@"";
  59. [_avatar sd_setImageWithURL:[NSURL URLWithString:stravatar] placeholderImage:[UIImage imageNamed:@"Avatar"]];
  60. NSDictionary *d1 =@{
  61. @"name":@"FriendCtr-mingzi",
  62. @"image":@"wgerenxx",
  63. @"detetle":self.friendMsg[@"name"]
  64. };
  65. NSDictionary *d2 =@{
  66. @"name":@"FriendCtr-shuji",
  67. @"image":@"wgerenxx",
  68. @"detetle":self.friendMsg[@"mobile"]?:@""
  69. };
  70. NSDictionary *d3 =@{
  71. @"name":@"FriendCtr-youxiang",
  72. @"image":@"wgerenxx",
  73. @"detetle":self.friendMsg[@"email"]?:@""
  74. };
  75. NSDictionary *d4 =@{
  76. @"name":@"FriendCtr-liaotanjl",
  77. @"image":@"wgerenxx",
  78. };
  79. NSDictionary *d5 =@{
  80. @"name":@"FriendCtr-toushujb",
  81. @"image":@"wgerenxx",
  82. };
  83. NSDictionary *d6 =@{
  84. @"name":@"FriendCtr-jiaruhmd",
  85. @"image":@"wgerenxx",
  86. };
  87. NSDictionary *d7 =@{
  88. @"name":@"FriendCtr-xiaoximdr",
  89. @"image":@"wgerenxx",
  90. };
  91. _cellDatas = [[NSMutableArray alloc] init];
  92. [_cellDatas addObject:d1];
  93. [_cellDatas addObject:d2];
  94. [_cellDatas addObject:d3];
  95. [_cellDatas addObject:d4];
  96. [_cellDatas addObject:d5];
  97. [_cellDatas addObject:d6];
  98. [_cellDatas addObject:d7];
  99. }
  100. -(void)getnetFriendMsg{
  101. [UserNetApi getUserinfo_id:self.friendId succ:^(int code, NSDictionary * res) {
  102. NSLog(@"res:%@",res);
  103. self.friendMsg = res[@"data"];
  104. [self getNoDiturbSettingData];
  105. [self initCelldata];
  106. [self->_tableView reloadData];
  107. } fail:^(NSError * _Nonnull error) {
  108. }];
  109. }
  110. -(void)getNoDiturbSettingData{
  111. [FriendNetApi getNoDisturbSetting:self.friendMsg[@"id"] succ:^(int code, NSDictionary * _Nullable result) {
  112. NSLog(@"noDisturbSetting:-----%@",result);
  113. NSArray * dataArray = result[@"data"];
  114. if (dataArray.count!=0) {
  115. self.noDisturbDict = dataArray[0];
  116. }
  117. [self.tableView reloadData];
  118. } fail:^(NSError * _Nonnull error) {
  119. }];
  120. }
  121. - (void)saveNoDisturbSetting{
  122. NSDictionary * param = @{
  123. @"userId":self.friendMsg[@"id"],
  124. @"chatId":self.friendMsg[@"id"]
  125. };
  126. [FriendNetApi saveNoDisturbSetting:param succ:^(int code, NSDictionary * _Nullable result) {
  127. [MBProgressHUD showWithText:result[@"msg"]];
  128. } fail:^(NSError * _Nonnull error) {
  129. }];
  130. }
  131. - (void)cancelNoDisturbSetting{
  132. [FriendNetApi cancelNoDisturbSettingWithUserId:self.friendMsg[@"id"] chatId:self.friendMsg[@"id"] succ:^(int code, NSDictionary * _Nullable result) {
  133. [MBProgressHUD showWithText:result[@"msg"]];
  134. } fail:^(NSError * _Nonnull error) {
  135. }];
  136. }
  137. - (IBAction)gotoBack:(id)sender {
  138. NSLog(@"gotoBack--------");
  139. [self dismissViewControllerAnimated:YES completion:nil];
  140. }
  141. - (IBAction)gotochatView:(id)sender {
  142. NSDictionary *data=self.self.friendMsg;
  143. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  144. ChatController *chatctr = [board instantiateViewControllerWithIdentifier:@"ChatController"];
  145. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:chatctr];
  146. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  147. chatctr.chatId = data[@"id"];
  148. chatctr.type = 0;
  149. ChatListStore.shareInstance.chatId =data[@"id"];
  150. chatctr.titlename = data[@"name"];
  151. chatctr.avatar = data[@"avatar"];
  152. [self presentViewController :uiNavC animated:YES completion:nil];
  153. }
  154. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  155. NSInteger section =indexPath.section;
  156. NSString *cellT =@"cellC";
  157. if(section==0||section==1||section==2){
  158. cellT =@"cellA";
  159. }
  160. if(section==3||section==4||section==5){
  161. cellT =@"cellB";
  162. }
  163. UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellT forIndexPath:indexPath];
  164. if(cell==nil){
  165. cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellT];
  166. }
  167. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  168. cell.backgroundColor = [UIColor clearColor];
  169. NSDictionary *time =_cellDatas[section];
  170. NSString *title = NSLocalizedString(time[@"name"], @"");
  171. if(section==0||section==1||section==2){
  172. cell.imageView.image = [UIImage imageNamed:time[@"image"]];
  173. cell.textLabel.text =title;
  174. cell.textLabel.textColor = [UIColor whiteColor];
  175. CGRect ctfrm = cell.contentView.frame;
  176. NSString *detetle=time[@"detetle"];
  177. if([detetle isKindOfClass:[NSNull class]]||detetle.length==0){
  178. detetle=NSLocalizedString(@"app-nomsg", @"");
  179. }
  180. UILabel *titleLb = [[UILabel alloc] initWithFrame:CGRectMake(ctfrm.size.width/3-10, 0, ctfrm.size.width/3*2, 52)];
  181. titleLb.text =detetle;
  182. titleLb.textColor = [UIColor whiteColor];
  183. titleLb.textAlignment = NSTextAlignmentRight;
  184. titleLb.font = [UIFont systemFontOfSize:17.0f];
  185. [cell.contentView addSubview:titleLb];
  186. }else if(section==3||section==4||section==5){
  187. cell.imageView.image = [UIImage imageNamed:time[@"image"]];
  188. cell.textLabel.text =title;
  189. cell.textLabel.textColor = [UIColor whiteColor];
  190. UIImageView *right = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow-right"]];
  191. CGRect ctfrm = cell.contentView.frame;
  192. right.frame = CGRectMake(ctfrm.size.width-30, 21, 20, 20);
  193. [cell.contentView addSubview:right];
  194. }else if (section==6){
  195. cell.imageView.image = [UIImage imageNamed:time[@"image"]];
  196. cell.textLabel.text =title;
  197. cell.textLabel.textColor = [UIColor whiteColor];
  198. CGRect ctfrm = cell.contentView.frame;
  199. UISwitch *switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(ctfrm.size.width-66, 10, 20, 10)];
  200. if (self.noDisturbDict && [self.noDisturbDict jk_hasKey:@"id"]) {
  201. [switchButton setOn:YES];
  202. }else{
  203. [switchButton setOn:NO];
  204. }
  205. [switchButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
  206. [cell.contentView addSubview:switchButton];
  207. }
  208. cell.contentView.layer.borderWidth = 0.5f;
  209. cell.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor; //globalColor(GCTypeGreen);
  210. cell.contentView.layer.cornerRadius = 8.0f; // 可选,设置圆角
  211. return cell;
  212. }
  213. - (void)switchAction:(id)sender {
  214. UISwitch *switchButton = (UISwitch*)sender;
  215. BOOL isButtonOn = [switchButton isOn];
  216. if (isButtonOn) {
  217. // 处理开关打开的情况
  218. NSLog(@"isButtonOn");
  219. [self saveNoDisturbSetting];
  220. } else {
  221. // 处理开关关闭的情况
  222. NSLog(@"isButtonOff");
  223. [self cancelNoDisturbSetting];
  224. }
  225. }
  226. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  227. NSLog(@"indexPath:%ld",(long)indexPath.section);
  228. if(indexPath.section==3){
  229. if(!self.isfriend){
  230. [MBProgressHUD showWithText:NSLocalizedString(@"login-agreed", @"")];
  231. return;
  232. }
  233. UIStoryboard *board = [UIStoryboard storyboardWithName:@"ChatHistory" bundle:[NSBundle mainBundle]];
  234. ChatHistoryController *chatctr = [board instantiateViewControllerWithIdentifier:@"ChatHistoryController"];
  235. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:chatctr];
  236. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  237. chatctr.chatId = self.friendMsg[@"id"];
  238. chatctr.type = 0;
  239. chatctr.titlename = self.friendMsg[@"name"];
  240. chatctr.avatar = self.friendMsg[@"avatar"];
  241. [self presentViewController :uiNavC animated:YES completion:nil];
  242. }
  243. if(indexPath.section==4){
  244. ReportViewController *Reportctr = [[ReportViewController alloc] init];
  245. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:Reportctr];
  246. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  247. Reportctr.friendMsg = self.friendMsg;
  248. Reportctr.friendId = self.friendMsg[@"id"];
  249. Reportctr.friendName = self.friendMsg[@"name"];
  250. Reportctr.friendAvatar = self.friendMsg[@"avatar"];
  251. [self presentViewController :uiNavC animated:YES completion:nil];
  252. }
  253. if (indexPath.section == 5) {
  254. //拉黑
  255. NSString *msgnot = [NSString stringWithFormat:@"%@%@",self.friendMsg[@"name"],NSLocalizedString(@"FriendCtr-jiaruhmd", @"")];
  256. UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"FriendCtr-jiaruhmd", @"")
  257. message:msgnot
  258. preferredStyle:UIAlertControllerStyleAlert];
  259. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Common_cancel",@"取消")
  260. style:UIAlertActionStyleCancel
  261. handler:^(UIAlertAction * action) {
  262. // 点击取消后的操作
  263. }];
  264. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Common_confirm", @"确定")
  265. style:UIAlertActionStyleDefault
  266. handler:^(UIAlertAction * action) {
  267. [self AddToBlacklist:self.friendMsg[@"id"]];
  268. // 点击确定后的操作
  269. }];
  270. [alert addAction:cancelAction];
  271. [alert addAction:okAction];
  272. [self presentViewController:alert animated:YES completion:nil];
  273. }
  274. }
  275. -(void)AddToBlacklist:(NSString *)friendId{
  276. [FriendNetApi AddToBlacklistWithId:self.friendMsg[@"id"] succ:^(int code, NSDictionary * _Nullable result) {
  277. [MBProgressHUD showWithText:NSLocalizedString(@"friendCtr-caozuocg", @"")];
  278. } fail:^(NSError * _Nonnull error) {
  279. [MBProgressHUD showWithText:NSLocalizedString(@"AppLock_fail", @"")];
  280. }];
  281. }
  282. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  283. return 1;
  284. }
  285. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  286. return _cellDatas.count;
  287. }
  288. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  289. return 52.0;
  290. }
  291. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  292. CGFloat height =10.0;
  293. // if(section==1||section==3||section==4){
  294. // height =0.0;
  295. // }
  296. return height;
  297. }
  298. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  299. CGFloat height =10.0;
  300. // if(section==1||section==3||section==4){
  301. // height =0.0;
  302. // }
  303. UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, height)];
  304. view.backgroundColor = [UIColor clearColor];
  305. return view;
  306. }
  307. -(void)chetRelation{
  308. [FriendNetApi isfriend:self.friendId succ:^(int code, NSDictionary * res) {
  309. NSLog(@"isfriend:%@",[res[@"data"] class]);
  310. BOOL state = res[@"data"];
  311. if(state){
  312. NSLog(@"isfriend1:");
  313. self.isfriend = true;
  314. }
  315. else{
  316. NSLog(@"isfriend2:");
  317. self.isfriend=false;
  318. self->_gotochatBt.alpha = 0;
  319. }
  320. } fail:^(NSError * _Nonnull error) {
  321. }];
  322. }
  323. @end