// // FKProBCChannelFeeCell.m // FirstLink // // Created by ascii on 2017/8/21. // Copyright © 2017年 FirstLink. All rights reserved. // #import "FKProBCChannelFeeCell.h" #import "FKProDetailViewModel.h" @interface FKProBCChannelFeeCell () @property (nonatomic, strong) UIView *topLine; @property (nonatomic, strong) UILabel *priceTipLabel; @property (nonatomic, strong) UILabel *priceLabel; @property (nonatomic, strong) UIImageView *rightArrow; @end @implementation FKProBCChannelFeeCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.contentView.backgroundColor = [UIColor whiteColor]; [self setupViews]; } return self; } + (CGFloat)cellHeight{ return 44.0f; } - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{ if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) { FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel; FKProductInfoItem *productInfoItem = detailModel.dataItem.productInfo; NSString *productPrice = productInfoItem.price; if (detailModel.selectBuyItem) { productPrice = detailModel.selectBuyItem.price; } FKProPriceDetailCellType cellType = [detailModel priceDetailCellType]; if (cellType == FKProPriceDetailCellTypeInProgress) { if (detailModel.selectBuyItem.activityPrice) { productPrice = detailModel.selectBuyItem.activityPrice; } } else { if ([detailModel.discountItem isVipUserWithDiscount]) { CGFloat discount = [detailModel.discountItem.discount floatValue]; productPrice = [NSString stringWithFormat:@"%.2lf", [productPrice floatValue] * discount/100.0]; } } CGFloat totalPrice = productPrice.floatValue + productInfoItem.internationalPostage.floatValue; CGFloat taxRate = productInfoItem.taxRate.floatValue/100000.0; self.priceLabel.text = [NSString stringWithFormat:@"%.2f元", (floor(totalPrice * taxRate)/100.0)]; } } #pragma mark - Private Method - (void)setupViews { [self.contentView addSubview:self.topLine]; [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.equalTo(self.contentView); make.height.mas_equalTo(1.0/[UIScreen mainScreen].scale); }]; [self.contentView addSubview:self.priceTipLabel]; [self.priceTipLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(15); make.centerY.equalTo(self.contentView); }]; [self.contentView addSubview:self.priceLabel]; [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.priceTipLabel.mas_right).offset(12); make.centerY.equalTo(self.contentView); }]; [self.contentView addSubview:self.rightArrow]; [self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView).offset(-15); make.centerY.equalTo(self.contentView); }]; } #pragma mark - Property - (UIView *)topLine{ if (_topLine == nil) { _topLine = [[UIView alloc]init]; _topLine.backgroundColor = UIColorFromRGB(0xe5e5e5); } return _topLine; } - (UILabel *)priceTipLabel { if (_priceTipLabel == nil) { _priceTipLabel = [[UILabel alloc]init]; _priceTipLabel.textColor = UIColorFromRGB(0x666666); _priceTipLabel.font = [UIFont systemFontOfSize:14]; _priceTipLabel.text = @"进口税:"; } return _priceTipLabel; } - (UILabel *)priceLabel { if (_priceLabel == nil) { _priceLabel = [[UILabel alloc]init]; _priceLabel.textColor = UIColorFromRGB(0xff6362); _priceLabel.font = [UIFont systemFontOfSize:14]; _priceLabel.text = @"--"; } return _priceLabel; } - (UIImageView *)rightArrow { if (_rightArrow == nil) { _rightArrow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"more_right_arrow"]]; [_rightArrow setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; [_rightArrow setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; } return _rightArrow; } @end