123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- //
- // DetailPriceExplainCell.m
- // FirstLink
- //
- // Created by jack on 15/7/20.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "DetailPriceExplainCell.h"
- @interface DetailPriceExplainCell ()
- @property (nonatomic, strong) UIView *cutLine;
- @property (nonatomic, strong) UIImageView *priceExplainView;
- @property (nonatomic, strong) NSLayoutConstraint *cutLineWidthConst;
- @property (nonatomic, strong) UILabel *vipPriceLabel;
- @property (nonatomic, strong) UILabel *referPriceTipLabel;
- @property (nonatomic, strong) UILabel *referPriceLabel;
- @property (nonatomic, strong) UILabel *collectLabel;
- @end
- @implementation DetailPriceExplainCell
- @synthesize priceLabel = _priceLabel;
- @synthesize helpBtn = _helpBtn;
- @synthesize referPriceLabel = _referPriceLabel;
- @synthesize countTimeLabel = _countTimeLabel;
- @synthesize collectBtn = _collectBtn;
- @synthesize cutLineWidthConst = _cutLineWidthConst;
- @synthesize cutLine = _cutLine;
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self initialize];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return self;
- }
- #pragma mark -
- - (void)setVipPrice:(NSString *)vipPrice {
- if (vipPrice.length > 0) {
- self.vipPriceLabel.hidden = NO;
- self.vipPriceLabel.text = [NSString stringWithFormat:@"VIP价格:%@", vipPrice];
- } else {
- self.vipPriceLabel.hidden = YES;
- [self.referPriceTipLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(15);
- make.centerY.equalTo(self.vipPriceLabel);
- }];
- }
- }
- #pragma method
- - (void)initialize{
- [self.contentView addSubview:self.priceLabel];
- [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(12);
- make.top.equalTo(self.contentView).offset(14);
- make.width.greaterThanOrEqualTo(@20);
- }];
-
- [self.contentView addSubview:self.helpBtn];
- [self.helpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.priceLabel.mas_right).offset(7);
- make.centerY.equalTo(self.priceLabel);
- }];
-
- [self.contentView addSubview:self.countTimeLabel];
- [self.countTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.helpBtn.mas_right).offset(7);
- make.centerY.equalTo(self.helpBtn);
- make.height.mas_equalTo(16);
- }];
-
- [self.contentView addSubview:self.priceExplainView];
- [self.priceExplainView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.helpBtn).offset(10);
- make.top.equalTo(self.priceLabel.mas_bottom);
- make.height.equalTo(@0);
- }];
-
- [self.contentView addSubview:self.vipPriceLabel];
- [self.vipPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(15);
- make.top.equalTo(self.priceExplainView.mas_bottom).offset(-12);
- make.bottom.equalTo(self.contentView);
- }];
-
- [self.contentView addSubview:self.referPriceTipLabel];
- [self.referPriceTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.vipPriceLabel.mas_right).offset(15);
- make.centerY.equalTo(self.vipPriceLabel);
- }];
-
- [self.contentView addSubview:self.referPriceLabel];
- [self.referPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.referPriceTipLabel.mas_right).offset(2);
- make.centerY.equalTo(self.referPriceTipLabel);
- }];
-
- [self.contentView addSubview:self.collectBtn];
- [self.collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView).offset(10);
- make.right.equalTo(self.contentView).offset(- 20);
- make.size.mas_equalTo(CGSizeMake(40, 40));
- }];
- [self.contentView addSubview:self.collectLabel];
- [self.collectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.collectBtn.mas_bottom).offset(- 3);
- make.centerX.equalTo(self.collectBtn);
- }];
- [self.contentView addSubview:self.cutLine];
- [self.cutLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self.referPriceLabel);
- make.height.equalTo(@0.5);
- make.width.equalTo(@0);
- }];
- }
- #pragma mark - DetailCellProtocol
- - (void)configWithDetailViewModel:(PindanDetailViewModel *)viewModel indexPath:(NSIndexPath *)indexPath{
-
- if (![viewModel isKindOfClass:[PindanDetailViewModel class]]) return;
-
- self.priceLabel.attributedText = [viewModel totalPriceAttributedString];
- self.referPrice = [FLStringHelper convertFenStringToYuanValue:[viewModel referPrice]];
- self.collectBtn.selected = [viewModel isFavorite];
-
- [self setVipPrice:[viewModel vipPrice]];
-
- if (viewModel.pindanState == kPindanStateWaitBegin) {
- [self resetTimeStrWithInterval:[viewModel timeInterval] isBegin:NO];
-
- }else if ([viewModel isProductStateSaleDone]) {
- self.priceLabel.textColor = UIColorFromRGB(0xcccccc);
- self.countTimeLabel.text = @"拼单已抢光";
- } else if ([viewModel isProductStateEnd]){
- self.priceLabel.textColor = UIColorFromRGB(0xcccccc);
- self.countTimeLabel.text = @"拼单已结束";
- } else{
- [self resetTimeStrWithInterval:[viewModel timeInterval] isBegin:YES];
- }
- }
- - (void)resetTimeStrWithInterval:(NSTimeInterval)timeCount isBegin:(BOOL)isBegin{
- if (isBegin) {
- self.countTimeLabel.text = [NSString stringWithFormat:@"剩余%@", [FLStringHelper convertTimeIntervalToCountString:timeCount]];
- }else{
- NSString *timeStr = [FLStringHelper convertTimeIntervalToCountString:timeCount];
- NSString *lastStr = @" 后开启";
- NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@", timeStr, lastStr]];
- [attr addAttribute:NSForegroundColorAttributeName value:APP_BUTTON_COLOR range:NSMakeRange(timeStr.length, lastStr.length)];
- self.countTimeLabel.attributedText = attr;
- }
- }
- #pragma mark - event response
- - (void)helpBtnClick:(UIButton *)sender {
- _showHelpeView = !_showHelpeView;
- [self changePriceExplainViewLayout];
- if ([self.delegate respondsToSelector:@selector(priceDetailCell:showPriceExplain:)]) {
- [self.delegate priceDetailCell:self showPriceExplain:_showHelpeView];
- }
- }
- - (void)changePriceExplainViewLayout {
- __block typeof(_showHelpeView) block_showHelper = _showHelpeView;
- [self.priceExplainView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.helpBtn).offset(45);
- make.top.equalTo(self.priceLabel.mas_bottom).offset(2);
- if (!block_showHelper) {
- make.height.equalTo(@0);
- }
- }];
- }
- #pragma mark - getter && setter
- - (UILabel *)priceLabel {
- if (_priceLabel == nil) {
- _priceLabel = [[UILabel alloc]init];
- _priceLabel.backgroundColor = [UIColor clearColor];
- _priceLabel.textColor = UIColorFromRGB(0x333333);
- _priceLabel.font = [UIFont boldSystemFontOfSize:18];
- _priceLabel.textAlignment = NSTextAlignmentCenter;
- [_priceLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
- }
- return _priceLabel;
- }
- - (UIButton *)helpBtn {
- if (_helpBtn == nil) {
- _helpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_helpBtn setImage:[UIImage imageNamed:@"detail_info"] forState:UIControlStateNormal];
- [_helpBtn addTarget:self action:@selector(helpBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _helpBtn;
- }
- - (UILabel *)countTimeLabel {
- if (_countTimeLabel == nil) {
- _countTimeLabel = [[UILabel alloc]init];
- _countTimeLabel.backgroundColor = [UIColor clearColor];
- _countTimeLabel.textColor = UIColorFromRGB(0x666666);
- _countTimeLabel.font = [UIFont systemFontOfSize:13];
- _countTimeLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _countTimeLabel;
- }
- - (UIImageView *)priceExplainView {
- if (_priceExplainView == nil) {
- _priceExplainView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"details_body_explanation1_n"]];
- [_priceExplainView setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
- }
- return _priceExplainView;
- }
- - (UILabel *)vipPriceLabel {
- if (_vipPriceLabel == nil) {
- _vipPriceLabel = [[UILabel alloc]init];
- _vipPriceLabel.backgroundColor = [UIColor clearColor];
- _vipPriceLabel.textColor = UIColorFromRGB(0x999999);
- _vipPriceLabel.font = [UIFont systemFontOfSize:11];
- _vipPriceLabel.textAlignment = NSTextAlignmentCenter;
- _vipPriceLabel.text = @"¥-.--";
- }
- return _vipPriceLabel;
- }
- - (UILabel *)referPriceLabel {
- if (_referPriceLabel == nil) {
- _referPriceLabel = [[UILabel alloc]init];
- _referPriceLabel.backgroundColor = [UIColor clearColor];
- _referPriceLabel.textColor = UIColorFromRGB(0x999999);
- _referPriceLabel.font = [UIFont systemFontOfSize:11];
- _referPriceLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _referPriceLabel;
- }
- - (UIButton *)collectBtn {
- if (_collectBtn == nil) {
- _collectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_collectBtn setImage:[UIImage imageNamed:@"detail_collect_n"] forState:UIControlStateNormal];
- [_collectBtn setImage:[UIImage imageNamed:@"collectHeartSelected"] forState:UIControlStateSelected];
- _collectBtn.alpha = 0.8;
- }
- return _collectBtn;
- }
- - (UIView *)cutLine {
- if (_cutLine == nil) {
- _cutLine = [[UIView alloc]init];
- _cutLine.backgroundColor = UIColorFromRGB(0x999999);
- }
- return _cutLine;
- }
- - (NSLayoutConstraint *)cutLineWidthConst {
- if (_cutLineWidthConst == nil) {
- for (NSLayoutConstraint *constraint in self.cutLine.constraints) {
- if (constraint.firstItem == self.cutLine && constraint.firstAttribute == NSLayoutAttributeWidth) {
- _cutLineWidthConst = constraint;
- break;
- }
- }
- }
- return _cutLineWidthConst;
- }
- - (void)setShowHelpeView:(BOOL)showHelpeView {
- _showHelpeView = showHelpeView;
- [self changePriceExplainViewLayout];
- }
- - (UILabel *)referPriceTipLabel {
- if (_referPriceTipLabel == nil) {
- _referPriceTipLabel = [[UILabel alloc]init];
- _referPriceTipLabel.text = @"国内价:";
- _referPriceTipLabel.textColor = UIColorFromRGB(0x999999);
- _referPriceTipLabel.font = [UIFont systemFontOfSize:11];
- }
- return _referPriceTipLabel;
- }
- - (UILabel *)collectLabel {
- if (_collectLabel == nil) {
- _collectLabel = [[UILabel alloc]init];
- _collectLabel.text = @"收藏";
- _collectLabel.font = [UIFont systemFontOfSize:12];
- _collectLabel.textColor = UIColorFromRGB(0x999999);
- }
- return _collectLabel;
- }
- - (void)setReferPrice:(CGFloat)referPrice {
- self.cutLine.hidden = YES;
- if (referPrice <= 0) {
- self.referPriceTipLabel.text = @"";
- self.referPriceLabel.text = @"国内无售";
- } else {
- self.cutLine.hidden = NO;
- self.referPriceLabel.text = [NSString stringWithFormat:@"¥%.2f",referPrice];
- CGRect stringRect = [FLStringHelper rectOfString:self.referPriceLabel.text font:self.referPriceLabel.font height:CGFLOAT_MAX];
- self.cutLineWidthConst.constant = CGRectGetWidth(stringRect);
- }
- }
- @end
|