// // YMMineInfoView.m // MSYOUPAI // // Created by YoMi on 2024/2/15. // Copyright © 2024 MS. All rights reserved. // #import "YMMineInfoView.h" #import "YMMineViewModel.h" #define kQuantityInfoGridView_rowCount 4 #define kQuantityInfoGridView_itemHeight 60 @interface YMMineInfoView () /// 我的VM @property (nonatomic, strong) YMMineViewModel *viewModel; /// 用户头像视图 @property (nonatomic, strong) UIImageView *bgimgv; /// 用户头像视图 @property (nonatomic, strong) UIImageView *bgcimgv; /// 用户头像视图 @property (nonatomic, strong) UIImageView *userAvatarView; /// 用户昵称标签 @property (nonatomic, strong) UILabel *userNicknameLb; /// 用户VIP图标 @property (nonatomic, strong) UIImageView *userVIPIcon; /// 用户Code视图 @property (nonatomic, strong) UIView *userCodeView; /// 用户Code标签 @property (nonatomic, strong) UIImageView *userCodeIcon; /// 用户Code标签 @property (nonatomic, strong) UILabel *userCodeLb; /// 用户Code复制图标 @property (nonatomic, strong) UIImageView *userCodeCopyIcon; /// 用户简介标签 @property (nonatomic, strong) UILabel *userIntroLb; /// 编辑资料 @property (nonatomic, strong) UIButton *editProfileBtn; /// 数量信息宫格配置 @property (nonatomic, strong) BAGridView_Config *quantityInfoGridViewConfig; /// 数量信息宫格视图 @property (nonatomic, strong) BAGridView *quantityInfoGridView; @property (nonatomic, strong) UIButton *personBtn; @property (nonatomic, strong) UIButton *customButton; @property (nonatomic, strong) UIButton *settingButton; @end @implementation YMMineInfoView - (void)ym_setupViews{ [self addSubview:self.bgimgv]; [self addSubview:self.bgcimgv]; [self addSubview:self.editProfileBtn]; [self addSubview:self.settingButton]; [self addSubview:self.customButton]; [self addSubview:self.userAvatarView]; [self addSubview:self.personBtn]; [self addSubview:self.userNicknameLb]; [self addSubview:self.userVIPIcon]; [self addSubview:self.userCodeView]; [self.userCodeView addSubview:self.userCodeIcon]; [self.userCodeView addSubview:self.userCodeLb]; [self.userCodeView addSubview:self.userCodeCopyIcon]; [self addSubview:self.userIntroLb]; [self addSubview:self.quantityInfoGridView]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.editProfileBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self).offset(adapt(0)); make.centerY.equalTo(self.userAvatarView).offset(adapt(-10)); make.width.mas_equalTo(adapt(80)); make.height.mas_equalTo(adapt(28)); }]; [self.settingButton mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.mas_top).offset(NavBarHeight-10); make.right.equalTo(self).offset(adapt(-20)); make.width.height.mas_equalTo(adapt(24)); }]; [self.customButton mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.settingButton); make.right.equalTo(self.settingButton.mas_left).offset(adapt(-16)); make.width.height.mas_equalTo(adapt(24)); }]; [self.personBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.mas_top).offset(NavBarHeight-10); make.left.equalTo(self).offset(adapt(20)); make.width.mas_equalTo(adapt(110)); make.height.mas_equalTo(adapt(28)); }]; [self.bgimgv mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(0); make.left.bottom.right.equalTo(self); make.height.mas_equalTo(adapt(348)); }]; [self.bgcimgv mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.bottom.right.equalTo(self); make.height.mas_equalTo(adapt(348)); }]; [self.userAvatarView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.mas_top).offset(adapt(100)); make.centerX.equalTo(self); make.width.height.mas_equalTo(adapt(100)); }]; [self.userNicknameLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userAvatarView.mas_bottom).offset(adapt(5)); make.centerX.equalTo(self).offset(adapt(-0)); make.right.lessThanOrEqualTo(self).offset(adapt(-8)); }]; // 横向抗压缩优先级低 [self.userNicknameLb setContentCompressionResistancePriority:(UILayoutPriorityDefaultLow) forAxis:(UILayoutConstraintAxisHorizontal)]; [self.userCodeView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userNicknameLb.mas_bottom).offset(adapt(5)); make.centerX.equalTo(self); make.height.mas_equalTo(adapt(20)); }]; [self.userCodeIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.userCodeView.mas_centerY); make.left.equalTo(self.userCodeView).offset(adapt(0)); }]; [self.userCodeLb mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.userCodeView.mas_centerY); make.left.equalTo(self.userCodeView).offset(adapt(0)); }]; [self.userCodeCopyIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.userCodeView.mas_centerY); make.left.equalTo(self.userCodeLb.mas_right).offset(adapt(5)); make.right.equalTo(self.userCodeView).offset(adapt(-10)); make.width.height.mas_equalTo(adapt(12)); }]; [self.userVIPIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.userNicknameLb.mas_centerY).offset(adapt(0)); make.left.equalTo(self.userNicknameLb.mas_right).offset(adapt(5)); make.width.mas_equalTo(adapt(28)); make.height.mas_equalTo(adapt(28)); }]; [self.userIntroLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userCodeView.mas_bottom).offset(adapt(5)); make.left.equalTo(self).offset(adapt(10)); make.right.equalTo(self).offset(adapt(-10)); }]; [self.quantityInfoGridView mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.left.right.equalTo(self).offset(0); make.height.mas_equalTo(adapt(60)); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMMineViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; @weakify(self) [[[[RACObserve(self.viewModel, userAvatar) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * userAvatar) { @strongify(self) [self.bgimgv sd_setImageWithURL:[LCTools getImageUrlWithAddress:userAvatar]]; [self.userAvatarView sd_setImageWithURL:[LCTools getImageUrlWithAddress:userAvatar]]; }]; RAC(self.userNicknameLb, text) = RACObserve(self.viewModel, userNickname); [[[[RACObserve(self.viewModel, isVIP) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * isVIP) { @strongify(self) if ([isVIP boolValue]) { self.userVIPIcon.hidden = NO; } else { self.userVIPIcon.hidden = YES; } }]; [[[[RACObserve(self.viewModel, userCode) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * userCode) { @strongify(self) self.userCodeLb.text = stringFormat(@"ID: %@",userCode); }]; RAC(self.userIntroLb, text) = RACObserve(self.viewModel, userIntro); [[[[RACObserve(self.viewModel, quantityInfoGridDataArray) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSArray * quantityInfoGridDataArray) { @strongify(self) self.quantityInfoGridView.config = self.quantityInfoGridViewConfig; self.quantityInfoGridViewConfig.dataArray = quantityInfoGridDataArray; [self.quantityInfoGridView mas_remakeConstraints:^(MASConstraintMaker *make) { //make.top.equalTo(self.userAvatarView.mas_bottom).offset(adapt(10)); make.left.equalTo(self).offset(adapt(15)); make.right.equalTo(self).offset(adapt(-15)); make.bottom.equalTo(self).offset(adapt(-0)); make.height.mas_equalTo(adapt(60)); }]; }]; } - (UIButton *)personBtn{ if (!_personBtn) { _personBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _personBtn.hidden = YES; [_personBtn setImage:ImageByName(@"ym_mine_go_person_center") forState:UIControlStateNormal]; [_personBtn setTitle:@"个人主页" forState:UIControlStateNormal]; [_personBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal]; _personBtn.titleLabel.font = LCBoldFont(18); _personBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [_personBtn setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft]; CGFloat margin = 3; _personBtn.imageEdgeInsets = UIEdgeInsetsMake(0, margin, 0, -margin); _personBtn.backgroundColor = UIColor.clearColor; _personBtn.layer.cornerRadius = adapt(10); _personBtn.layer.masksToBounds = true; WS(weakSelf) [[[_personBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { [weakSelf.viewModel.commonFunctionsOperationSubject sendNext:@(YMCommonFunctionsTypePersonalPage)]; }]; } return _personBtn; } - (UIImageView *)bgimgv { if (!_bgimgv) { _bgimgv = [[UIImageView alloc] init]; _bgimgv.contentMode = UIViewContentModeScaleAspectFill; //_bgimgv.layer.cornerRadius = adapt(15); _bgimgv.layer.masksToBounds = YES; } return _bgimgv; } - (UIImageView *)bgcimgv { if (!_bgcimgv) { _bgcimgv = [[UIImageView alloc] init]; _bgcimgv.image = ImageByName(@"ym_mine_bg_cover_img"); } return _bgcimgv; } - (UIImageView *)userAvatarView{ if (!_userAvatarView) { _userAvatarView = [[UIImageView alloc]init]; _userAvatarView.contentMode = UIViewContentModeScaleAspectFill; _userAvatarView.backgroundColor = UIColor.lightGrayColor; _userAvatarView.layer.cornerRadius = adapt(100)/2; _userAvatarView.layer.masksToBounds = YES; _userAvatarView.userInteractionEnabled = YES; WS(weakSelf) UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init]; [_userAvatarView addGestureRecognizer:tap]; [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [weakSelf.viewModel.commonFunctionsOperationSubject sendNext:@(YMCommonFunctionsTypePersonalPage)]; }]; } return _userAvatarView; } - (UIButton *)settingButton{ if (!_settingButton) { _settingButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_settingButton setImage:ImageByName(@"ym_mine_right_setting") forState:UIControlStateNormal]; WS(weakSelf) [[[_settingButton rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { [weakSelf.viewModel.commonFunctionsOperationSubject sendNext:@(YMCommonFunctionsTypeSystemSetting)]; }]; } return _settingButton; } - (UIButton *)customButton{ if (!_customButton) { _customButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_customButton setImage:ImageByName(@"ym_mine_right_custom") forState:UIControlStateNormal]; WS(weakSelf) [[[_customButton rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { [weakSelf.viewModel.commonFunctionsOperationSubject sendNext:@(YMCommonFunctionsTypeOnlineCustomerSupport)]; }]; } return _customButton; } - (UILabel *)userNicknameLb{ if (!_userNicknameLb) { _userNicknameLb = [[UILabel alloc]init]; _userNicknameLb.font = LCBoldFont(18); _userNicknameLb.textColor = UIColor.whiteColor;//HexColorFromRGB(0x115B3B); _userNicknameLb.textAlignment = NSTextAlignmentLeft; _userNicknameLb.text = @"******"; } return _userNicknameLb; } - (UIImageView *)userVIPIcon{ if (!_userVIPIcon) { _userVIPIcon = [[UIImageView alloc]init]; _userVIPIcon.image = ImageByName(@"ym_mine_vip_icon"); } return _userVIPIcon; } - (UIView *)userCodeView{ if (!_userCodeView) { _userCodeView = [[UIView alloc]init]; // _userCodeView.backgroundColor = HexColorFromRGBA(0x000000,0.5); // _userCodeView.layer.cornerRadius = adapt(15)/2; // _userCodeView.layer.masksToBounds = YES; // _userCodeView.userInteractionEnabled = YES; WS(weakSelf) UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init]; [_userCodeView addGestureRecognizer:tap]; [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [weakSelf.viewModel copyUserId]; }]; } return _userCodeView; } - (UIImageView *)userCodeIcon { if (!_userCodeIcon) { _userCodeIcon = [[UIImageView alloc] init]; _userCodeIcon.hidden = YES; _userCodeIcon.image = ImageByName(@"ym_mine_id_icon"); } return _userCodeIcon; } - (UILabel *)userCodeLb{ if (!_userCodeLb) { _userCodeLb = [[UILabel alloc]init]; _userCodeLb.font = [UIFont systemFontOfSize:12]; _userCodeLb.textColor = HexColorFromRGBA(0xFFFFFF, 1); _userCodeLb.textAlignment = NSTextAlignmentLeft; _userCodeLb.text = @"ID:***"; } return _userCodeLb; } - (UIImageView *)userCodeCopyIcon{ if (!_userCodeCopyIcon) { _userCodeCopyIcon = [[UIImageView alloc]init]; //_userCodeCopyIcon.image = [UIImage systemImageNamed:@"doc.on.doc"]; _userCodeCopyIcon.image = ImageByName(@"ym_mine_copy_icon"); _userCodeCopyIcon.tintColor = HexColorFromRGB(0xFFFFFF); //_userCodeCopyIcon.preferredSymbolConfiguration = [UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightMedium]; } return _userCodeCopyIcon; } - (UILabel *)userIntroLb{ if (!_userIntroLb) { _userIntroLb = [[UILabel alloc]init]; _userIntroLb.font = LCFont(10); _userIntroLb.textColor = HexColorFromRGBA(0xFFFFFF, 0.8); _userIntroLb.textAlignment = NSTextAlignmentCenter; _userIntroLb.text = @"这个人很懒,什么都没有留下..."; _userIntroLb.numberOfLines = 3; } return _userIntroLb; } - (UIButton *)editProfileBtn{ if (!_editProfileBtn) { _editProfileBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _editProfileBtn.hidden = NO; //[_editProfileBtn setImage:ImageByName(@"ym_mine_edit_profile") forState:UIControlStateNormal]; _editProfileBtn.titleLabel.font = LCFont(12); [_editProfileBtn setTitle:@"编辑资料" forState:UIControlStateNormal]; [_editProfileBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal]; [_editProfileBtn setImage:ImageByName(@"vqu_images_ic_profile_edit_arrow") forState:UIControlStateNormal]; _editProfileBtn.backgroundColor = HexColorFromRGBA(0x000000, 0.3); _editProfileBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; [_editProfileBtn setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft]; CGFloat margin = 3; _editProfileBtn.imageEdgeInsets = UIEdgeInsetsMake(0, margin, 0, -margin); CAShapeLayer *shapeLayer = [CAShapeLayer layer]; shapeLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, adapt(80), adapt(28)) byRoundingCorners: UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:CGSizeMake(adapt(14),adapt(14))].CGPath; _editProfileBtn.layer.mask = shapeLayer; WS(weakSelf) [[[_editProfileBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) { [weakSelf.viewModel gotoEditProfile]; }]; } return _editProfileBtn; } - (BAGridView_Config *)quantityInfoGridViewConfig{ if (!_quantityInfoGridViewConfig) { _quantityInfoGridViewConfig = [[BAGridView_Config alloc]init]; _quantityInfoGridViewConfig.scrollEnabled = NO; // 是否显示分割线 _quantityInfoGridViewConfig.showLineView = NO; // item:分割线颜色,默认:BAKit_Color_Gray_11【BAKit_Color_RGB(248, 248, 248)】 _quantityInfoGridViewConfig.ba_gridView_lineColor = HexColorFromRGB(0xededed); // item:每行 item 的个数 _quantityInfoGridViewConfig.ba_gridView_rowCount = kQuantityInfoGridView_rowCount; // item:高度/宽度 _quantityInfoGridViewConfig.ba_gridView_itemHeight = kQuantityInfoGridView_itemHeight; // item:title 颜色,默认:BAKit_Color_Black【[UIColor blackColor]】 _quantityInfoGridViewConfig.ba_gridView_titleColor = UIColor.whiteColor; _quantityInfoGridViewConfig.ba_gridView_titleDescColor = UIColor.whiteColor; // item:title Font,默认:图文样式下 16,两行文字下(上25,下12) _quantityInfoGridViewConfig.ba_gridView_titleFont = LCBoldFont(18); _quantityInfoGridViewConfig.ba_gridView_titleDescFont = LCFont(12); // item:背景颜色,默认:白色 _quantityInfoGridViewConfig.ba_gridView_backgroundColor = BAKit_Color_Clear_pod; // item:背景选中颜色,默认:无色 _quantityInfoGridViewConfig.ba_gridView_selectedBackgroundColor = BAKit_Color_Clear_pod; // badge _quantityInfoGridViewConfig.ba_gridView_badgeType = kBAGridViewBadgeType_Center; _quantityInfoGridViewConfig.ba_gridView_badgeFont = LCFont(10); _quantityInfoGridViewConfig.ba_gridView_badgeRectCorners = UIRectCornerTopLeft | UIRectCornerTopRight |UIRectCornerBottomLeft| UIRectCornerBottomRight; _quantityInfoGridViewConfig.ba_gridView_badgeCornerRadius = 7; _quantityInfoGridViewConfig.ba_gridView_badgeBgColor = HexColorFromRGB(0xF4003F); _quantityInfoGridViewConfig.ba_gridView_badgeTextColor = HexColorFromRGB(0xFFFFFF); _quantityInfoGridViewConfig.ba_gridView_badgeHeight = 14; _quantityInfoGridViewConfig.ba_gridView_badgeOffsetPoint = CGPointMake(8, 8); // _quantityInfoGridViewConfig.ba_gridView_itemEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10); // _quantityInfoGridViewConfig.minimumLineSpacing = 10; // _quantityInfoGridViewConfig.minimumInteritemSpacing = 10; _quantityInfoGridViewConfig.gridViewType = BAGridViewTypeTitleDesc; } return _quantityInfoGridViewConfig; } - (BAGridView *)quantityInfoGridView{ if (!_quantityInfoGridView) { @weakify(self) _quantityInfoGridView = [BAGridView ba_creatGridViewWithGridViewConfig:self.quantityInfoGridViewConfig block:^(BAGridItemModel *model, NSIndexPath *indexPath) { @strongify(self) [self.viewModel.quantityInfoOperationSubject sendNext:@(self.viewModel.quantityInfoGridDataArray[indexPath.row].infoType)]; }]; } return _quantityInfoGridView; } @end