// // YMMyEarningsInfoView.m // MSYOUPAI // // Created by YoMi on 2024/2/29. // Copyright © 2024 MS. All rights reserved. // #import "YMMyEarningsInfoView.h" #import "YMMyEarningsViewModel.h" @interface YMMyEarningsInfoView () /// 我的收益VM @property (nonatomic, strong) YMMyEarningsViewModel *viewModel; /// 圆角视图 @property (nonatomic, strong) UIView *roundedCornerView; /// 信息背景图 @property (nonatomic, strong) UIImageView *infoBgView; /// 用户剩余金币标签 @property (nonatomic, strong) UILabel *userRemainingPointsLb; /// 用户收益名称标签 @property (nonatomic, strong) UILabel *userEarningsNameLb; @property (nonatomic, strong) UIImageView *userBalanceIcon; ///// 今日收益视图 //@property (nonatomic, strong) UIView *userTodayEarningsView; ///// 今日收益图标 //@property (nonatomic, strong) UIImageView *userTodayEarningsIcon; ///// 今日收益标题标签 //@property (nonatomic, strong) UILabel *userTodayEarningsTitleLb; ///// 今日收益内容标签 //@property (nonatomic, strong) UILabel *userTodayEarningsContentLb; // ///// 七日收益视图 //@property (nonatomic, strong) UIView *userSevenDayEarningsView; ///// 七日收益图标 //@property (nonatomic, strong) UIImageView *userSevenDayEarningsIcon; ///// 七日收益标题标签 //@property (nonatomic, strong) UILabel *userSevenDayEarningsTitleLb; ///// 七日收益内容标签 //@property (nonatomic, strong) UILabel *userSevenDayEarningsContentLb; @end @implementation YMMyEarningsInfoView - (void)ym_setupViews{ [self addSubview:self.roundedCornerView]; [self addSubview:self.infoBgView]; [self.infoBgView addSubview:self.userEarningsNameLb]; [self.infoBgView addSubview:self.userBalanceIcon]; [self.infoBgView addSubview:self.userRemainingPointsLb]; [self.infoBgView addSubview:self.incomeBreakdownBtn]; // [self.infoBgView addSubview:self.userTodayEarningsView]; // [self.userTodayEarningsView addSubview:self.userTodayEarningsIcon]; // [self.userTodayEarningsView addSubview:self.userTodayEarningsTitleLb]; // [self.userTodayEarningsView addSubview:self.userTodayEarningsContentLb]; // // [self.infoBgView addSubview:self.userSevenDayEarningsView]; // [self.userSevenDayEarningsView addSubview:self.userSevenDayEarningsIcon]; // [self.userSevenDayEarningsView addSubview:self.userSevenDayEarningsTitleLb]; // [self.userSevenDayEarningsView addSubview:self.userSevenDayEarningsContentLb]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.roundedCornerView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self); make.right.equalTo(self); make.bottom.equalTo(self); make.height.mas_equalTo(adapt(70)); }]; [self.infoBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(adapt(12)); make.left.equalTo(self).offset(adapt(12)); make.right.equalTo(self).offset(adapt(-12)); make.bottom.equalTo(self); make.height.mas_equalTo(adapt(102)); }]; [self.userBalanceIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.infoBgView).offset(adapt(0)); make.left.equalTo(self.infoBgView.mas_left).offset(adapt(12)); make.width.mas_equalTo(adapt(46)); make.height.mas_equalTo(adapt(46)); }]; [self.userEarningsNameLb mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.userBalanceIcon.mas_centerY).offset(adapt(-5)); make.left.equalTo(self.userBalanceIcon.mas_right).offset(adapt(3)); }]; [self.userRemainingPointsLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.userEarningsNameLb.mas_bottom).offset(adapt(0)); make.left.equalTo(self.userBalanceIcon.mas_right).offset(adapt(3)); }]; [self.incomeBreakdownBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.infoBgView).offset(-adapt(20)); make.centerY.equalTo(self.infoBgView).offset(0); make.width.equalTo(adapt(88)); make.height.equalTo(adapt(30)); }]; // [self.userTodayEarningsView mas_makeConstraints:^(MASConstraintMaker *make) { // make.bottom.equalTo(self.infoBgView).offset(adapt(-10)); // make.left.equalTo(self.infoBgView).offset(adapt(40)); // }]; // // [self.userTodayEarningsTitleLb mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.userTodayEarningsView).offset(adapt(3)); // make.left.equalTo(self.userTodayEarningsView).offset(adapt(3)); // make.bottom.equalTo(self.userTodayEarningsView).offset(adapt(-3)); // }]; // // [self.userTodayEarningsIcon mas_makeConstraints:^(MASConstraintMaker *make) { // make.centerY.equalTo(self.userTodayEarningsView.mas_centerY); // make.left.equalTo(self.userTodayEarningsTitleLb.mas_right).offset(adapt(3)); // make.width.height.mas_equalTo(adapt(15)); // }]; // // [self.userTodayEarningsContentLb mas_makeConstraints:^(MASConstraintMaker *make) { // make.centerY.equalTo(self.userTodayEarningsView.mas_centerY); // make.left.equalTo(self.userTodayEarningsIcon.mas_right).offset(adapt(3)); // make.right.equalTo(self.userTodayEarningsView).offset(adapt(-3)); // }]; // // [self.userSevenDayEarningsView mas_makeConstraints:^(MASConstraintMaker *make) { // make.bottom.equalTo(self.infoBgView).offset(adapt(-10)); // make.right.equalTo(self.infoBgView).offset(adapt(-40)); // }]; // // [self.userSevenDayEarningsTitleLb mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.userSevenDayEarningsView).offset(adapt(3)); // make.left.equalTo(self.userSevenDayEarningsView).offset(adapt(3)); // make.bottom.equalTo(self.userSevenDayEarningsView).offset(adapt(-3)); // }]; // // [self.userSevenDayEarningsIcon mas_makeConstraints:^(MASConstraintMaker *make) { // make.centerY.equalTo(self.userSevenDayEarningsView.mas_centerY); // make.left.equalTo(self.userSevenDayEarningsTitleLb.mas_right).offset(adapt(3)); // make.width.height.mas_equalTo(adapt(15)); // }]; // // [self.userSevenDayEarningsContentLb mas_makeConstraints:^(MASConstraintMaker *make) { // make.centerY.equalTo(self.userSevenDayEarningsView.mas_centerY); // make.left.equalTo(self.userSevenDayEarningsIcon.mas_right).offset(adapt(3)); // make.right.equalTo(self.userSevenDayEarningsView).offset(adapt(-3)); // }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMMyEarningsViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; @weakify(self) [[[[RACObserve(self.viewModel, userRemainingPoints) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * userRemainingPoints) { @strongify(self) self.userRemainingPointsLb.text = stringFormat(@"%.2f",[userRemainingPoints doubleValue]); }]; } - (UIView *)roundedCornerView{ if (!_roundedCornerView) { _roundedCornerView = [[UIView alloc]init]; _roundedCornerView.hidden = YES; _roundedCornerView.backgroundColor = UIColor.whiteColor; [_roundedCornerView addRectCorner:UIRectCornerTopLeft|UIRectCornerTopRight radius:adapt(20)]; } return _roundedCornerView; } - (UIImageView *)infoBgView{ if (!_infoBgView) { _infoBgView = [[UIImageView alloc]init]; _infoBgView.image = ImageByName(@"ym_my_earnings_info_bg_icon"); _infoBgView.layer.cornerRadius = adapt(16); _infoBgView.layer.masksToBounds = YES; _infoBgView.userInteractionEnabled = true; } return _infoBgView; } - (UILabel *)userRemainingPointsLb{ if (!_userRemainingPointsLb) { _userRemainingPointsLb = [[UILabel alloc]init]; _userRemainingPointsLb.font = LCBoldFont(24); _userRemainingPointsLb.textColor = HexColorFromRGB(0x333333); _userRemainingPointsLb.textAlignment = NSTextAlignmentLeft; _userRemainingPointsLb.text = @"******"; } return _userRemainingPointsLb; } - (UILabel *)userEarningsNameLb{ if (!_userEarningsNameLb) { _userEarningsNameLb = [[UILabel alloc]init]; _userEarningsNameLb.font = LCFont(12); _userEarningsNameLb.textColor = HexColorFromRGB(0x333333); _userEarningsNameLb.textAlignment = NSTextAlignmentLeft; _userEarningsNameLb.text = @"我的金币"; } return _userEarningsNameLb; } - (UIImageView *)userBalanceIcon{ if (!_userBalanceIcon) { _userBalanceIcon = [[UIImageView alloc]init]; _userBalanceIcon.image = ImageByName(@"ym_my_earnings_coin"); } return _userBalanceIcon; } - (UIButton *)incomeBreakdownBtn { if (!_incomeBreakdownBtn) { _incomeBreakdownBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _incomeBreakdownBtn.titleLabel.font = LCFont(13); [_incomeBreakdownBtn setTitle:@"收支明细 " forState:UIControlStateNormal]; [_incomeBreakdownBtn setImage:ImageByName(@"ym_account_balance_go_detail") forState:(UIControlStateNormal)]; _incomeBreakdownBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; [_incomeBreakdownBtn setTitleColor:HexColorFromRGB(0x000000) forState:UIControlStateNormal]; _incomeBreakdownBtn.backgroundColor = HexColorFromRGB(0xF6F6F6); _incomeBreakdownBtn.layer.cornerRadius = adapt(15); _incomeBreakdownBtn.layer.masksToBounds = YES; WS(weakSelf) [[[_incomeBreakdownBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [weakSelf.viewModel gotoIncomeBreakdown]; }]; } return _incomeBreakdownBtn; } //- (UIView *)userTodayEarningsView{ // if (!_userTodayEarningsView) { // _userTodayEarningsView = [[UIView alloc]init]; // } // return _userTodayEarningsView; //} // //- (UILabel *)userTodayEarningsTitleLb{ // if (!_userTodayEarningsTitleLb) { // _userTodayEarningsTitleLb = [[UILabel alloc]init]; // _userTodayEarningsTitleLb.font = LCFont(12); // _userTodayEarningsTitleLb.textColor = HexColorFromRGB(0xFFFFFF); // _userTodayEarningsTitleLb.textAlignment = NSTextAlignmentLeft; // _userTodayEarningsTitleLb.text = @"今日收益:"; // } // return _userTodayEarningsTitleLb; //} // //- (UIImageView *)userTodayEarningsIcon{ // if (!_userTodayEarningsIcon) { // _userTodayEarningsIcon = [[UIImageView alloc]init]; // _userTodayEarningsIcon.image = ImageByName(@""); // } // return _userTodayEarningsIcon; //} // //- (UILabel *)userTodayEarningsContentLb{ // if (!_userTodayEarningsContentLb) { // _userTodayEarningsContentLb = [[UILabel alloc]init]; // _userTodayEarningsContentLb.font = LCBoldFont(13); // _userTodayEarningsContentLb.textColor = HexColorFromRGB(0xFFFFFF); // _userTodayEarningsContentLb.textAlignment = NSTextAlignmentLeft; // _userTodayEarningsContentLb.text = @"******"; // } // return _userTodayEarningsContentLb; //} // //- (UIView *)userSevenDayEarningsView{ // if (!_userSevenDayEarningsView) { // _userSevenDayEarningsView = [[UIView alloc]init]; // } // return _userSevenDayEarningsView; //} // //- (UILabel *)userSevenDayEarningsTitleLb{ // if (!_userSevenDayEarningsTitleLb) { // _userSevenDayEarningsTitleLb = [[UILabel alloc]init]; // _userSevenDayEarningsTitleLb.font = LCFont(12); // _userSevenDayEarningsTitleLb.textColor = HexColorFromRGB(0xFFFFFF); // _userSevenDayEarningsTitleLb.textAlignment = NSTextAlignmentLeft; // _userSevenDayEarningsTitleLb.text = @"七日收益:"; // } // return _userSevenDayEarningsTitleLb; //} // //- (UIImageView *)userSevenDayEarningsIcon{ // if (!_userSevenDayEarningsIcon) { // _userSevenDayEarningsIcon = [[UIImageView alloc]init]; // _userSevenDayEarningsIcon.image = ImageByName(@""); // } // return _userSevenDayEarningsIcon; //} // //- (UILabel *)userSevenDayEarningsContentLb{ // if (!_userSevenDayEarningsContentLb) { // _userSevenDayEarningsContentLb = [[UILabel alloc]init]; // _userSevenDayEarningsContentLb.font = LCBoldFont(13); // _userSevenDayEarningsContentLb.textColor = HexColorFromRGB(0xFFFFFF); // _userSevenDayEarningsContentLb.textAlignment = NSTextAlignmentLeft; // _userSevenDayEarningsContentLb.text = @"******"; // } // return _userSevenDayEarningsContentLb; //} @end