ASGoodsTitlePriceCell.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // ASGoodsTitlePriceCell.m
  3. // Asteria
  4. //
  5. // Created by xingyu on 2024/5/20.
  6. //
  7. #import "ASGoodsTitlePriceCell.h"
  8. @interface ASGoodsTitlePriceCell()
  9. @property (nonatomic, strong) QMUILabel *titleLab;
  10. @property (nonatomic, strong) QMUILabel *soldLab;
  11. @property (nonatomic, strong) QMUILabel *reviewsLab;
  12. @property (nonatomic, strong) QMUILabel *priceLab;
  13. @property (nonatomic, strong) QMUILabel *saveLab;
  14. @end
  15. @implementation ASGoodsTitlePriceCell
  16. - (void)setupSubviewS{
  17. [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(setData) name:GoodsDetailsUpdatePrice object:nil];
  18. // self.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  19. [self.contentView addSubview:self.titleLab];
  20. [self.contentView addSubview:self.soldLab];
  21. [self.contentView addSubview:self.reviewsLab];
  22. [self.contentView addSubview:self.priceLab];
  23. [self.contentView addSubview:self.saveLab];
  24. [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.left.mas_equalTo(10);
  26. make.width.mas_equalTo(KScreenWidth-20);
  27. make.top.mas_equalTo(10);
  28. make.height.mas_lessThanOrEqualTo(45);
  29. }];
  30. [self.soldLab mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.left.mas_equalTo(10);
  32. make.height.mas_equalTo(16);
  33. make.top.equalTo(self.titleLab.mas_bottom).offset(10);
  34. }];
  35. [self.reviewsLab mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.right.equalTo(self.titleLab.mas_right);
  37. make.height.mas_equalTo(16);
  38. make.top.equalTo(self.titleLab.mas_bottom).offset(10);
  39. }];
  40. [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.mas_equalTo(10);
  42. make.top.equalTo(self.reviewsLab.mas_bottom).offset(20);
  43. make.height.mas_equalTo(24);
  44. make.bottom.mas_equalTo(-10);
  45. }];
  46. [self.saveLab mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.left.equalTo(self.priceLab.mas_right).offset(10);
  48. make.height.mas_equalTo(20);
  49. make.centerY.equalTo(self.priceLab);
  50. }];
  51. }
  52. - (void)setData {
  53. [self configData:self.infoModel];
  54. }
  55. - (void)configData:(id)Data{
  56. GoodsInformationM *model = (GoodsInformationM *)Data;
  57. _infoModel = model;
  58. self.titleLab.text =MM_str(model.name);
  59. self.soldLab.text = [NSString stringWithFormat:@"SOLD: %@",model.sold] ;
  60. NSMutableAttributedString *reviewsStr = [[NSMutableAttributedString alloc]
  61. initWithString:[NSString stringWithFormat:@"REVIEWS:%@",model.review_nums]];
  62. NSRange contentRange = {0,[reviewsStr length]};
  63. [reviewsStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
  64. self.reviewsLab.attributedText = reviewsStr;
  65. self.reviewsLab.textAlignment = NSTextAlignmentRight;
  66. //总价 (优惠前价格)
  67. NSString *noDiscountPrice = model.show_prices;
  68. if (!AS_String_valid(model.show_prices) || [model.show_prices isEqualToString:@"0"]) {
  69. noDiscountPrice = model.price;
  70. }
  71. NSString *discountPrice = model.show_final_prices;
  72. if (!AS_String_valid(model.show_final_prices) || [model.show_final_prices isEqualToString:@"0"]) {
  73. discountPrice = model.final_prices;
  74. }
  75. NSMutableAttributedString *priceAtr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",model.currency_symbol,discountPrice]];
  76. [priceAtr addAttribute: NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#0B0B0B"] range:NSMakeRange(0, priceAtr.length)];
  77. [priceAtr addAttribute:NSFontAttributeName value:[UIFont fontWithName:Rob_Bold size:20] range:NSMakeRange(0, priceAtr.length)];
  78. NSString *saveStr = @"";
  79. if(noDiscountPrice == discountPrice){
  80. self.saveLab.hidden = YES;
  81. }else{
  82. self.saveLab.hidden = NO;
  83. double savePrice = [noDiscountPrice doubleValue]-[discountPrice doubleValue];
  84. saveStr = [NSString stringWithFormat:@"Save %@%.2f",model.currency_symbol,savePrice];
  85. [priceAtr appendAttributedString:[[NSAttributedString alloc]initWithString:@" "]];
  86. NSMutableAttributedString *priceAtrSub1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",model.currency_symbol, noDiscountPrice]];
  87. [priceAtrSub1 addAttribute:NSForegroundColorAttributeName
  88. value:[UIColor colorWithHexString:@"#8c8c8c"]
  89. range:NSMakeRange(0, priceAtrSub1.length)];
  90. [priceAtrSub1 addAttribute:NSFontAttributeName
  91. value:[UIFont fontWithName:Rob_Regular size:14]
  92. range:NSMakeRange(0, priceAtrSub1.length)];
  93. [priceAtrSub1 addAttribute:NSStrikethroughStyleAttributeName
  94. value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
  95. range:NSMakeRange(0, priceAtrSub1.length)];
  96. [priceAtr appendAttributedString:priceAtrSub1];
  97. }
  98. self.priceLab.attributedText = priceAtr;
  99. self.infoModel.priceAtr = priceAtr;
  100. self.saveLab.text = saveStr;
  101. }
  102. -(void)tap_reviewsClick{
  103. if (self.currencyparameterClose) {
  104. self.currencyparameterClose(1, self.infoModel);
  105. }
  106. }
  107. - (QMUILabel *)titleLab {
  108. if (!_titleLab) {
  109. _titleLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  110. _titleLab.textAlignment = NSTextAlignmentLeft;
  111. _titleLab.numberOfLines = 2;
  112. _titleLab.textColor = [UIColor colorWithHexString:@"#000000"];
  113. _titleLab.font = [UIFont fontWithName:Rob_Bold size:16];
  114. }
  115. return _titleLab;
  116. }
  117. - (QMUILabel *)soldLab {
  118. if (!_soldLab) {
  119. _soldLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  120. _soldLab.textAlignment = NSTextAlignmentLeft;
  121. _soldLab.textColor = [UIColor colorWithHexString:@"#666666"];
  122. _soldLab.font = [UIFont systemFontOfSize:12];
  123. }
  124. return _soldLab;
  125. }
  126. - (QMUILabel *)reviewsLab {
  127. if (!_reviewsLab) {
  128. _reviewsLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  129. _reviewsLab.textAlignment = NSTextAlignmentRight;
  130. _reviewsLab.textColor = [UIColor colorWithHexString:@"#666666"];
  131. _reviewsLab.font = [UIFont fontWithName:Rob_Regular size:12];
  132. _reviewsLab.userInteractionEnabled = YES;
  133. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap_reviewsClick)];
  134. [_reviewsLab addGestureRecognizer:tap];
  135. // reviewsStr.underlineStyle = NSUnderlineStyleSingle;
  136. }
  137. return _reviewsLab;
  138. }
  139. - (QMUILabel *)priceLab {
  140. if (!_priceLab) {
  141. _priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  142. _priceLab.textAlignment = NSTextAlignmentLeft;
  143. _priceLab.textColor = [UIColor blackColor];
  144. _priceLab.font = [UIFont systemFontOfSize:18];
  145. }
  146. return _priceLab;
  147. }
  148. - (QMUILabel *)saveLab {
  149. if (!_saveLab) {
  150. _saveLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
  151. _saveLab.contentEdgeInsets= UIEdgeInsetsMake(10, 10, 10, 10);
  152. _saveLab.backgroundColor = [UIColor colorWithHexString:@"#E0FFF5"];
  153. _saveLab.textAlignment = NSTextAlignmentCenter;
  154. _saveLab.textColor = [UIColor colorWithHexString:@"#113632"];
  155. _saveLab.font = [UIFont fontWithName:Rob_Bold size:12];
  156. }
  157. return _saveLab;
  158. }
  159. - (void)dealloc {
  160. [[NSNotificationCenter defaultCenter] removeObserver:self];
  161. }
  162. @end