// // HSQCommunityRightCell.m // YouHuiProject // // Created by 小花 on 2018/8/7. // Copyright © 2018年 kuxuan. All rights reserved. // #import "HSQCommunityRightCell.h" #import "CPFindIconView.h" #import "PhoneLoginManager.h" @interface HSQCommunityRightCell () @property (nonatomic, strong) UIImageView *iconView; @property (nonatomic, strong) UILabel *titleLb; @property (nonatomic, strong) UILabel *desLabel1; @property (nonatomic, strong) UILabel *desLabel2; @property (nonatomic, strong) UILabel *disPrice; @property (nonatomic, strong) CPFindIconView *icons; @property (nonatomic, strong) UIButton *shareBtn; @property (nonatomic, strong) UILabel *commissionLb; @end @implementation HSQCommunityRightCell + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *cellID = nil; cellID = NSStringFromClass([self class]); HSQCommunityRightCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[HSQCommunityRightCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } 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.backgroundColor = [UIColor yhGrayColor]; [self initSubViews]; } return self; } - (void)initSubViews { UIView *bg = [[UIView alloc] init]; bg.backgroundColor = [UIColor whiteColor]; bg.layer.cornerRadius = Fitsize(5); [self.contentView addSubview:bg]; [bg mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(Fitsize(10)); make.right.mas_equalTo(Fitsize(-10)); make.top.mas_equalTo(Fitsize(5)); make.bottom.mas_equalTo(Fitsize(-5)); }]; [bg addSubview:self.iconView]; [bg addSubview:self.titleLb]; [bg addSubview:self.desLabel1]; [bg addSubview:self.desLabel2]; [bg addSubview:self.disPrice]; [bg addSubview:self.icons]; [bg addSubview:self.shareBtn]; [bg addSubview:self.commissionLb]; [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.mas_equalTo(Fitsize(10)); make.width.height.mas_equalTo(Fitsize(104)); }]; [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.iconView.mas_right).mas_offset(Fitsize(10)); make.top.mas_equalTo(self.iconView.mas_top).mas_offset(Fitsize(5)); make.right.mas_equalTo(Fitsize(-10)); }]; [self.desLabel1 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLb); make.top.mas_equalTo(self.titleLb.mas_bottom).mas_offset(Fitsize(5)); make.right.mas_equalTo(Fitsize(-10)); }]; [self.desLabel2 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLb); make.top.mas_equalTo(self.desLabel1.mas_bottom).mas_offset(Fitsize(5)); make.right.mas_equalTo(Fitsize(-10)); }]; [self.disPrice mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLb); make.bottom.mas_equalTo(self.iconView.mas_bottom); }]; [self.icons mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.iconView.mas_bottom).mas_offset(Fitsize(10)); make.left.mas_equalTo(Fitsize(10)); make.right.mas_equalTo(0); make.height.mas_equalTo(Fitsize(40)); }]; [self.shareBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(57); make.height.mas_equalTo(20); make.centerY.mas_equalTo(self.icons.mas_centerY); make.right.mas_equalTo(-10); }]; [self.commissionLb mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(self.disPrice.mas_bottom); make.right.mas_equalTo(self.shareBtn.mas_right); }]; } - (void)shareAction { if (self.shareClick) { self.shareClick(); } } - (void)setModel:(HSQCommunityRightModel *)model { _model = model; self.titleLb.text = model.title; self.desLabel1.text = model.desc1; self.desLabel2.text = model.desc2; self.commissionLb.text = [NSString stringWithFormat:@"预估佣金:¥%@",model.commission_price]; self.disPrice.text = [NSString stringWithFormat:@"券后¥%.2f",[model.discount_price floatValue]]; [self.iconView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil]; [self.icons configViewWithIcons:model.headimg upCount:model.share_count]; if ([[PhoneLoginManager shareManager].showPhoneBtn boolValue]) { self.commissionLb.hidden = YES; }else { if (model.commission_price.length > 0) { self.commissionLb.hidden = NO; }else { self.commissionLb.hidden = YES; } } } - (UIImageView *)iconView { if (!_iconView) { _iconView = [[UIImageView alloc] init]; _iconView.layer.cornerRadius = Fitsize(5); _iconView.backgroundColor = [UIColor yhGrayColor]; } return _iconView; } - (UILabel *)titleLb { if (!_titleLb) { _titleLb = [[UILabel alloc] init]; _titleLb.font = [UIFont systemFontOfSize:Fitsize(14)]; _titleLb.textColor = [UIColor YHColorWithHex:0x333333]; _titleLb.numberOfLines = 2; _titleLb.text = @"标题加载中..."; } return _titleLb; } - (UILabel *)desLabel1 { if (!_desLabel1) { _desLabel1 = [[UILabel alloc] init]; _desLabel1.font = [UIFont systemFontOfSize:Fitsize(14)]; _desLabel1.textColor = [UIColor YHColorWithHex:0x999999]; } return _desLabel1; } - (UILabel *)desLabel2 { if (!_desLabel2) { _desLabel2 = [[UILabel alloc] init]; _desLabel2.font = [UIFont systemFontOfSize:Fitsize(14)]; _desLabel2.textColor = [UIColor YHColorWithHex:0x999999]; } return _desLabel2; } - (UILabel *)disPrice { if (!_disPrice) { _disPrice = [[UILabel alloc] init]; _disPrice.font = [UIFont boldSystemFontOfSize:Fitsize(14)]; _disPrice.textColor = [UIColor homeRedColor]; _disPrice.text = @"券后¥--"; } return _disPrice; } - (CPFindIconView *)icons { if (!_icons) { _icons = [[CPFindIconView alloc] init]; _icons.backgroundColor = [UIColor whiteColor]; } return _icons; } - (UIButton *)shareBtn { if (!_shareBtn) { _shareBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_shareBtn setImage:[UIImage imageNamed:@"right_share"] forState:UIControlStateNormal]; [_shareBtn addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside]; } return _shareBtn; } - (UILabel *)commissionLb { if (!_commissionLb) { _commissionLb = [[UILabel alloc] init]; _commissionLb.textColor = [UIColor homeRedColor]; _commissionLb.font = [UIFont systemFontOfSize:Fitsize(12)]; _commissionLb.textAlignment = NSTextAlignmentRight; } return _commissionLb; } @end