// // NYLIVipPriceCell.m // jiaPei // // Created by Ning.ge on 2025/2/7. // Copyright © 2025 JCZ. All rights reserved. // #import "NYLIVipPriceCell.h" @interface NYLIVipPriceCell () @property (nonatomic, readwrite, strong) NYLIVipSinglePriceItemViewModel *viewModel; @property (weak, nonatomic) IBOutlet UIImageView *myBgView; @property (weak, nonatomic) IBOutlet UIStackView *priceView; @property (weak, nonatomic) IBOutlet UILabel *nowPriceLabel; @property (weak, nonatomic) IBOutlet UILabel *oldPriceLabel; @property (weak, nonatomic) IBOutlet UILabel *myTitleLabel; @property (weak, nonatomic) IBOutlet UILabel *saveMoneyLabel; @property (weak, nonatomic) IBOutlet UIImageView *saveMoneyLabelBgImageView; @property (weak, nonatomic) IBOutlet UIButton *recommendBtn; @end @implementation NYLIVipPriceCell #pragma mark - PublicMethods + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"NYLIVipPriceCell"; [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID]; NYLIVipPriceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath]; if (!cell) cell = [self rq_viewFromXib]; return cell; } - (void)bindViewModel:(NYLIVipSinglePriceItemViewModel *)viewModel { _viewModel = viewModel; @weakify(self) [[[RACObserve(viewModel, isSelect) takeUntil:self.rac_prepareForReuseSignal] distinctUntilChanged] subscribeNext:^(id _Nullable x) { @strongify(self) if (viewModel.isSelect) { self.myBgView.image = [UIImage imageWithQQCorner:^(QQCorner *corner) { corner.radius = QQRadiusMake(10, 25, 10, 10); corner.borderColor = [UIColor qmui_colorWithHexString:@"#498EF5"]; corner.borderWidth = 4; corner.fillColor = [UIColor qmui_colorWithHexString:@"#E6F0FF"]; } size:self.myBgView.bounds.size]; self.saveMoneyLabelBgImageView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) { graColor.fromColor = [UIColor qmui_colorWithHexString:@"#4C99E0"]; graColor.toColor = [UIColor qmui_colorWithHexString:@"#70B7F3"]; graColor.type = QQGradualChangeTypeLeftToRight; } QQCorner:^(QQCorner *corner) { corner.radius = QQRadiusMake(0, 0, 10, 10); corner.borderColor = [UIColor qmui_colorWithHexString:@"#4C99E0"]; corner.borderWidth = 4; corner.borderPosition = QMUIImageBorderPositionLeft|QMUIImageBorderPositionBottom|QMUIImageBorderPositionRight; } size:self.saveMoneyLabelBgImageView.bounds.size cornerRadius:QQRadiusMake(0, 0, 10, 10)]; self.saveMoneyLabel.textColor = RQColorFromHexString(@"#FFFFFF"); _nowPriceLabel.textColor = RQColorFromHexString(@"#EE2A2C"); } else { self.myBgView.image = [UIImage imageWithQQCorner:^(QQCorner *corner) { corner.radius = QQRadiusMake(10, 25, 10, 10); corner.borderColor = [UIColor qmui_colorWithHexString:@"#D9D9D9"]; corner.borderWidth = 2; corner.fillColor = [UIColor qmui_colorWithHexString:@"#FFFFFF"]; } size:self.myBgView.bounds.size]; self.saveMoneyLabelBgImageView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) { graColor.fromColor = [UIColor qmui_colorWithHexString:@"#E6F0FF"]; graColor.toColor = [UIColor qmui_colorWithHexString:@"#E6F0FF"]; graColor.type = QQGradualChangeTypeLeftToRight; } QQCorner:^(QQCorner *corner) { corner.radius = QQRadiusMake(0, 0, 10, 10); corner.borderColor = [UIColor qmui_colorWithHexString:@"#D9D9D9"]; corner.borderWidth = 2; corner.borderPosition = QMUIImageBorderPositionLeft|QMUIImageBorderPositionBottom|QMUIImageBorderPositionRight; } size:self.saveMoneyLabelBgImageView.bounds.size cornerRadius:QQRadiusMake(0, 0, 10, 10)]; self.saveMoneyLabel.textColor = RQColorFromHexString(@"#203C65"); _nowPriceLabel.textColor = RQColorFromHexString(@"#203C65"); } }]; _myTitleLabel.text = viewModel.typeModel.dictLabel; NSString *nowPriceStr; NSString *oldPriceStr; if (RQStringIsNotEmpty(viewModel.typeModel.dictValue) && [viewModel.typeModel.dictValue containsString:@","]) { nowPriceStr = [viewModel.typeModel.dictValue componentsSeparatedByString:@","].firstObject; if ([viewModel.typeModel.dictValue componentsSeparatedByString:@","].count >= 2) { oldPriceStr = [viewModel.typeModel.dictValue componentsSeparatedByString:@","][1]; } else { oldPriceStr = @""; } } else { nowPriceStr = viewModel.typeModel.dictValue; oldPriceStr = viewModel.typeModel.dictValue; } NSString *str = [NSString stringWithFormat:@"各科单独买¥%@元",oldPriceStr]; NSDictionary *attrDic = @{ NSStrikethroughStyleAttributeName: @(1), NSFontAttributeName : [UIFont systemFontOfSize:10], NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle) }; NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str attributes:attrDic]; _oldPriceLabel.attributedText = attrStr; // _oldPriceLabel.hidden = [nowPriceStr isEqualToString:oldPriceStr]; NSString *nowPrice = [NSString stringWithFormat:@"¥%@",nowPriceStr]; NSString *year = [NSString stringWithFormat:@"/1年"]; NSString *price = [NSString stringWithFormat:@"%@%@",nowPrice,year]; NSMutableAttributedString *nowPriceAttrStr = [[NSMutableAttributedString alloc] initWithString:price]; [nowPriceAttrStr addAttribute:NSFontAttributeName value:RQSemiboldFont(32) range:[price rangeOfString:nowPrice]]; [nowPriceAttrStr addAttribute:NSFontAttributeName value:RQRegularFont_15 range:[price rangeOfString:year]]; // [nowPriceAttrStr addAttribute:NSForegroundColorAttributeName value:[UIColor qmui_colorWithHexString:@"#D9D9D9"] range:[price rangeOfString:year]]; _nowPriceLabel.attributedText = nowPriceAttrStr; self.recommendBtn.hidden = ![viewModel.typeModel.dictLabel containsString:@"科一科四特训包"]; self.oldPriceLabel.hidden = ![viewModel.typeModel.dictLabel containsString:@"科一科四特训包"]; } #pragma mark - SystemMethods - (void)awakeFromNib { [super awakeFromNib]; self.myBgView.image = [UIImage imageWithQQCorner:^(QQCorner *corner) { corner.radius = QQRadiusMake(10, 25, 10, 10); corner.borderColor = [UIColor qmui_colorWithHexString:@"#D9D9D9"]; corner.borderWidth = 2; corner.fillColor = [UIColor qmui_colorWithHexString:@"#FFFFFF"]; } size:self.myBgView.bounds.size]; self.saveMoneyLabelBgImageView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) { graColor.fromColor = [UIColor qmui_colorWithHexString:@"#E6F0FF"]; graColor.toColor = [UIColor qmui_colorWithHexString:@"#E6F0FF"]; graColor.type = QQGradualChangeTypeLeftToRight; } QQCorner:^(QQCorner *corner) { corner.radius = QQRadiusMake(0, 0, 10, 10); corner.borderColor = [UIColor qmui_colorWithHexString:@"#D9D9D9"]; corner.borderWidth = 2; corner.borderPosition = QMUIImageBorderPositionLeft|QMUIImageBorderPositionBottom|QMUIImageBorderPositionRight; } size:self.saveMoneyLabelBgImageView.bounds.size cornerRadius:QQRadiusMake(0, 0, 10, 10)]; [_recommendBtn setBackgroundImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) { graColor.fromColor = [UIColor qmui_colorWithHexString:@"#498EF5"]; graColor.toColor = [UIColor qmui_colorWithHexString:@"#4DA8E6"]; graColor.type = QQGradualChangeTypeLeftToRight; } size:_recommendBtn.bounds.size cornerRadius:QQRadiusMake(10, 2, 2, 10)] forState:UIControlStateNormal]; } @end