123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- //
- // ASGoodsTitlePriceCell.m
- // Asteria
- //
- // Created by xingyu on 2024/5/20.
- //
- #import "ASGoodsTitlePriceCell.h"
- @interface ASGoodsTitlePriceCell()
- @property (nonatomic, strong) QMUILabel *titleLab;
- @property (nonatomic, strong) QMUILabel *soldLab;
- @property (nonatomic, strong) QMUILabel *reviewsLab;
- @property (nonatomic, strong) QMUILabel *priceLab;
- @property (nonatomic, strong) QMUILabel *saveLab;
- @end
- @implementation ASGoodsTitlePriceCell
- - (void)setupSubviewS{
-
- [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(setData) name:GoodsDetailsUpdatePrice object:nil];
-
- // self.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
-
- [self.contentView addSubview:self.titleLab];
- [self.contentView addSubview:self.soldLab];
- [self.contentView addSubview:self.reviewsLab];
- [self.contentView addSubview:self.priceLab];
- [self.contentView addSubview:self.saveLab];
-
- [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.width.mas_equalTo(KScreenWidth-20);
- make.top.mas_equalTo(10);
- make.height.mas_lessThanOrEqualTo(45);
- }];
- [self.soldLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.height.mas_equalTo(16);
- make.top.equalTo(self.titleLab.mas_bottom).offset(10);
- }];
- [self.reviewsLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.titleLab.mas_right);
- make.height.mas_equalTo(16);
- make.top.equalTo(self.titleLab.mas_bottom).offset(10);
- }];
- [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.top.equalTo(self.reviewsLab.mas_bottom).offset(20);
- make.height.mas_equalTo(24);
- make.bottom.mas_equalTo(-10);
- }];
- [self.saveLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.priceLab.mas_right).offset(10);
- make.height.mas_equalTo(20);
- make.centerY.equalTo(self.priceLab);
- }];
-
-
- }
- - (void)setData {
- [self configData:self.infoModel];
- }
- - (void)configData:(id)Data{
- GoodsInformationM *model = (GoodsInformationM *)Data;
-
- _infoModel = model;
-
- self.titleLab.text =MM_str(model.name);
- self.soldLab.text = [NSString stringWithFormat:@"SOLD: %@",model.sold] ;
- NSMutableAttributedString *reviewsStr = [[NSMutableAttributedString alloc]
- initWithString:[NSString stringWithFormat:@"REVIEWS:%@",model.review_nums]];
- NSRange contentRange = {0,[reviewsStr length]};
- [reviewsStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
- self.reviewsLab.attributedText = reviewsStr;
- self.reviewsLab.textAlignment = NSTextAlignmentRight;
-
- //总价 (优惠前价格)
- NSString *noDiscountPrice = model.show_prices;
- if (!AS_String_valid(model.show_prices) || [model.show_prices isEqualToString:@"0"]) {
- noDiscountPrice = model.price;
- }
- NSString *discountPrice = model.show_final_prices;
- if (!AS_String_valid(model.show_final_prices) || [model.show_final_prices isEqualToString:@"0"]) {
- discountPrice = model.final_prices;
- }
-
- NSMutableAttributedString *priceAtr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",model.currency_symbol,discountPrice]];
- [priceAtr addAttribute: NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#0B0B0B"] range:NSMakeRange(0, priceAtr.length)];
- [priceAtr addAttribute:NSFontAttributeName value:[UIFont fontWithName:Rob_Bold size:20] range:NSMakeRange(0, priceAtr.length)];
- NSString *saveStr = @"";
- if(noDiscountPrice == discountPrice){
- self.saveLab.hidden = YES;
- }else{
- self.saveLab.hidden = NO;
- double savePrice = [noDiscountPrice doubleValue]-[discountPrice doubleValue];
- saveStr = [NSString stringWithFormat:@"Save %@%.2f",model.currency_symbol,savePrice];
- [priceAtr appendAttributedString:[[NSAttributedString alloc]initWithString:@" "]];
- NSMutableAttributedString *priceAtrSub1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",model.currency_symbol, noDiscountPrice]];
- [priceAtrSub1 addAttribute:NSForegroundColorAttributeName
- value:[UIColor colorWithHexString:@"#8c8c8c"]
- range:NSMakeRange(0, priceAtrSub1.length)];
- [priceAtrSub1 addAttribute:NSFontAttributeName
- value:[UIFont fontWithName:Rob_Regular size:14]
- range:NSMakeRange(0, priceAtrSub1.length)];
- [priceAtrSub1 addAttribute:NSStrikethroughStyleAttributeName
- value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
- range:NSMakeRange(0, priceAtrSub1.length)];
- [priceAtr appendAttributedString:priceAtrSub1];
- }
- self.priceLab.attributedText = priceAtr;
- self.infoModel.priceAtr = priceAtr;
- self.saveLab.text = saveStr;
- }
- -(void)tap_reviewsClick{
- if (self.currencyparameterClose) {
- self.currencyparameterClose(1, self.infoModel);
- }
- }
- - (QMUILabel *)titleLab {
- if (!_titleLab) {
- _titleLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
- _titleLab.textAlignment = NSTextAlignmentLeft;
- _titleLab.numberOfLines = 2;
- _titleLab.textColor = [UIColor colorWithHexString:@"#000000"];
- _titleLab.font = [UIFont fontWithName:Rob_Bold size:16];
- }
- return _titleLab;
- }
- - (QMUILabel *)soldLab {
- if (!_soldLab) {
- _soldLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
- _soldLab.textAlignment = NSTextAlignmentLeft;
- _soldLab.textColor = [UIColor colorWithHexString:@"#666666"];
- _soldLab.font = [UIFont systemFontOfSize:12];
- }
- return _soldLab;
- }
- - (QMUILabel *)reviewsLab {
- if (!_reviewsLab) {
- _reviewsLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
- _reviewsLab.textAlignment = NSTextAlignmentRight;
- _reviewsLab.textColor = [UIColor colorWithHexString:@"#666666"];
- _reviewsLab.font = [UIFont fontWithName:Rob_Regular size:12];
- _reviewsLab.userInteractionEnabled = YES;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap_reviewsClick)];
- [_reviewsLab addGestureRecognizer:tap];
- // reviewsStr.underlineStyle = NSUnderlineStyleSingle;
- }
- return _reviewsLab;
- }
- - (QMUILabel *)priceLab {
- if (!_priceLab) {
- _priceLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
- _priceLab.textAlignment = NSTextAlignmentLeft;
- _priceLab.textColor = [UIColor blackColor];
- _priceLab.font = [UIFont systemFontOfSize:18];
- }
- return _priceLab;
- }
- - (QMUILabel *)saveLab {
- if (!_saveLab) {
- _saveLab = [[QMUILabel alloc] initWithFrame:CGRectZero];
- _saveLab.contentEdgeInsets= UIEdgeInsetsMake(10, 10, 10, 10);
- _saveLab.backgroundColor = [UIColor colorWithHexString:@"#E0FFF5"];
- _saveLab.textAlignment = NSTextAlignmentCenter;
- _saveLab.textColor = [UIColor colorWithHexString:@"#113632"];
- _saveLab.font = [UIFont fontWithName:Rob_Bold size:12];
- }
- return _saveLab;
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- @end
|