EXFriendListCell.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // EXFriendListCell.m
  3. // AIIM
  4. //
  5. // Created by gan on 2025/4/6.
  6. //
  7. #import "EXFriendListCell.h"
  8. #import <SDWebImage/UIImageView+WebCache.h>
  9. #import "config.h"
  10. #import "FriendNetApi.h"
  11. @interface EXFriendListCell()
  12. @property (strong, nonatomic) UIButton *agreetBt;
  13. @property (strong, nonatomic) UIButton *rejectBt;
  14. @property (strong, nonatomic) NSDictionary *dataDic;
  15. @end
  16. @implementation EXFriendListCell
  17. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  18. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  19. if (self) {
  20. [self setupViews];
  21. }
  22. return self;
  23. }
  24. - (void)setupViews {
  25. CGSize bsize = self.contentView.frame.size;
  26. _avatar =[[UIImageView alloc] init];
  27. _avatar.frame=CGRectMake(8, 10, 50, 50);
  28. _avatar.contentMode = UIViewContentModeScaleAspectFill;
  29. _avatar.layer.cornerRadius = 25;
  30. _avatar.layer.masksToBounds = YES;
  31. _avatar.backgroundColor=[UIColor lightGrayColor];
  32. [self.contentView addSubview:_avatar];
  33. _name = [[UILabel alloc] init];
  34. _name.frame=CGRectMake(68, 10, 150, 50);
  35. _name.backgroundColor=[UIColor clearColor];
  36. _name.numberOfLines = 2;
  37. [_name setFont:[UIFont boldSystemFontOfSize:18]];
  38. [_name setTextColor:[UIColor whiteColor]];
  39. [self.contentView addSubview:_name];
  40. _agreetBt =[[UIButton alloc] init];
  41. _agreetBt.layer.backgroundColor =globalColor(GCTypeGreend).CGColor;
  42. _agreetBt.layer.cornerRadius = 8.0f;
  43. _agreetBt.frame=CGRectMake(bsize.width-94, 17, 60, 36);
  44. [_agreetBt setTitle:@"同意" forState:UIControlStateNormal];
  45. [_agreetBt.titleLabel setFont:[UIFont systemFontOfSize:16.0f]];
  46. [_agreetBt addTarget:nil action:@selector(agreetex) forControlEvents:UIControlEventTouchUpInside];
  47. [self.contentView addSubview:_agreetBt];
  48. _rejectBt =[[UIButton alloc] init];
  49. _rejectBt.layer.backgroundColor =[UIColor lightGrayColor].CGColor;
  50. _rejectBt.layer.cornerRadius = 8.0f;
  51. _rejectBt.frame=CGRectMake(bsize.width-28, 17, 60, 36);
  52. [_rejectBt setTitle:@"拒绝" forState:UIControlStateNormal];
  53. [_rejectBt.titleLabel setFont:[UIFont systemFontOfSize:16.0f]];
  54. [_rejectBt addTarget:nil action:@selector(rejectex) forControlEvents:UIControlEventTouchUpInside];
  55. [self.contentView addSubview:_rejectBt];
  56. }
  57. - (void)fillWithData:( NSDictionary*)data {
  58. NSLog(@"fillWithData:%@",data);
  59. _dataDic = data;
  60. [self.avatar sd_setImageWithURL:[NSURL URLWithString:data[@"avatar"]] placeholderImage:[UIImage imageNamed:@"Avatar"]];
  61. self.name.text = data[@"username"];
  62. // tell constraints they need updating
  63. [self setNeedsUpdateConstraints];
  64. // update constraints now so we can animate the change
  65. [self updateConstraintsIfNeeded];
  66. [self layoutIfNeeded];
  67. }
  68. -(void)agreetex{
  69. NSLog(@"agreetex");
  70. [FriendNetApi agreeADDfriend:_dataDic[@"userId"] succ:^(int code, NSDictionary * res) {
  71. NSError *error;
  72. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:res options:0 error:&error];
  73. if (!jsonData) {
  74. NSLog(@"Got an error: %@", error);
  75. } else {
  76. NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  77. NSLog(@"%@", jsonString); // 输出:{"name":"John","age":25}
  78. }
  79. if(self.delegate){
  80. [self.delegate actionNote:@"succ"];
  81. }
  82. } fail:^(NSError * _Nonnull error) {
  83. NSLog(@"error:%@",error);
  84. if(self.delegate){
  85. [self.delegate actionNote:@"fail"];
  86. }
  87. }];
  88. }
  89. -(void)rejectex{
  90. [FriendNetApi deletefriend:_dataDic[@"userId"] succ:^(int code, NSDictionary * res) {
  91. NSLog(@"res:%@",res);
  92. if(self.delegate){
  93. [self.delegate actionNote:@"succ"];
  94. }
  95. } fail:^(NSError * _Nonnull error) {
  96. NSLog(@"error:%@",error);
  97. if(self.delegate){
  98. [self.delegate actionNote:@"fail"];
  99. }
  100. }];
  101. }
  102. @end