GroupListCell.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // GroupListCell.m
  3. // AIIM
  4. //
  5. // Created by gan on 2025/4/6.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "GroupListCell.h"
  9. #import <SDWebImage/UIImageView+WebCache.h>
  10. @implementation GroupListCell
  11. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  12. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  13. if (self) {
  14. [self setupViews];
  15. }
  16. return self;
  17. }
  18. - (void)setupViews {
  19. CGSize size = self.contentView.frame.size;
  20. _avatar =[[UIImageView alloc] init];
  21. _avatar.frame=CGRectMake(8, 8, 50, 50);
  22. _avatar.contentMode = UIViewContentModeScaleAspectFill;
  23. _avatar.layer.cornerRadius = 25;
  24. _avatar.layer.masksToBounds = YES;
  25. _avatar.backgroundColor=[UIColor lightGrayColor];
  26. [self.contentView addSubview:_avatar];
  27. _name = [[UILabel alloc] init];
  28. _name.frame=CGRectMake(68, 8,190, 50);
  29. _name.backgroundColor=[UIColor clearColor];
  30. [_name setFont:[UIFont boldSystemFontOfSize:15]];
  31. _name.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
  32. _name.adjustsFontForContentSizeCategory = YES;
  33. [_name setTextColor:[UIColor whiteColor]];
  34. [self.contentView addSubview:_name];
  35. _tongyi = [[UIButton alloc] init];
  36. _tongyi.frame=CGRectMake(size.width-70, 16, 50, 30);
  37. _tongyi.backgroundColor =globalColor(GCTypeGreen);
  38. _tongyi.layer.cornerRadius = 8;
  39. _tongyi.layer.masksToBounds = YES; // 防止子视图超出圆角边界
  40. _tongyi.titleLabel.font = [UIFont systemFontOfSize: 14.0];
  41. [_tongyi setTitle:@"同意" forState:UIControlStateNormal];
  42. _tongyi.titleLabel.textColor = [UIColor whiteColor];
  43. [self.contentView addSubview:_tongyi];
  44. _jujue = [[UIButton alloc] init];
  45. // _jujue.frame=CGRectMake(size.width-10, 16, 50, 30);
  46. _jujue.titleLabel.font = [UIFont systemFontOfSize: 14.0];
  47. [_jujue setTitle:@"拒绝" forState:UIControlStateNormal];
  48. _jujue.backgroundColor =globalColor(GCTypeOrangeR);
  49. _jujue.layer.cornerRadius = 8;
  50. _jujue.layer.masksToBounds = YES; // 防止子视图超出圆角边界
  51. _jujue.titleLabel.textColor = [UIColor whiteColor];
  52. [self.contentView addSubview:_jujue];
  53. [_tongyi addTarget:self action:@selector(tongyiAct) forControlEvents:UIControlEventTouchUpInside];
  54. [_jujue addTarget:self action:@selector(jujueAct) forControlEvents:UIControlEventTouchUpInside];
  55. }
  56. - (void)fillWithData:( NSDictionary*)data cellType:(NSInteger)type{
  57. [_name setTextColor:[UIColor whiteColor]];
  58. [_jujue mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.right.equalTo(self.contentView).offset(-0);
  60. make.top.equalTo(self.contentView).offset(16);
  61. make.width.height.mas_equalTo(CGSizeMake(50, 30));
  62. }];
  63. [_tongyi mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.right.equalTo(_jujue.mas_left).offset(-6);
  65. make.top.equalTo(self.contentView).offset(16);
  66. make.width.height.mas_equalTo(CGSizeMake(50, 30));
  67. }];
  68. if(type==0){
  69. _tongyi.alpha = 0;
  70. _jujue.alpha = 0;
  71. }
  72. else if(type==1){
  73. _tongyi.alpha = 1;
  74. _jujue.alpha = 1;
  75. _actId =data[@"id"];
  76. }
  77. else if(type==2){
  78. if([self ismaster:data[@"id"]]){
  79. _tongyi.alpha = 0;
  80. _jujue.alpha = 0;
  81. [_name setTextColor:globalColor(GCTypeOrangeR)];
  82. }
  83. else{
  84. _tongyi.alpha = 0;
  85. _jujue.alpha = 1;
  86. _actId =data[@"id"];
  87. [_jujue setTitle:@"转让" forState:UIControlStateNormal];
  88. }
  89. }
  90. else if(type==3){
  91. _tongyi.alpha = 0;
  92. _jujue.alpha = 1;
  93. _actId =data[@"id"];
  94. [_jujue setTitle:@"邀请" forState:UIControlStateNormal];
  95. }
  96. else if(type==4){
  97. if([self ismaster:data[@"id"]]){
  98. _tongyi.alpha = 0;
  99. _jujue.alpha = 0;
  100. [_name setTextColor:globalColor(GCTypeOrangeR)];
  101. }
  102. else{
  103. _tongyi.alpha = 0;
  104. _jujue.alpha = 1;
  105. _actId =data[@"id"];
  106. [_jujue setTitle:@"踢出" forState:UIControlStateNormal];
  107. }
  108. }
  109. //NSLog(@"fillWithData:%@",data);
  110. NSString *avatar =data[@"avatar"];
  111. if([avatar isKindOfClass:[NSString class]]){
  112. }
  113. else{
  114. avatar = @"";
  115. }
  116. [self.avatar sd_setImageWithURL:[NSURL URLWithString:avatar] placeholderImage:[UIImage imageNamed:@"Avatar"]];
  117. if(type==1){
  118. self.name.text = data[@"userName"];
  119. }
  120. else{
  121. self.name.text = data[@"name"];
  122. }
  123. // tell constraints they need updating
  124. [self setNeedsUpdateConstraints];
  125. // update constraints now so we can animate the change
  126. [self updateConstraintsIfNeeded];
  127. [self layoutIfNeeded];
  128. }
  129. -(void)tongyiAct{
  130. if(self.delegate){
  131. [self.delegate GroupListCellAct:_actId act:1];
  132. }
  133. }
  134. -(void)jujueAct{
  135. if(self.delegate){
  136. [self.delegate GroupListCellAct:_actId act:0];
  137. }
  138. }
  139. -(BOOL)ismaster:(NSString *)userId{
  140. NSDictionary * userinfo= [UDManager.shareInstance getDDManager:dkuserinfo];
  141. NSString *usid = userinfo[@"id"];
  142. if([userId isEqualToString:usid]){
  143. return YES;
  144. }
  145. return NO;
  146. }
  147. @end