// // DRGoodDetailView.m // YouHuiProject // // Created by xiaoxi on 2018/1/25. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRGoodDetailView.h" #import "DRGoodDetailModel.h" #import "DRGotoDetailView.h" #import "UIView+SDAutoLayout.h" #import "CCCopyLabel.h" @interface DRGoodDetailView () @property (nonatomic, strong) CCCopyLabel *goodTitleLabel; @property (nonatomic, strong) UILabel *priceLabel; @property (nonatomic, strong) UIImageView *discountImageView; @property (nonatomic, strong) UILabel *discountPriceLabel; @property (nonatomic, strong) UILabel *freePostLabel; @property (nonatomic, strong) UILabel *volumeLabel; @property (nonatomic, strong) UILabel *quanType; @property (nonatomic, strong) UILabel *quanNum; @property (nonatomic, strong) UILabel *commissionPrice; @end @implementation DRGoodDetailView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor whiteColor]; [self initSubviews]; } return self; } - (void)setGoodModel:(DRGoodDetailModel *)goodModel { _goodModel = goodModel; NSString *quanType = [goodModel.is_coupon boolValue]?@"券":@"折"; self.quanType.text = quanType; NSString *quanNum = [goodModel.is_coupon boolValue]?[NSString stringWithFormat:@"%@元",goodModel.coupon_price]:[NSString stringWithFormat:@"%@折",goodModel.coupon_price]; self.quanNum.text = quanNum; self.discountImageView.hidden = ![goodModel.is_coupon boolValue]; //标题 NSTextAttachment *textAttach = [[NSTextAttachment alloc]init]; UIImage *img; if ([goodModel.shop_type isEqualToString:@"1"]) { img= [UIImage imageNamed:@"tm_shop"]; }else if([goodModel.shop_type isEqualToString:@"0"]){ // img= [UIImage imageNamed:@"share_title_tb"]; } if (img) { textAttach.image = img; textAttach.bounds = CGRectMake(0, -4, img.size.width, img.size.height); } NSMutableAttributedString *attri; if ([goodModel.shop_type isEqualToString:@"1"]) { attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",goodModel.title]]; }else { attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",goodModel.title]]; } NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:textAttach]; [attri insertAttributedString:string atIndex:0]; NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:8]; [attri addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [string length])]; self.goodTitleLabel.textStr = goodModel.title; self.goodTitleLabel.attributedText = attri; NSString *priceText = [NSString stringWithFormat:@"原价 ¥%.2f", [goodModel.price floatValue]]; // NSMutableAttributedString *attritu = [[NSMutableAttributedString alloc]initWithString:priceText]; // [attritu addAttributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleThick), // NSForegroundColorAttributeName:[UIColor lightGrayColor], // NSBaselineOffsetAttributeName:@(0), // } range:[priceText rangeOfString:priceText]]; self.priceLabel.text = priceText; NSString *dis_price = [goodModel.is_coupon boolValue] ? [NSString stringWithFormat:@"券后 ¥%.2f", [goodModel.discount_price floatValue]]:[NSString stringWithFormat:@"折后 ¥%.2f", [goodModel.discount_price floatValue]]; NSMutableAttributedString *dispriceAttr = [[NSMutableAttributedString alloc]initWithString:dis_price]; [dispriceAttr addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:13]} range:NSMakeRange(0, 3)]; self.discountPriceLabel.attributedText = dispriceAttr; self.volumeLabel.text = [NSString stringWithFormat:@"月销 %@", goodModel.volume]; self.freePostLabel.text = [goodModel.freeShipping isEqual:@1] ? @"包邮" : [NSString stringWithFormat:@"邮费 %@", goodModel.postage]; } - (void)initSubviews { [self addSubview:self.goodTitleLabel]; [self addSubview:self.priceLabel]; [self addSubview:self.discountImageView]; [self addSubview:self.discountPriceLabel]; [self addSubview:self.volumeLabel]; [self addSubview:self.commissionPrice]; [self.discountImageView addSubview:self.quanType]; [self.discountImageView addSubview:self.quanNum]; [self makeSubviewsConstraints]; } - (void)makeSubviewsConstraints { [self.discountPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(FITSIZE(10)); make.top.mas_equalTo(Fitsize(15)); }]; [self.discountImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.discountPriceLabel.mas_right).mas_offset(10); make.centerY.mas_equalTo(self.discountPriceLabel.mas_centerY); make.width.mas_equalTo(64); make.height.mas_equalTo(14); }]; [self.quanType mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.bottom.mas_equalTo(0); make.width.mas_equalTo(20); }]; [self.quanNum mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(20); make.top.bottom.right.mas_equalTo(0); }]; [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.discountPriceLabel); make.top.equalTo(self.discountPriceLabel.mas_bottom).offset(FITSIZE(15)); }]; [self.goodTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(FITSIZE(10)); make.left.equalTo(self.discountPriceLabel); make.right.equalTo(self).offset(-FITSIZE(10)); }]; [self.volumeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self).offset(-FITSIZE(20)); make.centerY.mas_equalTo(self.priceLabel.mas_centerY); }]; [self.commissionPrice mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.volumeLabel.mas_right); make.bottom.mas_equalTo(self.discountPriceLabel.mas_bottom); }]; } - (void)couponTapAction:(UIGestureRecognizer *)sender { if ([self.delegate respondsToSelector:@selector(yh_GoodDetailViewTapCoupon)]) { [self.delegate yh_GoodDetailViewTapCoupon]; } } - (void)shopTapAction:(UIGestureRecognizer *)sender { if ([self.delegate respondsToSelector:@selector(yh_GoodDetailViewTapShop)]) { [self.delegate yh_GoodDetailViewTapShop]; } } #pragma mark - lazy - (CCCopyLabel *)goodTitleLabel { if (!_goodTitleLabel) { _goodTitleLabel = [[CCCopyLabel alloc] init]; _goodTitleLabel.backgroundColor = [UIColor clearColor]; _goodTitleLabel.textColor = [UIColor YHColorWithHex:0x222222]; _goodTitleLabel.font = [UIFont systemFontOfSize:FITSIZE(14)]; _goodTitleLabel.numberOfLines = 2; // _goodTitleLabel.hidden=YES; } return _goodTitleLabel; } - (UILabel *)priceLabel { if (!_priceLabel) { _priceLabel = [[UILabel alloc] init]; _priceLabel.backgroundColor = [UIColor clearColor]; _priceLabel.textColor = [UIColor YHColorWithHex:0x999999]; _priceLabel.font = [UIFont systemFontOfSize:FITSIZE(13)]; } return _priceLabel; } - (UIImageView *)discountImageView { if (!_discountImageView) { _discountImageView = [[UIImageView alloc] init]; _discountImageView.backgroundColor = [UIColor clearColor]; _discountImageView.image = [UIImage imageNamed:@"quan_bg"]; } return _discountImageView; } - (UILabel *)discountPriceLabel { if (!_discountPriceLabel) { _discountPriceLabel = [[UILabel alloc] init]; _discountPriceLabel.backgroundColor = [UIColor clearColor]; _discountPriceLabel.textColor = [UIColor YHColorWithHex:0xff2420]; _discountPriceLabel.font = [UIFont systemFontOfSize:FITSIZE(22)]; } return _discountPriceLabel; } - (UILabel *)freePostLabel { if (!_freePostLabel) { _freePostLabel = [[UILabel alloc] init]; _freePostLabel.backgroundColor = [UIColor clearColor]; _freePostLabel.textColor = [UIColor YHColorWithHex:0x999999]; _freePostLabel.font = [UIFont systemFontOfSize:FITSIZE(11)]; } return _freePostLabel; } - (UILabel *)volumeLabel { if (!_volumeLabel) { _volumeLabel = [[UILabel alloc] init]; _volumeLabel.backgroundColor = [UIColor clearColor]; _volumeLabel.textColor = [UIColor YHColorWithHex:0x999999]; _volumeLabel.font = [UIFont systemFontOfSize:FITSIZE(11)]; } return _volumeLabel; } - (UILabel *)quanType { if (!_quanType) { _quanType = [[UILabel alloc] init]; _quanType.textColor = [UIColor whiteColor]; _quanType.font = [UIFont boldSystemFontOfSize:10]; _quanType.textAlignment = NSTextAlignmentCenter; } return _quanType; } - (UILabel *)quanNum { if (!_quanNum) { _quanNum = [[UILabel alloc] init]; _quanNum.textColor = [UIColor whiteColor]; _quanNum.font = [UIFont boldSystemFontOfSize:10]; _quanNum.textAlignment = NSTextAlignmentCenter; } return _quanNum; } - (UILabel *)commissionPrice { if (!_commissionPrice) { _commissionPrice = [[UILabel alloc] init]; _commissionPrice.textColor = [UIColor homeRedColor]; _commissionPrice.font = [UIFont systemFontOfSize:Fitsize(14)]; _commissionPrice.textAlignment = NSTextAlignmentRight; _commissionPrice.hidden = YES; } return _commissionPrice; } @end