123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- //
- // RQVipSinglePriceCell.m
- // jiaPei
- //
- // Created by 张嵘 on 2022/3/1.
- // Copyright © 2022 JCZ. All rights reserved.
- //
- #import "RQVipSinglePriceCell.h"
- @interface RQVipSinglePriceCell ()
- @property (nonatomic, readwrite, strong) RQVipSinglePriceItemViewModel *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 UIImageView *selectImageView;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *selectImgTopToBgView;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *selectImgLeadingToBgView;
- @end
- @implementation RQVipSinglePriceCell
- #pragma mark - PublicMethods
- + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
- static NSString *ID = @"RQVipSinglePriceCell";
- [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
- RQVipSinglePriceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
- if (!cell) cell = [self rq_viewFromXib];
- return cell;
- }
- - (void)bindViewModel:(RQVipSinglePriceItemViewModel *)viewModel {
- _viewModel = viewModel;
- @weakify(self)
- [[[RACObserve(viewModel, isSelect) takeUntil:self.rac_prepareForReuseSignal] distinctUntilChanged] subscribeNext:^(id _Nullable x) {
- @strongify(self)
- if (viewModel.isSelect) {
- self.selectImageView.hidden = NO;
- self.myBgView.image = [UIImage imageWithQQCorner:^(QQCorner *corner) {
- corner.radius = QQRadiusMake(10, 25, 10, 10);
- corner.borderColor = [UIColor qmui_colorWithHexString:@"#FF944D"];
- corner.borderWidth = 4;
- corner.fillColor = [UIColor qmui_colorWithHexString:@"#FFEFD8"];
- } size:self.myBgView.bounds.size];
-
- self.saveMoneyLabelBgImageView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
- graColor.fromColor = [UIColor qmui_colorWithHexString:@"#FC9652"];
- graColor.toColor = [UIColor qmui_colorWithHexString:@"#FFBE5D"];
- graColor.type = QQGradualChangeTypeLeftToRight;
- } QQCorner:^(QQCorner *corner) {
- corner.radius = QQRadiusMake(0, 0, 10, 10);
- corner.borderColor = [UIColor qmui_colorWithHexString:@"#FF944D"];
- corner.borderWidth = 4;
- corner.borderPosition = QMUIImageBorderPositionLeft|QMUIImageBorderPositionBottom|QMUIImageBorderPositionRight;
- } size:self.saveMoneyLabelBgImageView.bounds.size cornerRadius:QQRadiusMake(0, 0, 10, 10)];
- } else {
- self.selectImageView.hidden = YES;
- self.myBgView.image = [UIImage imageWithQQCorner:^(QQCorner *corner) {
- corner.radius = QQRadiusMake(10, 25, 10, 10);
- corner.borderColor = [UIColor qmui_colorWithHexString:@"#E0B279"];
- corner.borderWidth = 2;
- corner.fillColor = [UIColor qmui_colorWithHexString:@"#FEF6EC"];
- } size:self.myBgView.bounds.size];
- self.saveMoneyLabelBgImageView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
- graColor.fromColor = [UIColor qmui_colorWithHexString:@"#DBA05C"];
- graColor.toColor = [UIColor qmui_colorWithHexString:@"#F3C085"];
- graColor.type = QQGradualChangeTypeLeftToRight;
- } QQCorner:^(QQCorner *corner) {
- corner.radius = QQRadiusMake(0, 0, 10, 10);
- corner.borderColor = [UIColor qmui_colorWithHexString:@"#E0B279"];
- corner.borderWidth = 2;
- corner.borderPosition = QMUIImageBorderPositionLeft|QMUIImageBorderPositionBottom|QMUIImageBorderPositionRight;
- } size:self.saveMoneyLabelBgImageView.bounds.size cornerRadius:QQRadiusMake(0, 0, 10, 10)];
- }
- }];
-
- _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;
- }
-
- _saveMoneyLabel.text = [NSString stringWithFormat:@"立省%.f元",[oldPriceStr floatValue] - [nowPriceStr floatValue]];
-
- NSString *str = [NSString stringWithFormat:@"原价%@元",oldPriceStr];
- NSDictionary *attrDic = @{
- NSStrikethroughStyleAttributeName: @(1),
- NSFontAttributeName : [UIFont systemFontOfSize:13],
- 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:[viewModel.typeModel.dictLabel isEqualToString:@"理论实操计时"]? @"/长期" : @"/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_18 range:[price rangeOfString:year]];
- [nowPriceAttrStr addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_2 range:[price rangeOfString:year]];
- _nowPriceLabel.attributedText = nowPriceAttrStr;
- }
- #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:@"#E0B279"];
- corner.borderWidth = 2;
- corner.fillColor = [UIColor qmui_colorWithHexString:@"#FEF6EC"];
- } size:self.myBgView.bounds.size];
-
- self.saveMoneyLabelBgImageView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
- graColor.fromColor = [UIColor qmui_colorWithHexString:@"#DBA05C"];
- graColor.toColor = [UIColor qmui_colorWithHexString:@"#F3C085"];
- graColor.type = QQGradualChangeTypeLeftToRight;
- } QQCorner:^(QQCorner *corner) {
- corner.radius = QQRadiusMake(0, 0, 10, 10);
- corner.borderColor = [UIColor qmui_colorWithHexString:@"#E0B279"];
- corner.borderWidth = 2;
- corner.borderPosition = QMUIImageBorderPositionLeft|QMUIImageBorderPositionBottom|QMUIImageBorderPositionRight;
- } size:self.saveMoneyLabelBgImageView.bounds.size cornerRadius:QQRadiusMake(0, 0, 10, 10)];
-
- self.selectImageView.hidden = YES;
- _selectImgLeadingToBgView.constant = - (RQ_FIT_HORIZONTAL(16.f) / 2.f) + 4;
- _selectImgTopToBgView.constant = - (RQ_FIT_HORIZONTAL(16.f) / 2.f) + 4;
-
- }
- #pragma mark - PrivateMethods
- #pragma mark - LazyLoad
- @end
|