// // KDPLiveRightTableViewCell.m // KuDianProject // // Created by admin on 2019/7/9. // Copyright © 2019 KDP. All rights reserved. // #import "KDPLiveRightTableViewCell.h" #import "KDPLiveStatisticsModel.h" #import "KDPBaseLabel.h" @interface KDPLiveRightTableViewCell () @property (nonatomic, strong) UIImageView *iconImageView; @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UILabel *priceLabel; @property (nonatomic, strong) UILabel *priceDetailLabel; @property (nonatomic, strong) UILabel *profitLabel; @property (nonatomic, strong) KDPBaseLabel *profitDetailLabel; @property (nonatomic, strong) UILabel *orderLabel; @property (nonatomic, strong) UILabel *orderDetailLabel; @property (nonatomic, strong) UIImageView *profitImageView; @property (nonatomic, strong) UIView *lineView; @end @implementation KDPLiveRightTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setContentView]; [self setContentViewConstraints]; } return self; } - (void)setContentView{ self.contentView.backgroundColor = [UIColor whiteColor]; self.iconImageView = [[UIImageView alloc] init]; self.iconImageView.layer.cornerRadius = 8; self.iconImageView.layer.masksToBounds = YES; [self.contentView addSubview:self.iconImageView]; self.titleLabel = [[UILabel alloc] init]; self.titleLabel.font = FONT_SYS(15); self.titleLabel.textColor = [UIColor colorWithHex:0x333333]; [self.contentView addSubview:self.titleLabel]; self.priceLabel = [[UILabel alloc] init]; self.priceLabel.textColor = [UIColor colorWithHex:0x333333]; self.priceLabel.font = FONT_SYS(18); self.priceLabel.text = @"0"; self.priceLabel.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:self.priceLabel]; self.priceDetailLabel = [[UILabel alloc] init]; self.priceDetailLabel.textColor = [UIColor colorWithHex:0x666666]; self.priceDetailLabel.font = FONT_SYS(12); self.priceDetailLabel.text = @"价格"; self.priceDetailLabel.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:self.priceDetailLabel]; self.profitLabel = [[UILabel alloc] init]; self.profitLabel.textColor = [UIColor colorWithHex:0x333333]; self.profitLabel.font = FONT_SYS(18); self.profitLabel.text = @"40%"; self.profitLabel.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:self.profitLabel]; self.profitDetailLabel = [[KDPBaseLabel alloc] init]; self.profitDetailLabel.textColor = [UIColor colorWithHex:0x666666]; self.profitDetailLabel.font = FONT_SYS(12); self.profitDetailLabel.text = @"利润"; self.profitDetailLabel.textAlignment = NSTextAlignmentCenter; self.profitDetailLabel.insets = UIEdgeInsetsMake(0, 0, 0, 10); [self.contentView addSubview:self.profitDetailLabel]; self.profitImageView = [[UIImageView alloc] init]; [self.profitDetailLabel addSubview:self.profitImageView]; self.orderLabel = [[UILabel alloc] init]; self.orderLabel.textColor = [UIColor colorWithHex:0x333333]; self.orderLabel.font = FONT_SYS(18); self.orderLabel.text = @"0"; self.orderLabel.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:self.orderLabel]; self.orderDetailLabel = [[UILabel alloc] init]; self.orderDetailLabel.textColor = [UIColor colorWithHex:0x666666]; self.orderDetailLabel.font = FONT_SYS(12); self.orderDetailLabel.text = @"预估订单数"; self.orderDetailLabel.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:self.orderDetailLabel]; self.lineView = [[UIView alloc] init]; self.lineView.backgroundColor = [UIColor colorWithHex:0xF5F5F5]; [self.contentView addSubview:self.lineView]; } - (void)setContentViewConstraints{ [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.mas_left).offset(10); make.size.equalTo(CGSizeMake(80, 80)); make.centerY.equalTo(self.contentView); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.iconImageView.mas_right).offset(12); make.top.equalTo(self.iconImageView.mas_top); make.right.equalTo(self.contentView.mas_right).offset(-10); }]; [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.titleLabel.mas_left); make.width.equalTo(self.profitLabel); make.top.equalTo(self.titleLabel.mas_bottom).offset(13); }]; [self.priceDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.priceLabel); make.top.equalTo(self.priceLabel.mas_bottom).offset(6); make.width.equalTo(self.profitDetailLabel); }]; [self.profitLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.priceLabel.mas_right); make.width.equalTo(self.orderLabel); make.top.equalTo(self.titleLabel.mas_bottom).offset(13); }]; [self.profitDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.priceDetailLabel.mas_right); make.top.equalTo(self.profitLabel.mas_bottom).offset(6); make.width.equalTo(self.orderDetailLabel); }]; [self.orderLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.profitLabel.mas_right); make.width.equalTo(self.profitLabel); make.right.equalTo(self.contentView.mas_right).offset(-13); make.top.equalTo(self.titleLabel.mas_bottom).offset(13); }]; [self.orderDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.profitDetailLabel.mas_right); make.top.equalTo(self.orderLabel.mas_bottom).offset(6); make.right.equalTo(self.contentView.mas_right).offset(-13); make.width.equalTo(self.priceDetailLabel); }]; [self.profitImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.equalTo(CGSizeMake(15, 15)); make.centerY.equalTo(self.profitDetailLabel); make.left.equalTo(self.profitDetailLabel.mas_centerX).offset(7); }]; [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.equalTo(self.contentView); make.height.equalTo(1); }]; } - (void)configWithViewModel:(id)viewModel indexpath:(NSIndexPath *)indexPath{ KDPLiveStatisticsModel *statisModel = (KDPLiveStatisticsModel *)viewModel; [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:statisModel.img]placeholderImage:[UIImage imageNamed:placholderImg]]; self.titleLabel.text = statisModel.name; self.priceLabel.text = [NSString stringWithFormat:@"%.2f",[statisModel.money floatValue]]; self.profitLabel.text = [NSString stringWithFormat:@"%@%%",statisModel.commission_rate_2]; self.orderLabel.text = statisModel.predictCount; self.profitImageView.hidden = NO; if ([statisModel.commission_rate_2 integerValue] > [statisModel.commission_rate integerValue]) { self.profitImageView.image = [UIImage imageNamed:@"up_icon"]; self.profitDetailLabel.insets = UIEdgeInsetsMake(0, 0, 0, 10); } else if ([statisModel.commission_rate integerValue] == [statisModel.commission_rate_2 integerValue]){ self.profitDetailLabel.insets = UIEdgeInsetsMake(0, 0, 0, 0); self.profitImageView.hidden = YES; } else{ self.profitDetailLabel.insets = UIEdgeInsetsMake(0, 0, 0, 10); self.profitImageView.image = [UIImage imageNamed:@"down_icon"]; } } @end