// // FKProSourceCell.m // FirstLink // // Created by jack on 16/8/15. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKProSourceCell.h" #import "FKProDetailViewModel.h" @interface FKProSourceCell () @property (nonatomic, strong) UIImageView *flagImgView; @property (nonatomic, strong) UILabel *sourceLabel; @property (nonatomic, strong) UILabel *advLabel; @property (nonatomic, strong) UILabel *authenLabel; // 第三方认证 @property (nonatomic, strong) UILabel *countLabel; @property (nonatomic, strong) UIImageView *rightArrow; @end @implementation FKProSourceCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self addAllSubviews]; self.selectionStyle = UITableViewCellSelectionStyleNone; self.contentView.backgroundColor = [UIColor whiteColor]; } return self; } - (void)addAllSubviews{ [self.contentView addSubview:self.flagImgView]; [self.contentView addSubview:self.sourceLabel]; [self.contentView addSubview:self.authenLabel]; [self.contentView addSubview:self.countLabel]; [self.contentView addSubview:self.rightArrow]; [self.contentView addSubview:self.advLabel]; [self.flagImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(15); make.top.equalTo(self.contentView).offset(14); make.size.mas_equalTo(CGSizeMake(20, 13)); }]; [self.sourceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.flagImgView.mas_right).offset(5); make.centerY.equalTo(self.flagImgView); }]; [self.authenLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.sourceLabel.mas_right).offset(5); make.centerY.equalTo(self.sourceLabel); make.size.mas_equalTo(CGSizeMake(40, 13)); }]; [self.advLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.sourceLabel); make.top.equalTo(self.sourceLabel.mas_bottom).offset(6); }]; [self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView).offset(-15); make.centerY.equalTo(self.contentView); }]; [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.rightArrow.mas_left).offset(-4); make.centerY.equalTo(self.rightArrow); }]; } - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{ if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) { FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel; [self.flagImgView setImageWithURL:detailModel.dataItem.countryInfoItem.countryPicUrl cdnWidth:20]; self.sourceLabel.text = detailModel.dataItem.supplier.name; NSString *postageRule = detailModel.dataItem.supplier.postageRule; if ([FLStringHelper isValidString:postageRule]) { self.advLabel.hidden = NO; self.advLabel.text = [NSString stringWithFormat:@"(%@)", postageRule]; } else { self.advLabel.hidden = YES; } self.authenLabel.hidden = [detailModel.dataItem.supplier isAuthenedProduct] ? NO : YES; NSString *validCount = detailModel.dataItem.supplier.validProdCount; if (validCount.integerValue >= 10) { self.countLabel.hidden = NO; NSString *text = @""; if (validCount.integerValue < 10000) { text = validCount; } else { text = [NSString stringWithFormat:@"%ldw+", validCount.integerValue/10000]; } self.countLabel.text = [NSString stringWithFormat:@"%@件", text]; } else { self.countLabel.hidden = YES; } } } #pragma mark - property - (UIImageView *)flagImgView{ if (_flagImgView == nil) { _flagImgView = [[UIImageView alloc]init]; _flagImgView.contentMode = UIViewContentModeScaleAspectFit; } return _flagImgView; } - (UILabel *)sourceLabel{ if (_sourceLabel == nil) { _sourceLabel = [[UILabel alloc]init]; _sourceLabel.textColor = UIColorFromRGB(0x333333); _sourceLabel.font = [UIFont systemFontOfSize:14]; } return _sourceLabel; } - (UIImageView *)rightArrow{ if (_rightArrow == nil) { _rightArrow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"more_right_arrow"]]; } return _rightArrow; } - (UILabel *)advLabel{ if (_advLabel == nil) { _advLabel = [[UILabel alloc]init]; _advLabel.textColor = UIColorFromRGB(0x999999); _advLabel.font = [UIFont systemFontOfSize:12]; _advLabel.numberOfLines = 1; _advLabel.lineBreakMode = NSLineBreakByTruncatingTail; } return _advLabel; } - (UILabel *)authenLabel{ if (_authenLabel == nil) { _authenLabel = [[UILabel alloc]init]; _authenLabel.font = [UIFont systemFontOfSize:9]; _authenLabel.textColor = UIColorFromRGB(0xF7AC22); _authenLabel.text = @"认证采购"; _authenLabel.textAlignment = NSTextAlignmentCenter; _authenLabel.layer.cornerRadius = 3.0; _authenLabel.layer.borderWidth = 0.5; _authenLabel.layer.borderColor = UIColorFromRGB(0xF7AC22).CGColor; } return _authenLabel; } - (UILabel *)countLabel { if (_countLabel == nil) { _countLabel = [[UILabel alloc]init]; _countLabel.textAlignment = NSTextAlignmentRight; _countLabel.textColor = UIColorFromRGB(0x999999); _countLabel.font = [UIFont systemFontOfSize:13]; } return _countLabel; } @end