YMBlackListCell.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // YMBlackListCell.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/21.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMBlackListCell.h"
  9. #import "YMBlackListCellViewModel.h"
  10. @interface YMBlackListCell ()
  11. /// 黑名单VM
  12. @property (nonatomic, strong) YMBlackListCellViewModel *viewModel;
  13. /// 基础视图
  14. @property (nonatomic, strong) UIView *baseView;
  15. /// 用户头像视图
  16. @property (nonatomic, strong) UIImageView *userAvatarView;
  17. /// 用户昵称标签
  18. @property (nonatomic, strong) UILabel *userNicknameLb;
  19. /// 用户简介标签
  20. @property (nonatomic, strong) UILabel *userIntroLb;
  21. /// 用户性别和年龄视图
  22. @property (nonatomic, strong) UIView *userGenderAndAgeView;
  23. /// 用户性别图标
  24. @property (nonatomic, strong) UIImageView *userGenderAndAgeIcon;
  25. /// 用户年龄标签
  26. @property (nonatomic, strong) UILabel *userGenderAndAgeLb;
  27. /// 移除按钮
  28. @property (nonatomic, strong) UIButton *removeBtn;
  29. @end
  30. @implementation YMBlackListCell
  31. - (void)awakeFromNib {
  32. [super awakeFromNib];
  33. // Initialization code
  34. }
  35. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  36. [super setSelected:selected animated:animated];
  37. // Configure the view for the selected state
  38. }
  39. - (void)ym_setupViews{
  40. [self.contentView addSubview:self.baseView];
  41. [self.baseView addSubview:self.userAvatarView];
  42. [self.baseView addSubview:self.userNicknameLb];
  43. [self.baseView addSubview:self.userIntroLb];
  44. [self.baseView addSubview:self.userGenderAndAgeView];
  45. [self.userGenderAndAgeView addSubview:self.userGenderAndAgeIcon];
  46. [self.userGenderAndAgeView addSubview:self.userGenderAndAgeLb];
  47. [self.baseView addSubview:self.removeBtn];
  48. [self setNeedsUpdateConstraints];
  49. [self updateConstraintsIfNeeded];
  50. }
  51. - (void)updateConstraints{
  52. [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.top.equalTo(self.contentView);
  54. make.left.equalTo(self.contentView);
  55. make.right.equalTo(self.contentView);
  56. make.bottom.equalTo(self.contentView);
  57. }];
  58. [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.centerY.equalTo(self.baseView.mas_centerY);
  60. make.left.equalTo(self.baseView).offset(adapt(15));
  61. make.width.height.mas_equalTo(adapt(40));
  62. }];
  63. [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.top.equalTo(self.userAvatarView.mas_top);
  65. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  66. }];
  67. [self.userIntroLb mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.bottom.equalTo(self.userAvatarView.mas_bottom);
  69. make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10));
  70. make.right.equalTo(self.removeBtn.mas_left).offset(adapt(-10));
  71. }];
  72. [self.userGenderAndAgeView mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.centerY.equalTo(self.userNicknameLb.mas_centerY);
  74. make.left.equalTo(self.userNicknameLb.mas_right).offset(adapt(5));
  75. make.height.mas_equalTo(adapt(15));
  76. }];
  77. [self.userGenderAndAgeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.centerY.equalTo(self.userGenderAndAgeView.mas_centerY);
  79. make.left.equalTo(self.userGenderAndAgeView).offset(adapt(7));
  80. make.width.height.mas_equalTo(adapt(10));
  81. }];
  82. [self.userGenderAndAgeLb mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.centerY.equalTo(self.userGenderAndAgeView.mas_centerY);
  84. make.left.equalTo(self.userGenderAndAgeIcon.mas_right).offset(adapt(3));
  85. make.right.equalTo(self.userGenderAndAgeView).offset(adapt(-7));
  86. }];
  87. [self.removeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.centerY.equalTo(self.baseView.mas_centerY);
  89. make.right.equalTo(self.baseView).offset(adapt(-15));
  90. make.width.mas_equalTo(adapt(60));
  91. make.height.mas_equalTo(adapt(30));
  92. }];
  93. [super updateConstraints];
  94. }
  95. - (void)ym_bindViewModel:(YMBlackListCellViewModel *)viewModel{
  96. if (!viewModel) {
  97. return;
  98. }
  99. _viewModel = viewModel;
  100. [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.viewModel.userAvatar]];
  101. self.userNicknameLb.text = self.viewModel.userNickname;
  102. self.userNicknameLb.text = self.viewModel.userNickname;
  103. self.userGenderAndAgeIcon.image = self.viewModel.userGenderAndAgeIcon;
  104. self.userGenderAndAgeLb.text = self.viewModel.userGenderAndAgeText;
  105. if ([self.viewModel.userGender isEqualToString:@"女"]) {
  106. [self.userGenderAndAgeView ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0xb55ee9),HexColorFromRGB(0xe16cde)] locations:kMainGradLocation startPoint:CGPointMake(0.56, 0.09) endPoint:CGPointMake(0.56, 1)];
  107. } else {
  108. [self.userGenderAndAgeView ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0x6b82f6),HexColorFromRGB(0x80caf9)] locations:kMainGradLocation startPoint:CGPointMake(0.56, 0.09) endPoint:CGPointMake(0.56, 1)];
  109. }
  110. self.userIntroLb.text = self.viewModel.userIntro;
  111. }
  112. - (UIView *)baseView{
  113. if (!_baseView) {
  114. _baseView = [[UIView alloc]init];
  115. }
  116. return _baseView;
  117. }
  118. - (UIImageView *)userAvatarView{
  119. if (!_userAvatarView) {
  120. _userAvatarView = [[UIImageView alloc]init];
  121. _userAvatarView.backgroundColor = UIColor.lightGrayColor;
  122. _userAvatarView.contentMode = UIViewContentModeScaleAspectFill;
  123. _userAvatarView.layer.cornerRadius = adapt(40)/2;
  124. _userAvatarView.layer.masksToBounds = YES;
  125. _userAvatarView.clipsToBounds = YES;
  126. }
  127. return _userAvatarView;
  128. }
  129. - (UILabel *)userNicknameLb{
  130. if (!_userNicknameLb) {
  131. _userNicknameLb = [[UILabel alloc]init];
  132. _userNicknameLb.font = LCFont(16);
  133. _userNicknameLb.textColor = HexColorFromRGB(0x000000);
  134. _userNicknameLb.textAlignment = NSTextAlignmentLeft;
  135. _userNicknameLb.text = @"******";
  136. }
  137. return _userNicknameLb;
  138. }
  139. - (UILabel *)userIntroLb{
  140. if (!_userIntroLb) {
  141. _userIntroLb = [[UILabel alloc]init];
  142. _userIntroLb.font = LCFont(12);
  143. _userIntroLb.textColor = HexColorFromRGB(0x696969);
  144. _userIntroLb.textAlignment = NSTextAlignmentLeft;
  145. _userIntroLb.text = @"这个人很懒,什么都没有留下...";
  146. }
  147. return _userIntroLb;
  148. }
  149. - (UIView *)userGenderAndAgeView{
  150. if (!_userGenderAndAgeView) {
  151. _userGenderAndAgeView = [[UIView alloc]init];
  152. _userGenderAndAgeView.layer.cornerRadius = adapt(15)/2;
  153. }
  154. return _userGenderAndAgeView;
  155. }
  156. - (UIImageView *)userGenderAndAgeIcon{
  157. if (!_userGenderAndAgeIcon) {
  158. _userGenderAndAgeIcon = [[UIImageView alloc]init];
  159. _userGenderAndAgeIcon.image = ImageByName(@"ym_personal_page_female_icon");
  160. }
  161. return _userGenderAndAgeIcon;
  162. }
  163. - (UILabel *)userGenderAndAgeLb{
  164. if (!_userGenderAndAgeLb) {
  165. _userGenderAndAgeLb = [[UILabel alloc]init];
  166. _userGenderAndAgeLb.font = LCFont(10);
  167. _userGenderAndAgeLb.textColor = HexColorFromRGB(0xFFFFFF);
  168. _userGenderAndAgeLb.textAlignment = NSTextAlignmentCenter;
  169. _userGenderAndAgeLb.text = @"***";
  170. }
  171. return _userGenderAndAgeLb;
  172. }
  173. - (UIButton *)removeBtn{
  174. if (!_removeBtn) {
  175. _removeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  176. _removeBtn.backgroundColor = HexColorFromRGB(0xFF70C5);
  177. _removeBtn.titleLabel.font = LCFont(13);
  178. [_removeBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
  179. [_removeBtn setTitle:@"移除" forState:UIControlStateNormal];
  180. _removeBtn.layer.cornerRadius = adapt(8);
  181. WS(weakSelf)
  182. [[[_removeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  183. YMTipsPopupView *customView = [[YMTipsPopupView alloc]init];
  184. [customView configutationWithTips:@"您确定要将该用户移除黑名单吗?" TipsAlignment:NSTextAlignmentCenter IsHideTitle:YES IsHideSingleButton:YES];
  185. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  186. popupView.priority = 999;
  187. popupView.cornerRadius = adapt(10);
  188. popupView.rectCorners = UIRectCornerAllCorners;
  189. popupView.positionStyle = YMPositionStyleCenter;
  190. popupView.isHideBg = NO;
  191. popupView.bgAlpha = 0.3;
  192. @weakify(popupView)
  193. customView.buttonBlock = ^(BOOL isConfirm) {
  194. @strongify(popupView)
  195. if (isConfirm) {
  196. [weakSelf.viewModel removeBlackData];
  197. }
  198. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  199. };
  200. [popupView pop];
  201. }];
  202. }
  203. return _removeBtn;
  204. }
  205. @end