YHL_HotSaleTableViewCell.m 4.31 KB
//
//  YHL_HotSaleTableViewCell.m
//  YohoLive
//
//  Created by 盖剑秋 on 2016/11/14.
//  Copyright © 2016年 YOHO!. All rights reserved.
//

#import "YHL_HotSaleTableViewCell.h"
#import "NSString+LIVE.h"
#import "UIImageView+WebCache.h"

@implementation YHL_HotSaleTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.productImageView];
        [self.contentView addSubview:self.productNameLable];
        [self.contentView addSubview:self.salePriceLable];
        [self.contentView addSubview:self.originalPriceLable];
        [self layoutContentSubviews];
        UIView *line = [UIView new];
        line.backgroundColor = [UIColor lightGrayColor];
        [self.contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.bottom.and.right.mas_equalTo(0);
            make.height.mas_equalTo(0.5);
        }];
    }
    return self;
}

- (void)layoutContentSubviews
{
    [self.productImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(76, 102));
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(15);
    }];
    
    [self.productNameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.productImageView.mas_right).offset(15);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(15);
    }];
    
    [self.salePriceLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-25);
        make.left.equalTo(self.productImageView.mas_right).offset(15);
    }];
    
    [self.originalPriceLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-25);
        make.left.equalTo(self.salePriceLable.mas_right).offset(10);
    }];
    
}

- (void)bindModel:(YHL_Product *)model
{
    if (![model isKindOfClass:[YHL_Product class]]) {
        return;
    }
    _currentProduct = model;
    self.productNameLable.text = model.productName;
    
    NSString *marketPrice = model.marketPrice;//吊牌价
    NSString *salesPrice = model.salesPrice;//当前价格
    
    self.salePriceLable.text = [NSString stringWithFormat:@"¥%@",salesPrice];
    
    if (salesPrice.floatValue != marketPrice.floatValue) {
        self.originalPriceLable.hidden = NO;
        NSAttributedString *originalAttString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%@",model.marketPrice] attributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}];
        self.originalPriceLable.attributedText =  originalAttString;
    } else {
        self.originalPriceLable.hidden = YES;
    }
    
    NSString *picUrlString = [model.picUrl yhl_splitUrlWithWidth:@(CGRectGetWidth(self.productImageView.bounds)*kScreenScale).stringValue height:@(CGRectGetHeight(self.productImageView.bounds)*kScreenScale).stringValue];
    [self.productImageView sd_setImageWithURL:[NSURL URLWithString:picUrlString]];
    
}

+ (CGFloat)cellForHeight
{
    return 122.0f;
}

- (UIImageView *)productImageView
{
    if (!_productImageView) {
        _productImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 76, 102)];//76 * 102
        _productImageView.userInteractionEnabled = YES;
        _productImageView.backgroundColor = [UIColor lightGrayColor];
    }
    return _productImageView;
}

- (UILabel *)productNameLable
{
    if (!_productNameLable) {
        _productNameLable = [[UILabel alloc] init];
        _productNameLable.numberOfLines = 2;
        _productNameLable.font = [UIFont systemFontOfSize:11];
        _productNameLable.textColor = [UIColor blackColor];
    }
    return _productNameLable;
}

- (UILabel *)salePriceLable
{
    if (!_salePriceLable) {
        _salePriceLable = [[UILabel alloc] init];
        _salePriceLable.font = [UIFont systemFontOfSize:17];
        _salePriceLable.textColor = [UIColor redColor];
    }
    return _salePriceLable;
}

- (UILabel *)originalPriceLable
{
    if (!_originalPriceLable) {
        _originalPriceLable = [[UILabel alloc] init];
        _originalPriceLable.font = [UIFont systemFontOfSize:9];
        _originalPriceLable.textColor = [UIColor lightGrayColor];
    }
    return _originalPriceLable;
}



@end