// // DRCollectionTicketCell.m // YouHuiProject // // Created by 小花 on 2018/1/24. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRCollectionTicketCell.h" @interface DRCollectionTicketCell () @property (nonatomic, strong) UIImageView *iconView; @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UILabel *endDateLabel; @property (nonatomic, strong) UILabel *priceLabel; @property (nonatomic, strong) UILabel *disPriceLabel; @property (nonatomic, strong) UIImageView *ticketImg; @property (nonatomic, strong) UILabel *ticketLabel; @property (nonatomic, strong) UILabel *outTimeLabel; @property (nonatomic, strong) UIButton *sameButton; @end @implementation DRCollectionTicketCell + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *cellID = nil; cellID = NSStringFromClass([self class]); DRCollectionTicketCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[DRCollectionTicketCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } return cell; } - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self initSubView]; } return self; } - (void)initSubView { [self.contentView addSubview:self.iconView]; [self.contentView addSubview:self.titleLabel]; [self.contentView addSubview:self.endDateLabel]; [self.contentView addSubview:self.priceLabel]; [self.contentView addSubview:self.disPriceLabel]; [self.contentView addSubview:self.ticketImg]; [self.contentView addSubview:self.sameButton]; [self.ticketImg addSubview:self.ticketLabel]; [self.iconView addSubview:self.outTimeLabel]; [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.width.height.mas_equalTo(80); make.top.mas_equalTo(10); }]; [self.outTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.bottom.mas_equalTo(0); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(10); make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10); make.right.mas_equalTo(-10); }]; [self.endDateLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel.mas_left); make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(8); make.right.mas_equalTo(-10); }]; [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel.mas_left); make.bottom.mas_equalTo(-10); }]; [self.disPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.priceLabel.mas_right).mas_offset(5); make.centerY.mas_equalTo(self.priceLabel.mas_centerY); }]; [self.ticketImg mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.bottom.mas_equalTo(self.iconView.mas_bottom); make.width.mas_equalTo(60); make.height.mas_equalTo(20); }]; [self.ticketLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.bottom.mas_equalTo(0); }]; [self.sameButton mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.bottom.mas_equalTo(self.iconView.mas_bottom); make.width.mas_equalTo(60); make.height.mas_equalTo(23); }]; } - (void)setModel:(DRCollectionModel *)model { _model = model; [_iconView sd_setImageWithURL:[NSURL URLWithString:model.img]]; self.titleLabel.text = model.title; self.outTimeLabel.hidden = ![model.is_outdate boolValue]; self.ticketImg.hidden = [model.is_outdate boolValue]; self.sameButton.hidden = ![model.is_outdate boolValue]; self.endDateLabel.text = [NSString stringWithFormat:@"到期时间:%@",model.end_time]; self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]]; NSString *disPrice = [NSString stringWithFormat:@"¥%.2f",[model.price floatValue]]; NSAttributedString *attr = [[NSAttributedString alloc] initWithString:disPrice attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11], NSForegroundColorAttributeName:[UIColor YHColorWithHex:0x999999], NSStrikethroughColorAttributeName:[UIColor YHColorWithHex:0x999999], NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle|NSUnderlinePatternSolid)}]; self.disPriceLabel.attributedText = attr; self.ticketLabel.text = [NSString stringWithFormat:@"%@元券",model.coupon_price]; } - (void)setHistoryModel:(DRHistoryModel *)historyModel { _historyModel = historyModel; [_iconView sd_setImageWithURL:[NSURL URLWithString:historyModel.img]]; self.titleLabel.text = historyModel.title; BOOL isOutTime = [PublicFunction isOuttimeDate:historyModel.end_time]; self.outTimeLabel.hidden = !isOutTime; self.ticketImg.hidden = isOutTime; self.sameButton.hidden = !isOutTime; self.endDateLabel.text = [NSString stringWithFormat:@"到期时间:%@",historyModel.end_time]; self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f",[historyModel.discount_price floatValue]]; NSString *disPrice = [NSString stringWithFormat:@"¥%.2f",[historyModel.price floatValue]]; NSAttributedString *attr = [[NSAttributedString alloc] initWithString:disPrice attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11], NSForegroundColorAttributeName:[UIColor YHColorWithHex:0x999999], NSStrikethroughColorAttributeName:[UIColor YHColorWithHex:0x999999], NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle|NSUnderlinePatternSolid)}]; self.disPriceLabel.attributedText = attr; self.ticketLabel.text = [NSString stringWithFormat:@"%@元券",historyModel.coupon_price]; } /** 找相似 */ - (void)findSamiliar { if (self.similarClick) { self.similarClick(); } } #pragma mark ------------------ - (UIImageView *)iconView { if (!_iconView) { _iconView = [[UIImageView alloc] init]; _iconView.backgroundColor = [UIColor yhGrayColor]; } return _iconView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.textColor = [UIColor YHColorWithHex:0x444444]; _titleLabel.font = [UIFont systemFontOfSize:14]; _titleLabel.numberOfLines = 2; } return _titleLabel; } - (UILabel *)endDateLabel { if (!_endDateLabel) { _endDateLabel = [[UILabel alloc] init]; _endDateLabel.textColor = [UIColor YHColorWithHex:0x999999]; _endDateLabel.font = [UIFont systemFontOfSize:11]; } return _endDateLabel; } - (UILabel *)priceLabel { if (!_priceLabel) { _priceLabel = [[UILabel alloc] init]; _priceLabel.font = [UIFont systemFontOfSize:15]; _priceLabel.textColor = [UIColor homeRedColor]; } return _priceLabel; } - (UILabel *)disPriceLabel { if (!_disPriceLabel) { _disPriceLabel = [[UILabel alloc] init]; _disPriceLabel.font = [UIFont systemFontOfSize:11]; _disPriceLabel.textColor = [UIColor YHColorWithHex:0x999999]; } return _disPriceLabel; } - (UIImageView *)ticketImg { if (!_ticketImg) { _ticketImg = [[UIImageView alloc] init]; _ticketImg.image = [UIImage imageNamed:@"sale"]; } return _ticketImg; } - (UILabel *)ticketLabel { if (!_ticketLabel) { _ticketLabel = [[UILabel alloc] init]; _ticketLabel.textColor = [UIColor whiteColor]; _ticketLabel.font = [UIFont systemFontOfSize:14]; _ticketLabel.textAlignment = NSTextAlignmentCenter; _ticketLabel.backgroundColor = [UIColor clearColor]; } return _ticketLabel; } - (UILabel *)outTimeLabel { if (!_outTimeLabel) { _outTimeLabel = [[UILabel alloc] init]; _outTimeLabel.text = @"已过期"; _outTimeLabel.textAlignment = NSTextAlignmentCenter; _outTimeLabel.textColor = [UIColor whiteColor]; _outTimeLabel.font = [UIFont systemFontOfSize:12]; _outTimeLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6]; } return _outTimeLabel; } - (UIButton *)sameButton { if (!_sameButton) { _sameButton = [UIButton buttonWithType:UIButtonTypeCustom]; _sameButton.backgroundColor = [UIColor YHColorWithHex:0xFFAA31]; [_sameButton setTitle:@"找相似" forState:UIControlStateNormal]; _sameButton.titleLabel.textColor = [UIColor whiteColor]; _sameButton.titleLabel.font = [UIFont systemFontOfSize:13]; _sameButton.userInteractionEnabled = YES; [_sameButton addTarget:self action:@selector(findSamiliar) forControlEvents:UIControlEventTouchUpInside]; } return _sameButton; } @end