CNLiveCMineInteDetailHeaderView.m 7.02 KB
//
//  CNLiveCMineInteDetailHeaderView.m
//  CNLiveCMineModule
//
//  Created by open on 2021/12/29.
//

#import "CNLiveCMineInteDetailHeaderView.h"

@interface CNLiveCMineInteDetailHeaderView()
@property (nonatomic, strong) UILabel * inteLabel;
@property (nonatomic, strong) QMUIButton * dateButton;
@property (nonatomic, strong) UILabel * spendLabel;//支出
@property (nonatomic, strong) UILabel * obtaLabel;//获取
@end

@implementation CNLiveCMineInteDetailHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.inteLabel];
        [self addSubview:self.dateButton];
        [self addSubview:self.obtaLabel];
        [self addSubview:self.spendLabel];
    }
    return self;
}
-(void)setDetailModel:(CNLiveCMineInteDetailModel *)detailModel
{
    _detailModel = detailModel;
    
    NSMutableAttributedString * coin_string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@积分",[detailModel.currentInte isNotBlank]?detailModel.currentInte:@"0"]];
    [coin_string addAttribute:NSFontAttributeName value:UIFontCNMake(12) range:[coin_string.string rangeOfString:@"积分"]];
    [coin_string addAttribute:NSFontAttributeName value:UIFontBoldCNMake(35) range:NSMakeRange(0, [coin_string.string rangeOfString:@"积分"].location)];
    self.inteLabel.attributedText = coin_string;
    

    NSMutableAttributedString * spend_string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"获取:%@",[detailModel.obtainIntegral isNotBlank]?detailModel.obtainIntegral:@"0"]];
    [spend_string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11] range:[spend_string.string rangeOfString:@"获取:"]];
    [spend_string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, [spend_string.string rangeOfString:@"获取:"].location)];
    self.spendLabel.attributedText = spend_string;
    
    NSMutableAttributedString * obta_string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"支出:%@",[detailModel.payIntegral isNotBlank]?detailModel.payIntegral:@"0"]];
    [obta_string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11] range:[obta_string.string rangeOfString:@"支出:"]];
    [obta_string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, [obta_string.string rangeOfString:@"支出:"].location)];
    self.obtaLabel.attributedText = obta_string;
    
    NSArray * array = [detailModel.date_string componentsSeparatedByString:@"-"];
    [self.dateButton setTitle:[NSString stringWithFormat:@"%@年%@月",array.firstObject,array.lastObject] forState:UIControlStateNormal];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    __weak typeof(self) weakSelf = self;
    [self.inteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(weakSelf).offset(10);
    }];
    [self.dateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf).offset(10);
        make.top.mas_equalTo(weakSelf.inteLabel.mas_bottom).offset(30);
    }];
    [self.obtaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.dateButton);
        make.right.mas_equalTo(weakSelf.mas_right).offset(-5);
    }];
    [self.spendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.dateButton);
        make.right.mas_equalTo(weakSelf.obtaLabel.mas_left).offset(-5);
    }];
}
-(void)pushDateSelectAction:(QMUIButton *)button
{
    if (self.selectWithDateBlock) self.selectWithDateBlock();
}
#pragma mark =
- (UILabel *)inteLabel
{
    if (!_inteLabel) {
        _inteLabel = [[UILabel alloc] init];
        _inteLabel.backgroundColor = [UIColor clearColor];
        _inteLabel.textColor = UIColorHex(#FFFFFF);
        
        NSMutableAttributedString * coin_string = [[NSMutableAttributedString alloc] initWithString:@"0积分"];
        [coin_string addAttribute:NSFontAttributeName value:UIFontCNMake(12) range:[coin_string.string rangeOfString:@"积分"]];
        [coin_string addAttribute:NSFontAttributeName value:UIFontBoldCNMake(35) range:NSMakeRange(0, [coin_string.string rangeOfString:@"积分"].location)];
        _inteLabel.attributedText = coin_string;
    }
    return _inteLabel;
}
- (UILabel *)spendLabel
{
    if (!_spendLabel) {
        _spendLabel = [[UILabel alloc] init];
        _spendLabel.backgroundColor = [UIColor clearColor];
        _spendLabel.textColor = UIColorHex(#FFFFFF);
        
        NSMutableAttributedString * spend_string = [[NSMutableAttributedString alloc] initWithString:@"获取:0"];
        [spend_string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11] range:[spend_string.string rangeOfString:@"获取:"]];
        [spend_string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, [spend_string.string rangeOfString:@"获取:"].location)];
        _spendLabel.attributedText = spend_string;
    }
    return _spendLabel;
}
- (UILabel *)obtaLabel
{
    if (!_obtaLabel) {
        _obtaLabel = [[UILabel alloc] init];
        _obtaLabel.backgroundColor = [UIColor clearColor];
        _obtaLabel.textColor = UIColorHex(#FFFFFF);
        
        NSMutableAttributedString * obta_string = [[NSMutableAttributedString alloc] initWithString:@"支出:0"];
        [obta_string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:11] range:[obta_string.string rangeOfString:@"支出:"]];
        [obta_string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0, [obta_string.string rangeOfString:@"支出:"].location)];
        _obtaLabel.attributedText = obta_string;
    }
    return _obtaLabel;
}
-(QMUIButton *)dateButton
{
    if (!_dateButton) {
        _dateButton = [[QMUIButton alloc] init];
        [_dateButton setImage:[CNLiveCMineService imageWithMineName:@"c_mine_content_date_tira"] forState:UIControlStateNormal];
        [_dateButton setTitleColor:UIColorHex(0xFFFFFF) forState:UIControlStateNormal];
        _dateButton.titleLabel.font = [UIFont systemFontOfSize:12];
        _dateButton.backgroundColor = [UIColor clearColor];
        _dateButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _dateButton.spacingBetweenImageAndTitle = 2.5;
        _dateButton.imageEdgeInsets = UIEdgeInsetsMake(0, 2.5, 0, 2.5);
        _dateButton.imagePosition = QMUIButtonImagePositionLeft;
        [_dateButton addTarget:self action:@selector(pushDateSelectAction:) forControlEvents:UIControlEventTouchUpInside];
        
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM"];
        NSArray * dateArray = [[dateFormatter stringFromDate:[NSDate date]] componentsSeparatedByString:@"-"];
        NSString * s = [NSString stringWithFormat:@"%@年%@月",dateArray.firstObject,dateArray.lastObject];
        [_dateButton setTitle:s forState:UIControlStateNormal];
    }
    return _dateButton;
}

@end