// // LDGoodHorzitolCollectionCell.m // YouHuiProject // // Created by 小花 on 2018/5/8. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LDGoodHorzitolCollectionCell.h" #import "LDGoodTagsView.h" @interface LDGoodHorzitolCollectionCell () @property (nonatomic, strong) UIImageView *imgView; //大图 @property (nonatomic, strong) UILabel *titleLabel; //标题 @property (nonatomic, strong) UILabel *priceLabel; //原价 @property (nonatomic, strong) UILabel *saleCount; // 月销量 @property (nonatomic, strong) UILabel *disPriceL; // 优惠后价格 @property (nonatomic, strong) UIImageView *ticketNumber; // @property (nonatomic, strong) UILabel *totalCount; // 总件数 @property (nonatomic, strong) UILabel *zheKou; // 几折,或者几元券 //@property (nonatomic, strong) UIImageView *freeShopping; @property (nonatomic, strong) UILabel *ticketType; @property (nonatomic, strong) UILabel *commissionLabel; @property (nonatomic, strong) LDGoodTagsView *tagsView; @property (nonatomic, strong) YYLabel *shopInfo; @end @implementation LDGoodHorzitolCollectionCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.contentView.backgroundColor = [UIColor whiteColor]; [self initSubViews]; } return self; } - (void)initSubViews { [self.contentView addSubview:self.imgView]; [self.contentView addSubview:self.titleLabel]; [self.contentView addSubview:self.priceLabel]; [self.contentView addSubview:self.disPriceL]; [self.contentView addSubview:self.ticketNumber]; [self.imgView addSubview:self.commissionLabel]; [self.imgView addSubview:self.totalCount]; [self.ticketNumber addSubview:self.zheKou]; [self.ticketNumber addSubview:self.ticketType]; [self.contentView addSubview:self.saleCount]; [self.contentView addSubview:self.tagsView]; [self.contentView addSubview:self.shopInfo]; [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(10); make.left.mas_equalTo(10); make.width.height.mas_equalTo(120); }]; [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(0); make.height.mas_equalTo(20); make.bottom.mas_equalTo(0); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.imgView.mas_right).mas_offset(10); make.top.mas_equalTo(10); make.right.mas_equalTo(-10); }]; [self.disPriceL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel.mas_left); make.bottom.mas_equalTo(-10); }]; [self.shopInfo mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel); make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(15); }]; // [self.freeShopping mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.mas_equalTo(self.titleLabel.mas_right).mas_offset(5); // make.bottom.mas_equalTo(self.disPriceL.mas_top).mas_offset(-7); // make.width.mas_equalTo(30); // make.height.mas_equalTo(12); // }]; [self.ticketNumber mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(self.disPriceL.mas_top).mas_offset(-10); make.left.mas_equalTo(self.titleLabel.mas_left); make.width.mas_equalTo(64); make.height.mas_equalTo(14); }]; [self.ticketType mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.bottom.mas_equalTo(0); make.width.mas_equalTo(20); }]; [self.zheKou mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(20); make.top.bottom.right.mas_equalTo(0); }]; // [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.mas_equalTo(self.disPriceL.mas_right).mas_offset(5); // make.bottom.mas_equalTo(self.disPriceL.mas_bottom).mas_offset(-2); // }]; [self.totalCount mas_makeConstraints:^(MASConstraintMaker *make) { make.right.top.mas_equalTo(0); make.height.mas_equalTo(20); }]; [self.saleCount mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-13); make.centerY.mas_equalTo(self.disPriceL.mas_centerY); }]; [self.tagsView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.ticketNumber.mas_right).mas_offset(5); make.centerY.mas_equalTo(self.ticketNumber.mas_centerY); make.width.mas_equalTo(80); make.height.mas_equalTo(12); }]; } - (void)setModel:(LDChildGoodModel *)model { //标题 NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",model.title]]; self.titleLabel.attributedText = attri; //店铺信息 if (model.shop_title.length > 0) { UIImage *img; if ([model.shop_type isEqualToString:@"1"]) { img= [UIImage imageNamed:@"tm_shop"]; }else { img= [UIImage imageNamed:@"taobao_shop"]; } YYAnimatedImageView *imgeView = [[YYAnimatedImageView alloc] initWithImage:img]; imgeView.frame = CGRectMake(0, 0, 15, 15); NSMutableAttributedString *shopAtti = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",model.shop_title]]; NSMutableAttributedString *mua = [NSMutableAttributedString yy_attachmentStringWithContent:imgeView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imgeView.frame.size alignToFont:[UIFont systemFontOfSize:14] alignment:YYTextVerticalAlignmentCenter]; [shopAtti insertAttributedString:mua atIndex:0]; shopAtti.yy_font = [UIFont systemFontOfSize:12]; shopAtti.yy_color = [UIColor YHColorWithHex:0x9B9B9B]; self.shopInfo.attributedText = shopAtti; self.shopInfo.hidden = NO; }else { self.shopInfo.hidden = YES; } //大图 [self.imgView yy_setImageWithURL:[NSURL URLWithString:model.img] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation]; NSString *price = [NSString stringWithFormat:@"¥%.2f",[model.price floatValue]]; NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:price attributes:@{NSStrikethroughStyleAttributeName : @(NSUnderlineStyleNone)}]; [attrStr setAttributes:@{NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle), NSBaselineOffsetAttributeName:@0} range:NSMakeRange(0, price.length)]; self.priceLabel.attributedText = attrStr; if ([model.type boolValue]) { self.totalCount.hidden = NO; self.totalCount.text = [NSString stringWithFormat:@" 共%@件 ",model.coupon_surplus]; }else { self.totalCount.hidden = YES; } self.saleCount.text = [NSString stringWithFormat:@"%@人付款",model.volume]; //折后价 NSString *disStr; if ([model.is_coupon boolValue]) { disStr = [NSString stringWithFormat:@"券后¥%.2f",[model.discount_price floatValue]]; self.zheKou.text = [NSString stringWithFormat:@"%@元",model.coupon_price]; self.ticketType.text = @"券"; }else { disStr = [NSString stringWithFormat:@"折后¥%.2f",[model.discount_price floatValue]]; self.zheKou.text = [NSString stringWithFormat:@"%@折",model.coupon_price]; self.ticketType.text = @"折"; } NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:disStr]; [disAttr addAttributes:@{NSForegroundColorAttributeName:[UIColor homeRedColor]} range:NSMakeRange(0, disAttr.length)]; [disAttr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} range:NSMakeRange(0, 3)]; self.disPriceL.attributedText = disAttr; //券相关 self.ticketNumber.hidden = ![model.is_coupon boolValue]; CGFloat margin = [model.is_coupon boolValue] ? 5 : 0; CGFloat width = [model.is_coupon boolValue] ? 64 : 0; [self.ticketNumber mas_updateConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(width); }]; [self.tagsView mas_updateConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.ticketNumber.mas_right).mas_offset(margin); }]; [self.tagsView setTags:model.tags]; if (model.commission_price.length > 0) { self.commissionLabel.text = [NSString stringWithFormat:@"预估佣金¥%.2f",[model.commission_price floatValue]]; } self.commissionLabel.hidden = !(model.commission_price.length>0) ; } - (UIImageView *)imgView { if (!_imgView) { _imgView = [[UIImageView alloc] init]; _imgView.backgroundColor = [UIColor YHColorWithHex:0xf0f0f0]; } return _imgView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.font = [UIFont systemFontOfSize:14]; _titleLabel.textColor = [UIColor YHColorWithHex:0x444444]; _titleLabel.numberOfLines = 2; } return _titleLabel; } - (UILabel *)priceLabel { if (!_priceLabel) { _priceLabel = [[UILabel alloc] init]; _priceLabel.font = [UIFont systemFontOfSize:11]; _priceLabel.textColor = [UIColor YHColorWithHex:0x999999]; } return _priceLabel; } - (UILabel *)saleCount { if (!_saleCount) { _saleCount = [[UILabel alloc] init]; _saleCount.font = [UIFont systemFontOfSize:11]; _saleCount.textColor = [UIColor YHColorWithHex:0x999999]; _saleCount.textAlignment = NSTextAlignmentRight; } return _saleCount; } - (UILabel *)disPriceL { if (!_disPriceL) { _disPriceL = [[UILabel alloc] init]; _disPriceL.font = [UIFont systemFontOfSize:15]; _disPriceL.textColor = [UIColor homeRedColor]; } return _disPriceL; } - (UIImageView *)ticketNumber { if (!_ticketNumber) { _ticketNumber = [[UIImageView alloc] init]; _ticketNumber.image = [UIImage imageNamed:@"quan_bg"]; } return _ticketNumber; } - (UILabel *)totalCount { if (!_totalCount) { _totalCount = [[UILabel alloc] init]; _totalCount.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6]; _totalCount.layer.cornerRadius = 3; _totalCount.font = [UIFont systemFontOfSize:10]; _totalCount.textAlignment = NSTextAlignmentCenter; _totalCount.textColor = [UIColor YHColorWithHex:0xffffff]; } return _totalCount; } - (UILabel *)zheKou { if (!_zheKou) { _zheKou = [[UILabel alloc] init]; _zheKou.textColor = [UIColor homeRedColor]; _zheKou.textAlignment = NSTextAlignmentCenter; _zheKou.font = [UIFont systemFontOfSize:10]; } return _zheKou; } //- (UIImageView *)freeShopping { // if (!_freeShopping) { // _freeShopping = [[UIImageView alloc] init]; // _freeShopping.image = [UIImage imageNamed:@"freeshop"]; // } // return _freeShopping; //} - (UILabel *)ticketType { if (!_ticketType) { _ticketType = [[UILabel alloc] init]; _ticketType.font = [UIFont systemFontOfSize:10]; _ticketType.textAlignment = NSTextAlignmentCenter; _ticketType.textColor = [UIColor homeRedColor]; } return _ticketType; } - (UILabel *)commissionLabel { if (!_commissionLabel) { _commissionLabel = [[UILabel alloc] init]; _commissionLabel.font = [UIFont systemFontOfSize:11]; _commissionLabel.textColor = [UIColor whiteColor]; _commissionLabel.textAlignment = NSTextAlignmentCenter; _commissionLabel.backgroundColor = [UIColor homeRedColor]; } return _commissionLabel; } - (LDGoodTagsView *)tagsView { if (!_tagsView) { _tagsView = [[LDGoodTagsView alloc] init]; } return _tagsView; } - (YYLabel *)shopInfo { if (!_shopInfo) { _shopInfo = [[YYLabel alloc] init]; _shopInfo.displaysAsynchronously = YES; _shopInfo.font = [UIFont systemFontOfSize:12]; _shopInfo.textColor = [UIColor YHColorWithHex:0x9B9B9B]; } return _shopInfo; } @end