| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- //
- // EXFriendListCell.m
- // AIIM
- //
- // Created by gan on 2025/4/6.
- //
- #import "EXFriendListCell.h"
- #import <SDWebImage/UIImageView+WebCache.h>
- #import "config.h"
- #import "FriendNetApi.h"
- @interface EXFriendListCell()
- @property (strong, nonatomic) UIButton *agreetBt;
- @property (strong, nonatomic) UIButton *rejectBt;
- @property (strong, nonatomic) NSDictionary *dataDic;
- @end
- @implementation EXFriendListCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self setupViews];
- }
- return self;
- }
- - (void)setupViews {
- CGSize bsize = self.contentView.frame.size;
- _avatar =[[UIImageView alloc] init];
- _avatar.frame=CGRectMake(8, 10, 50, 50);
- _avatar.contentMode = UIViewContentModeScaleAspectFill;
- _avatar.layer.cornerRadius = 25;
- _avatar.layer.masksToBounds = YES;
- _avatar.backgroundColor=[UIColor lightGrayColor];
- [self.contentView addSubview:_avatar];
-
- _name = [[UILabel alloc] init];
- _name.frame=CGRectMake(68, 10, 150, 50);
- _name.backgroundColor=[UIColor clearColor];
- _name.numberOfLines = 2;
- [_name setFont:[UIFont boldSystemFontOfSize:18]];
- [_name setTextColor:[UIColor whiteColor]];
-
- [self.contentView addSubview:_name];
-
- _agreetBt =[[UIButton alloc] init];
- _agreetBt.layer.backgroundColor =globalColor(GCTypeGreend).CGColor;
- _agreetBt.layer.cornerRadius = 8.0f;
- _agreetBt.frame=CGRectMake(bsize.width-94, 17, 60, 36);
- [_agreetBt setTitle:@"同意" forState:UIControlStateNormal];
- [_agreetBt.titleLabel setFont:[UIFont systemFontOfSize:16.0f]];
- [_agreetBt addTarget:nil action:@selector(agreetex) forControlEvents:UIControlEventTouchUpInside];
- [self.contentView addSubview:_agreetBt];
-
-
- _rejectBt =[[UIButton alloc] init];
- _rejectBt.layer.backgroundColor =[UIColor lightGrayColor].CGColor;
- _rejectBt.layer.cornerRadius = 8.0f;
- _rejectBt.frame=CGRectMake(bsize.width-28, 17, 60, 36);
- [_rejectBt setTitle:@"拒绝" forState:UIControlStateNormal];
- [_rejectBt.titleLabel setFont:[UIFont systemFontOfSize:16.0f]];
- [_rejectBt addTarget:nil action:@selector(rejectex) forControlEvents:UIControlEventTouchUpInside];
- [self.contentView addSubview:_rejectBt];
- }
- - (void)fillWithData:( NSDictionary*)data {
-
- NSLog(@"fillWithData:%@",data);
- _dataDic = data;
- [self.avatar sd_setImageWithURL:[NSURL URLWithString:data[@"avatar"]] placeholderImage:[UIImage imageNamed:@"Avatar"]];
- self.name.text = data[@"username"];
-
- // tell constraints they need updating
- [self setNeedsUpdateConstraints];
- // update constraints now so we can animate the change
- [self updateConstraintsIfNeeded];
- [self layoutIfNeeded];
- }
- -(void)agreetex{
- NSLog(@"agreetex");
- [FriendNetApi agreeADDfriend:_dataDic[@"userId"] succ:^(int code, NSDictionary * res) {
- NSError *error;
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:res options:0 error:&error];
- if (!jsonData) {
- NSLog(@"Got an error: %@", error);
- } else {
- NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
- NSLog(@"%@", jsonString); // 输出:{"name":"John","age":25}
- }
- if(self.delegate){
- [self.delegate actionNote:@"succ"];
- }
- } fail:^(NSError * _Nonnull error) {
- NSLog(@"error:%@",error);
- if(self.delegate){
- [self.delegate actionNote:@"fail"];
- }
- }];
- }
- -(void)rejectex{
-
- [FriendNetApi deletefriend:_dataDic[@"userId"] succ:^(int code, NSDictionary * res) {
- NSLog(@"res:%@",res);
- if(self.delegate){
- [self.delegate actionNote:@"succ"];
- }
- } fail:^(NSError * _Nonnull error) {
- NSLog(@"error:%@",error);
- if(self.delegate){
- [self.delegate actionNote:@"fail"];
- }
- }];
- }
- @end
|