// // YMCallRecordCell.m // MSYOUPAI // // Created by YoMi on 2024/3/20. // Copyright © 2024 MS. All rights reserved. // #import "YMCallRecordCell.h" #import "YMCallRecordCellViewModel.h" @interface YMCallRecordCell () /// 通话记录VM @property (nonatomic, strong) YMCallRecordCellViewModel *viewModel; /// 基础视图 @property (nonatomic, strong) UIView *baseView; /// 用户头像视图 @property (nonatomic, strong) UIImageView *userAvatarView; /// 用户昵称标签 @property (nonatomic, strong) UILabel *userNicknameLb; /// 用户通话时长标签 @property (nonatomic, strong) UILabel *userCallDurationLb; /// 用户通话日期标签 @property (nonatomic, strong) UILabel *userCallDateLb; @end @implementation YMCallRecordCell - (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.userCallDurationLb]; [self.baseView addSubview:self.userCallDateLb]; [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(50)); }]; [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userAvatarView.mas_top).offset(adapt(5)); make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10)); }]; [self.userCallDurationLb mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.userAvatarView.mas_bottom).offset(adapt(-5)); make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(10)); }]; [self.userCallDateLb mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.baseView.mas_centerY); make.right.equalTo(self.baseView).offset(adapt(-15)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMCallRecordCellViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; self.userNicknameLb.text = self.viewModel.userNickname; [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.viewModel.userAvatar]]; self.userCallDurationLb.text = self.viewModel.userCallDuration; self.userCallDateLb.text = self.viewModel.userCallDate; } - (UIView *)baseView{ if (!_baseView) { _baseView = [[UIView alloc]init]; } return _baseView; } - (UIImageView *)userAvatarView{ if (!_userAvatarView) { _userAvatarView = [[UIImageView alloc]init]; _userAvatarView.backgroundColor = UIColor.lightGrayColor; _userAvatarView.layer.cornerRadius = adapt(50)/2; _userAvatarView.layer.masksToBounds = YES; } return _userAvatarView; } - (UILabel *)userNicknameLb{ if (!_userNicknameLb) { _userNicknameLb = [[UILabel alloc]init]; _userNicknameLb.font = LCBoldFont(15); _userNicknameLb.textColor = HexColorFromRGB(0x1B2739); _userNicknameLb.textAlignment = NSTextAlignmentLeft; _userNicknameLb.text = @"******"; } return _userNicknameLb; } - (UILabel *)userCallDurationLb{ if (!_userCallDurationLb) { _userCallDurationLb = [[UILabel alloc]init]; _userCallDurationLb.font = LCFont(12); _userCallDurationLb.textColor = HexColorFromRGB(0x7E848D); _userCallDurationLb.textAlignment = NSTextAlignmentLeft; _userCallDurationLb.text = @"通话时长:**:**"; } return _userCallDurationLb; } - (UILabel *)userCallDateLb{ if (!_userCallDateLb) { _userCallDateLb = [[UILabel alloc]init]; _userCallDateLb.font = LCFont(12); _userCallDateLb.textColor = HexColorFromRGB(0x7E848D); _userCallDateLb.textAlignment = NSTextAlignmentLeft; _userCallDateLb.text = @"****.**.**"; } return _userCallDateLb; } @end