// // KDPOrderDetailTableViewCell.m // KuDianProject // // Created by admin on 2019/7/9. // Copyright © 2019 KDP. All rights reserved. // #import "KDPOrderDetailTableViewCell.h" #import "KDPLiveDetailModel.h" @interface KDPOrderDetailTableViewCell () @property (nonatomic, strong) UILabel *timeLabel; @property (nonatomic, strong) UIImageView *iconImageView; @property (nonatomic, strong) UILabel *goodTitleLabel; @property (nonatomic, strong) UILabel *createTimeLabel; @property (nonatomic, strong) UILabel *endTimeLabel; @property (nonatomic, strong) UILabel *payMonny; @property (nonatomic, strong) UILabel *commMonny; // 佣金 @property (nonatomic, strong) CAShapeLayer *dotteShapeLayer; @end @implementation KDPOrderDetailTableViewCell - (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.contentView.layer.cornerRadius = 6; self.contentView.layer.masksToBounds = YES; self.iconImageView = [[UIImageView alloc] init]; self.iconImageView.layer.cornerRadius = 8; self.iconImageView.layer.masksToBounds = YES; [self.contentView addSubview:self.iconImageView]; self.timeLabel = [[UILabel alloc] init]; self.timeLabel.textColor = [UIColor colorWithHex:0x333333]; self.timeLabel.font = FONT_SYS(12); [self.contentView addSubview:self.timeLabel]; self.goodTitleLabel = [[UILabel alloc] init]; self.goodTitleLabel.textColor = [UIColor colorWithHex:0x333333]; self.goodTitleLabel.font = FONT_SYS(15); [self.contentView addSubview:self.goodTitleLabel]; self.createTimeLabel = [[UILabel alloc] init]; self.createTimeLabel.textColor = [UIColor colorWithHex:0x999999]; self.createTimeLabel.font = FONT_SYS(12); [self.contentView addSubview:self.createTimeLabel]; self.endTimeLabel = [[UILabel alloc] init]; self.endTimeLabel.textColor = [UIColor colorWithHex:0x999999]; self.endTimeLabel.font = FONT_SYS(12); [self.contentView addSubview:self.endTimeLabel]; self.payMonny = [[UILabel alloc] init]; self.payMonny.textColor = [UIColor colorWithHex:0x666666]; self.payMonny.font = FONT_SYS(12); [self.contentView addSubview:self.payMonny]; self.commMonny = [[UILabel alloc] init]; [self.contentView addSubview:self.commMonny]; } - (void)setContentViewConstraints{ self.backgroundColor = [UIColor clearColor]; [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(UIEdgeInsetsMake(0, 10, 6, 10)); }]; [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.mas_left).offset(8); make.top.equalTo(self.contentView.mas_top).offset(7); make.size.equalTo(CGSizeMake(SCREEN_WIDTH-30, 17)); }]; [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.mas_left).offset(8); make.bottom.equalTo(self.contentView.mas_bottom).offset(-8); make.size.equalTo(CGSizeMake(80, 80)); }]; [self.goodTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.iconImageView.mas_right).offset(6); make.top.equalTo(self.iconImageView.mas_top).offset(5); make.right.equalTo(self.contentView.mas_right).offset(-10); }]; [self.createTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.goodTitleLabel); make.top.equalTo(self.goodTitleLabel.mas_bottom).offset(9); make.width.equalTo(130); }]; [self.endTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.createTimeLabel.mas_right).offset(10); make.right.equalTo(self.contentView.mas_right).offset(-10); make.top.equalTo(self.createTimeLabel); }]; [self.payMonny mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.goodTitleLabel); make.top.equalTo(self.createTimeLabel.mas_bottom).offset(10); make.width.equalTo(self.createTimeLabel); }]; [self.commMonny mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.endTimeLabel); make.top.equalTo(self.payMonny); }]; // 虚线 self.dotteShapeLayer = [CAShapeLayer layer]; CGMutablePathRef dotteshapePath = CGPathCreateMutable(); // 设置虚线颜色 [self.dotteShapeLayer setStrokeColor:[UIColor colorWithHex:0xC5C5C5].CGColor]; self.dotteShapeLayer.lineWidth = 0.3f; NSArray *dottehShapeArr = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:4],[NSNumber numberWithInt:4],[NSNumber numberWithInt:4],[NSNumber numberWithInt:4],[NSNumber numberWithInt:4], nil]; [self.dotteShapeLayer setLineDashPattern:dottehShapeArr]; CGPathMoveToPoint(dotteshapePath, NULL, 8,29); CGPathAddLineToPoint(dotteshapePath, NULL, self.contentView.width-7, 29); [self.dotteShapeLayer setPath:dotteshapePath]; CGPathRelease(dotteshapePath); [self.contentView.layer addSublayer:self.dotteShapeLayer]; } - (void)configWithViewModel:(id)viewModel indexpath:(NSIndexPath *)indexPath{ KDPLiveDetailModel *detailModel = (KDPLiveDetailModel *)viewModel; [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:detailModel.img]placeholderImage:[UIImage imageNamed:placholderImg]]; self.goodTitleLabel.text = detailModel.name; self.createTimeLabel.text = [NSString stringWithFormat:@"创建日:%@",detailModel.order_create_at]; self.endTimeLabel.text = [NSString stringWithFormat:@"结算日:%@",detailModel.order_balance_at]; self.payMonny.text = [NSString stringWithFormat:@"付款金额:¥%@",detailModel.money]; NSString *string = [NSString stringWithFormat:@"结算佣金:¥%@",detailModel.rebate]; NSMutableAttributedString *commAtt = [[NSMutableAttributedString alloc] initWithString:string attributes:@{NSForegroundColorAttributeName:[UIColor baseColor],NSFontAttributeName:FONT_SYS(12)}]; [commAtt addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x666666]} range:[string rangeOfString:@"结算佣金:"]]; [self.commMonny setAttributedText:commAtt]; self.timeLabel.text = self.liveTime; if (indexPath.row == 0) { self.timeLabel.hidden = NO; } else{ self.timeLabel.hidden = YES; } if (indexPath.row == 0) { self.dotteShapeLayer.hidden = NO; } else{ self.dotteShapeLayer.hidden = YES; } } @end