RQVipSinglePriceCell.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // RQVipSinglePriceCell.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/3/1.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQVipSinglePriceCell.h"
  9. @interface RQVipSinglePriceCell ()
  10. @property (nonatomic, readwrite, strong) RQVipSinglePriceItemViewModel *viewModel;
  11. @property (weak, nonatomic) IBOutlet UIImageView *myBgView;
  12. @property (weak, nonatomic) IBOutlet UIStackView *priceView;
  13. @property (weak, nonatomic) IBOutlet UILabel *nowPriceLabel;
  14. @property (weak, nonatomic) IBOutlet UILabel *oldPriceLabel;
  15. @property (weak, nonatomic) IBOutlet UILabel *myTitleLabel;
  16. @property (weak, nonatomic) IBOutlet UILabel *saveMoneyLabel;
  17. @property (weak, nonatomic) IBOutlet UIImageView *saveMoneyLabelBgImageView;
  18. @property (weak, nonatomic) IBOutlet UIImageView *selectImageView;
  19. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *selectImgTopToBgView;
  20. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *selectImgLeadingToBgView;
  21. @end
  22. @implementation RQVipSinglePriceCell
  23. #pragma mark - PublicMethods
  24. + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
  25. static NSString *ID = @"RQVipSinglePriceCell";
  26. [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
  27. RQVipSinglePriceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
  28. if (!cell) cell = [self rq_viewFromXib];
  29. return cell;
  30. }
  31. - (void)bindViewModel:(RQVipSinglePriceItemViewModel *)viewModel {
  32. _viewModel = viewModel;
  33. @weakify(self)
  34. [[[RACObserve(viewModel, isSelect) takeUntil:self.rac_prepareForReuseSignal] distinctUntilChanged] subscribeNext:^(id _Nullable x) {
  35. @strongify(self)
  36. if (viewModel.isSelect) {
  37. self.selectImageView.hidden = NO;
  38. self.myBgView.image = [UIImage imageWithQQCorner:^(QQCorner *corner) {
  39. corner.radius = QQRadiusMake(10, 25, 10, 10);
  40. corner.borderColor = [UIColor qmui_colorWithHexString:@"#FF944D"];
  41. corner.borderWidth = 4;
  42. corner.fillColor = [UIColor qmui_colorWithHexString:@"#FFEFD8"];
  43. } size:self.myBgView.bounds.size];
  44. self.saveMoneyLabelBgImageView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  45. graColor.fromColor = [UIColor qmui_colorWithHexString:@"#FC9652"];
  46. graColor.toColor = [UIColor qmui_colorWithHexString:@"#FFBE5D"];
  47. graColor.type = QQGradualChangeTypeLeftToRight;
  48. } QQCorner:^(QQCorner *corner) {
  49. corner.radius = QQRadiusMake(0, 0, 10, 10);
  50. corner.borderColor = [UIColor qmui_colorWithHexString:@"#FF944D"];
  51. corner.borderWidth = 4;
  52. corner.borderPosition = QMUIImageBorderPositionLeft|QMUIImageBorderPositionBottom|QMUIImageBorderPositionRight;
  53. } size:self.saveMoneyLabelBgImageView.bounds.size cornerRadius:QQRadiusMake(0, 0, 10, 10)];
  54. } else {
  55. self.selectImageView.hidden = YES;
  56. self.myBgView.image = [UIImage imageWithQQCorner:^(QQCorner *corner) {
  57. corner.radius = QQRadiusMake(10, 25, 10, 10);
  58. corner.borderColor = [UIColor qmui_colorWithHexString:@"#E0B279"];
  59. corner.borderWidth = 2;
  60. corner.fillColor = [UIColor qmui_colorWithHexString:@"#FEF6EC"];
  61. } size:self.myBgView.bounds.size];
  62. self.saveMoneyLabelBgImageView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  63. graColor.fromColor = [UIColor qmui_colorWithHexString:@"#DBA05C"];
  64. graColor.toColor = [UIColor qmui_colorWithHexString:@"#F3C085"];
  65. graColor.type = QQGradualChangeTypeLeftToRight;
  66. } QQCorner:^(QQCorner *corner) {
  67. corner.radius = QQRadiusMake(0, 0, 10, 10);
  68. corner.borderColor = [UIColor qmui_colorWithHexString:@"#E0B279"];
  69. corner.borderWidth = 2;
  70. corner.borderPosition = QMUIImageBorderPositionLeft|QMUIImageBorderPositionBottom|QMUIImageBorderPositionRight;
  71. } size:self.saveMoneyLabelBgImageView.bounds.size cornerRadius:QQRadiusMake(0, 0, 10, 10)];
  72. }
  73. }];
  74. _myTitleLabel.text = viewModel.typeModel.dictLabel;
  75. NSString *nowPriceStr;
  76. NSString *oldPriceStr;
  77. if (RQStringIsNotEmpty(viewModel.typeModel.dictValue) && [viewModel.typeModel.dictValue containsString:@","]) {
  78. nowPriceStr = [viewModel.typeModel.dictValue componentsSeparatedByString:@","].firstObject;
  79. if ([viewModel.typeModel.dictValue componentsSeparatedByString:@","].count >= 2) {
  80. oldPriceStr = [viewModel.typeModel.dictValue componentsSeparatedByString:@","][1];
  81. } else {
  82. oldPriceStr = @"";
  83. }
  84. } else {
  85. nowPriceStr = viewModel.typeModel.dictValue;
  86. oldPriceStr = viewModel.typeModel.dictValue;
  87. }
  88. _saveMoneyLabel.text = [NSString stringWithFormat:@"立省%.f元",[oldPriceStr floatValue] - [nowPriceStr floatValue]];
  89. NSString *str = [NSString stringWithFormat:@"原价%@元",oldPriceStr];
  90. NSDictionary *attrDic = @{
  91. NSStrikethroughStyleAttributeName: @(1),
  92. NSFontAttributeName : [UIFont systemFontOfSize:13],
  93. NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)
  94. };
  95. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str attributes:attrDic];
  96. _oldPriceLabel.attributedText = attrStr;
  97. _oldPriceLabel.hidden = [nowPriceStr isEqualToString:oldPriceStr];
  98. NSString *nowPrice = [NSString stringWithFormat:@"¥%@",nowPriceStr];
  99. NSString *year = [NSString stringWithFormat:[viewModel.typeModel.dictLabel isEqualToString:@"理论实操计时"]? @"/长期" : @"/1年"];
  100. NSString *price = [NSString stringWithFormat:@"%@%@",nowPrice,year];
  101. NSMutableAttributedString *nowPriceAttrStr = [[NSMutableAttributedString alloc] initWithString:price];
  102. [nowPriceAttrStr addAttribute:NSFontAttributeName value:RQSemiboldFont(32) range:[price rangeOfString:nowPrice]];
  103. [nowPriceAttrStr addAttribute:NSFontAttributeName value:RQRegularFont_18 range:[price rangeOfString:year]];
  104. [nowPriceAttrStr addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_2 range:[price rangeOfString:year]];
  105. _nowPriceLabel.attributedText = nowPriceAttrStr;
  106. }
  107. #pragma mark - SystemMethods
  108. - (void)awakeFromNib {
  109. [super awakeFromNib];
  110. self.myBgView.image = [UIImage imageWithQQCorner:^(QQCorner *corner) {
  111. corner.radius = QQRadiusMake(10, 25, 10, 10);
  112. corner.borderColor = [UIColor qmui_colorWithHexString:@"#E0B279"];
  113. corner.borderWidth = 2;
  114. corner.fillColor = [UIColor qmui_colorWithHexString:@"#FEF6EC"];
  115. } size:self.myBgView.bounds.size];
  116. self.saveMoneyLabelBgImageView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  117. graColor.fromColor = [UIColor qmui_colorWithHexString:@"#DBA05C"];
  118. graColor.toColor = [UIColor qmui_colorWithHexString:@"#F3C085"];
  119. graColor.type = QQGradualChangeTypeLeftToRight;
  120. } QQCorner:^(QQCorner *corner) {
  121. corner.radius = QQRadiusMake(0, 0, 10, 10);
  122. corner.borderColor = [UIColor qmui_colorWithHexString:@"#E0B279"];
  123. corner.borderWidth = 2;
  124. corner.borderPosition = QMUIImageBorderPositionLeft|QMUIImageBorderPositionBottom|QMUIImageBorderPositionRight;
  125. } size:self.saveMoneyLabelBgImageView.bounds.size cornerRadius:QQRadiusMake(0, 0, 10, 10)];
  126. self.selectImageView.hidden = YES;
  127. _selectImgLeadingToBgView.constant = - (RQ_FIT_HORIZONTAL(16.f) / 2.f) + 4;
  128. _selectImgTopToBgView.constant = - (RQ_FIT_HORIZONTAL(16.f) / 2.f) + 4;
  129. }
  130. #pragma mark - PrivateMethods
  131. #pragma mark - LazyLoad
  132. @end