// // FKWantBuyProductCell.m // FirstLink // // Created by 施昌鹏 on 16/8/18. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKWantBuyProductCell.h" #import "FKInvalidView.h" #import "FKWantBuyProItem.h" #import "FKWantBuyItem.h" @interface FKWantBuyProductCell () @property (nonatomic, strong) UIView *divideView; @property (nonatomic, strong) UILabel *showLabel; @property (nonatomic, strong) UILabel *URLLabel; @property (nonatomic, strong) UILabel *priceLabel; @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UIImageView *brandImageView; @property (nonatomic, strong) UIImageView *productImageView; @property (nonatomic, strong) FKInvalidView *invalidView; @end @implementation FKWantBuyProductCell -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self addAllSubviews]; } return self; } -(void)addAllSubviews { [self.contentView addSubview:self.showLabel]; [self.contentView addSubview:self.URLLabel]; [self.contentView addSubview:self.divideView]; [self.contentView addSubview: self.productImageView]; [self.contentView addSubview:self.priceLabel]; [self.contentView addSubview:self.brandImageView]; [self.contentView addSubview:self.titleLabel]; [self.productImageView addSubview:self.invalidView]; [self.showLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(15); make.right.equalTo(self.contentView).offset(-20); make.top.equalTo(self.contentView).offset(13); }]; [self.URLLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.showLabel); make.top.equalTo(self.showLabel.mas_bottom); }]; [self.divideView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.contentView); make.top.equalTo(self.contentView).offset(63); make.height.mas_equalTo(1); }]; [self.productImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(15); make.top.equalTo(self.divideView.mas_bottom).offset(15); make.height.width.mas_equalTo(75); }]; [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.divideView.mas_bottom).offset(18); make.right.equalTo(self.contentView).offset(-10); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.productImageView.mas_right).offset(9); make.right.equalTo(self.priceLabel.mas_left).offset(-20); make.top.equalTo(self.divideView.mas_bottom).offset(18); }]; [self.brandImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.titleLabel); make.top.equalTo(self.titleLabel.mas_bottom).offset(10); make.height.mas_equalTo(17); make.width.mas_equalTo(80); }]; [self.invalidView mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(self.productImageView); }]; } #pragma mark - Action -(void)configWithViewModel:(FKWantBuyViewModel *)viewModel index:(NSIndexPath *)index{ FKWantBuyItem *item = viewModel.dataArray[index.section]; if (item && item.product) { self.URLLabel.text = item.proUrl; [self.productImageView setImageWithURL:item.product.productPic cdnWidth:75]; [self.brandImageView fl_setImageWithURL:[NSURL URLWithString:item.product.brand]]; self.titleLabel.text = item.product.proTitle; self.priceLabel.text = [FLStringHelper convertFenToRMBmoneyString:item.product.price]; if ([FLStringHelper isValidString:item.storageNum]) { if ([item.storageNum intValue]) { if ([item.product.status intValue] == 1) { self.invalidView.hidden = YES; }else if ([item.product.status intValue] == 3) { self.invalidView.titleLabel.text = @"已失效"; }else{ self.invalidView.titleLabel.text = @"已抢光"; } }else{ self.invalidView.titleLabel.text = @"已抢光"; } } } } #pragma mark- Property -(UIView *)divideView { if (_divideView == nil) { _divideView = [[UIView alloc] init]; _divideView.backgroundColor = UIColorFromRGB(0xf4f4f4); } return _divideView; } -(UILabel *)priceLabel { if (_priceLabel == nil) { _priceLabel = [[UILabel alloc] init]; _priceLabel.font = [UIFont boldSystemFontOfSize:13]; _priceLabel.textColor = UIColorFromRGB(0x333333); _priceLabel.numberOfLines = 1; _priceLabel.textAlignment = NSTextAlignmentRight; [_priceLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; } return _priceLabel; } -(UILabel *)showLabel { if (_showLabel == nil) { _showLabel = [[UILabel alloc] init]; _showLabel.textColor = UIColorFromRGB(0x333333); _showLabel.font = [UIFont systemFontOfSize:14]; _showLabel.text = @"商品抓取成功"; } return _showLabel; } -(UILabel *)URLLabel { if (_URLLabel == nil) { _URLLabel = [[UILabel alloc] init]; _URLLabel.font = [UIFont systemFontOfSize:14]; _URLLabel.textColor = UIColorFromRGB(0x999999); _URLLabel.numberOfLines = 1; } return _URLLabel; } -(UILabel *)titleLabel { if (_titleLabel == nil) { _titleLabel = [[UILabel alloc] init]; _titleLabel.font = [UIFont systemFontOfSize:13]; _titleLabel.textColor = UIColorFromRGB(0x666666); _titleLabel.numberOfLines = 2; } return _titleLabel; } -(UIImageView *)productImageView { if (_productImageView == nil) { _productImageView = [[UIImageView alloc] init]; _productImageView.contentMode = UIViewContentModeScaleAspectFit; } return _productImageView; } -(UIImageView *)brandImageView { if (_brandImageView == nil) { _brandImageView = [[UIImageView alloc] init]; } return _brandImageView; } -(FKInvalidView *)invalidView { if (_invalidView == nil) { _invalidView = [[FKInvalidView alloc] init]; } return _invalidView; } @end