// // YMMemberInfoView.m // MSYOUPAI // // Created by YoMi on 2024/2/27. // Copyright © 2024 MS. All rights reserved. // #import "YMMemberInfoView.h" #import "YMMemberCenterViewModel.h" @interface YMMemberInfoView () /// 会员中心VM @property (nonatomic, strong) YMMemberCenterViewModel *viewModel; /// 信息背景图 @property (nonatomic, strong) UIImageView *infoBgView; @property (nonatomic, strong) UIImageView *hgBgView; /// 用户头像视图 @property (nonatomic, strong) UIImageView *userAvatarView; /// 用户昵称标签 @property (nonatomic, strong) UILabel *userNicknameLb; /// 有效日期标签 @property (nonatomic, strong) UILabel *validityDateLb; /// 提示视图 @property (nonatomic, strong) UIView *tipsView; /// 提示标签 @property (nonatomic, strong) UILabel *tipsLb; @end @implementation YMMemberInfoView - (void)ym_setupViews{ [self addSubview:self.infoBgView]; [self.infoBgView addSubview:self.hgBgView]; [self.infoBgView addSubview:self.userAvatarView]; [self.infoBgView addSubview:self.userNicknameLb]; [self.infoBgView addSubview:self.validityDateLb]; [self.infoBgView addSubview:self.tipsView]; [self.tipsView addSubview:self.tipsLb]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.infoBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self); make.left.equalTo(self); make.right.equalTo(self); make.bottom.equalTo(self); make.height.mas_equalTo(adapt(98)); }]; [self.hgBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.infoBgView).offset(adapt(4)); make.right.equalTo(self.infoBgView).offset(adapt(-10)); make.width.mas_equalTo(adapt(104)); make.height.mas_equalTo(adapt(68)); }]; [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.infoBgView).offset(adapt(7)); make.left.equalTo(self.infoBgView).offset(adapt(12)); make.width.height.mas_equalTo(adapt(58)); }]; [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.userAvatarView.mas_centerY).offset(adapt(-5)); make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(12)); }]; [self.validityDateLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userNicknameLb.mas_bottom).offset(5); make.left.equalTo(self.userAvatarView.mas_right).offset(adapt(12)); }]; [self.tipsView mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.infoBgView).offset(0); make.left.equalTo(self.infoBgView); make.right.equalTo(self.infoBgView); make.height.mas_equalTo(adapt(25)); }]; [self.tipsLb mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.tipsView.mas_centerY); make.left.equalTo(self.tipsView).offset(adapt(17)); make.right.equalTo(self.tipsView).offset(adapt(-17)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMMemberCenterViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; @weakify(self) [[[[RACObserve(self.viewModel, userAvatar) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * userAvatar) { @strongify(self) [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:userAvatar]]; }]; RAC(self.userNicknameLb, text) = RACObserve(self.viewModel, userNickname); RAC(self.validityDateLb, text) = RACObserve(self.viewModel, validityDate); } - (UIImageView *)infoBgView{ if (!_infoBgView) { _infoBgView = [[UIImageView alloc]init]; //_infoBgView.image = ImageByName(@"ym_member_center_info_bg_icon"); _infoBgView.layer.cornerRadius = adapt(10); _infoBgView.layer.masksToBounds = YES; _infoBgView.clipsToBounds = YES; } return _infoBgView; } - (UIImageView *)hgBgView{ if (!_hgBgView) { _hgBgView = [[UIImageView alloc]init]; _hgBgView.hidden = YES; _hgBgView.image = ImageByName(@"ym_member_center_huangguan"); } return _hgBgView; } - (UIImageView *)userAvatarView{ if (!_userAvatarView) { _userAvatarView = [[UIImageView alloc]init]; _userAvatarView.backgroundColor = UIColor.lightGrayColor; _userAvatarView.layer.borderColor = UIColor.whiteColor.CGColor; _userAvatarView.layer.borderWidth = adapt(2); _userAvatarView.layer.cornerRadius = adapt(58)/2; _userAvatarView.layer.masksToBounds = YES; } return _userAvatarView; } - (UILabel *)userNicknameLb{ if (!_userNicknameLb) { _userNicknameLb = [[UILabel alloc]init]; _userNicknameLb.font = LCBoldFont(16); _userNicknameLb.textColor = rgba(99, 50, 40, 1); _userNicknameLb.textAlignment = NSTextAlignmentLeft; _userNicknameLb.text = @"******"; } return _userNicknameLb; } - (UILabel *)validityDateLb{ if (!_validityDateLb) { _validityDateLb = [[UILabel alloc]init]; _validityDateLb.font = LCFont(11); _validityDateLb.textColor = rgba(99, 50, 40, 1); _validityDateLb.textAlignment = NSTextAlignmentLeft; _validityDateLb.text = @"******"; } return _validityDateLb; } - (UIView *)tipsView{ if (!_tipsView) { _tipsView = [[UIView alloc]init]; _tipsView.backgroundColor = UIColor.clearColor; // [_tipsView ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP]; } return _tipsView; } - (UILabel *)tipsLb{ if (!_tipsLb) { _tipsLb = [[UILabel alloc]init]; _tipsLb.hidden = YES; _tipsLb.font = LCFont(12); _tipsLb.textColor = HexColorFromRGB(0x834A00); _tipsLb.textAlignment = NSTextAlignmentLeft; _tipsLb.text = @"9大特权,提升个性化体验"; } return _tipsLb; } @end