// // YMBlackListCell.m // MSYOUPAI // // Created by YoMi on 2024/2/21. // Copyright © 2024 MS. All rights reserved. // #import "YMBlackListCell.h" #import "YMBlackListCellViewModel.h" @interface YMBlackListCell () /// 黑名单VM @property (nonatomic, strong) YMBlackListCellViewModel *viewModel; /// 基础视图 @property (nonatomic, strong) UIView *baseView; /// 用户头像视图 @property (nonatomic, strong) UIImageView *userAvatarView; /// 用户昵称标签 @property (nonatomic, strong) UILabel *userNicknameLb; /// 用户简介标签 @property (nonatomic, strong) UILabel *userIntroLb; /// 用户性别和年龄视图 @property (nonatomic, strong) UIView *userGenderAndAgeView; /// 用户性别图标 @property (nonatomic, strong) UIImageView *userGenderAndAgeIcon; /// 用户年龄标签 @property (nonatomic, strong) UILabel *userGenderAndAgeLb; /// 移除按钮 @property (nonatomic, strong) UIButton *removeBtn; @end @implementation YMBlackListCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (void)ym_setupViews{ [self.contentView addSubview:self.baseView]; [self.baseView addSubview:self.userAvatarView]; [self.baseView addSubview:self.userNicknameLb]; [self.baseView addSubview:self.userIntroLb]; [self.baseView addSubview:self.userGenderAndAgeView]; [self.userGenderAndAgeView addSubview:self.userGenderAndAgeIcon]; [self.userGenderAndAgeView addSubview:self.userGenderAndAgeLb]; [self.baseView addSubview:self.removeBtn]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView); make.left.equalTo(self.contentView); make.right.equalTo(self.contentView); make.bottom.equalTo(self.contentView); }]; [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.baseView.mas_centerY); make.left.equalTo(self.baseView).offset(adapt(15)); make.width.height.mas_equalTo(adapt(40)); }]; [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userAvatarView.mas_top); make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10)); }]; [self.userIntroLb mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.userAvatarView.mas_bottom); make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10)); make.right.equalTo(self.removeBtn.mas_left).offset(adapt(-10)); }]; [self.userGenderAndAgeView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.userNicknameLb.mas_centerY); make.left.equalTo(self.userNicknameLb.mas_right).offset(adapt(5)); make.height.mas_equalTo(adapt(15)); }]; [self.userGenderAndAgeIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.userGenderAndAgeView.mas_centerY); make.left.equalTo(self.userGenderAndAgeView).offset(adapt(7)); make.width.height.mas_equalTo(adapt(10)); }]; [self.userGenderAndAgeLb mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.userGenderAndAgeView.mas_centerY); make.left.equalTo(self.userGenderAndAgeIcon.mas_right).offset(adapt(3)); make.right.equalTo(self.userGenderAndAgeView).offset(adapt(-7)); }]; [self.removeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.baseView.mas_centerY); make.right.equalTo(self.baseView).offset(adapt(-15)); make.width.mas_equalTo(adapt(60)); make.height.mas_equalTo(adapt(30)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMBlackListCellViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.viewModel.userAvatar]]; self.userNicknameLb.text = self.viewModel.userNickname; self.userNicknameLb.text = self.viewModel.userNickname; self.userGenderAndAgeIcon.image = self.viewModel.userGenderAndAgeIcon; self.userGenderAndAgeLb.text = self.viewModel.userGenderAndAgeText; if ([self.viewModel.userGender isEqualToString:@"女"]) { [self.userGenderAndAgeView ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0xb55ee9),HexColorFromRGB(0xe16cde)] locations:kMainGradLocation startPoint:CGPointMake(0.56, 0.09) endPoint:CGPointMake(0.56, 1)]; } else { [self.userGenderAndAgeView ym_setGradientBackgroundWithColors:@[HexColorFromRGB(0x6b82f6),HexColorFromRGB(0x80caf9)] locations:kMainGradLocation startPoint:CGPointMake(0.56, 0.09) endPoint:CGPointMake(0.56, 1)]; } self.userIntroLb.text = self.viewModel.userIntro; } - (UIView *)baseView{ if (!_baseView) { _baseView = [[UIView alloc]init]; } return _baseView; } - (UIImageView *)userAvatarView{ if (!_userAvatarView) { _userAvatarView = [[UIImageView alloc]init]; _userAvatarView.backgroundColor = UIColor.lightGrayColor; _userAvatarView.contentMode = UIViewContentModeScaleAspectFill; _userAvatarView.layer.cornerRadius = adapt(40)/2; _userAvatarView.layer.masksToBounds = YES; _userAvatarView.clipsToBounds = YES; } return _userAvatarView; } - (UILabel *)userNicknameLb{ if (!_userNicknameLb) { _userNicknameLb = [[UILabel alloc]init]; _userNicknameLb.font = LCFont(16); _userNicknameLb.textColor = HexColorFromRGB(0x000000); _userNicknameLb.textAlignment = NSTextAlignmentLeft; _userNicknameLb.text = @"******"; } return _userNicknameLb; } - (UILabel *)userIntroLb{ if (!_userIntroLb) { _userIntroLb = [[UILabel alloc]init]; _userIntroLb.font = LCFont(12); _userIntroLb.textColor = HexColorFromRGB(0x696969); _userIntroLb.textAlignment = NSTextAlignmentLeft; _userIntroLb.text = @"这个人很懒,什么都没有留下..."; } return _userIntroLb; } - (UIView *)userGenderAndAgeView{ if (!_userGenderAndAgeView) { _userGenderAndAgeView = [[UIView alloc]init]; _userGenderAndAgeView.layer.cornerRadius = adapt(15)/2; } return _userGenderAndAgeView; } - (UIImageView *)userGenderAndAgeIcon{ if (!_userGenderAndAgeIcon) { _userGenderAndAgeIcon = [[UIImageView alloc]init]; _userGenderAndAgeIcon.image = ImageByName(@"ym_personal_page_female_icon"); } return _userGenderAndAgeIcon; } - (UILabel *)userGenderAndAgeLb{ if (!_userGenderAndAgeLb) { _userGenderAndAgeLb = [[UILabel alloc]init]; _userGenderAndAgeLb.font = LCFont(10); _userGenderAndAgeLb.textColor = HexColorFromRGB(0xFFFFFF); _userGenderAndAgeLb.textAlignment = NSTextAlignmentCenter; _userGenderAndAgeLb.text = @"***"; } return _userGenderAndAgeLb; } - (UIButton *)removeBtn{ if (!_removeBtn) { _removeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _removeBtn.backgroundColor = HexColorFromRGB(0xFF70C5); _removeBtn.titleLabel.font = LCFont(13); [_removeBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal]; [_removeBtn setTitle:@"移除" forState:UIControlStateNormal]; _removeBtn.layer.cornerRadius = adapt(8); WS(weakSelf) [[[_removeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { YMTipsPopupView *customView = [[YMTipsPopupView alloc]init]; [customView configutationWithTips:@"您确定要将该用户移除黑名单吗?" TipsAlignment:NSTextAlignmentCenter IsHideTitle:YES IsHideSingleButton:YES]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm) { @strongify(popupView) if (isConfirm) { [weakSelf.viewModel removeBlackData]; } [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; [popupView pop]; }]; } return _removeBtn; } @end