CNLiveCMineInteHeaderView.m 6.53 KB
//
//  CNLiveCMineInteHeaderView.m
//  CNLiveCMineModule
//
//  Created by open on 2021/12/27.
//

#import "CNLiveCMineInteHeaderView.h"
#import "CNLiveCMineInteHeaderSignView.h"
#import "CNLiveCMineHeader.h"
@interface CNLiveCMineInteHeaderView()
@property (nonatomic, strong) QMUIButton * detailBtn;
@property (nonatomic, strong) UILabel * inteLabel;
@property (nonatomic, strong) UIButton * pushMallBtn;
@property (nonatomic, strong) CNLiveCMineInteHeaderSignView * signView;
@property (nonatomic, strong) UILabel * titleLabel;

@property (nonatomic, strong) CNLiveCMineInteScoreModel * scoreModel;  //签到数据
@property (nonatomic, strong) CNLiveCMineInteTaskListModel * taskModel;//任务列表及积分数据
@property (nonatomic, strong) CNLiveCMineInteListModel * announModel;  //公告数据
@property (nonatomic, strong) CNLiveCMineInteListModel * activModel;   //活动数据
@end

@implementation CNLiveCMineInteHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.detailBtn];
        [self addSubview:self.inteLabel];
        [self addSubview:self.pushMallBtn];
        [self addSubview:self.signView];
        [self addSubview:self.titleLabel];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    __weak typeof(self) weakSelf = self;
    [self.detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf).offset(10);
        make.left.mas_equalTo(weakSelf).offset(15);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(25);
    }];
    [self.inteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.detailBtn.mas_bottom).offset(5);
        make.left.mas_equalTo(weakSelf).offset(15);
    }];
    [self.pushMallBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(weakSelf.inteLabel.mas_bottom).offset(-5);
        make.right.mas_equalTo(weakSelf);
    }];
    [self.signView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf).offset(10);
        make.right.mas_equalTo(weakSelf).offset(-10);
        make.top.mas_equalTo(weakSelf.inteLabel.mas_bottom).offset(15);
        make.height.mas_equalTo(180);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(weakSelf.mas_bottom).offset(-10);
        make.left.mas_equalTo(weakSelf.signView.mas_left);
    }];
}
-(void)pushMallAction:(UIButton *)btn
{
    if (self.clickActionBlock) self.clickActionBlock(self.scoreModel, self.taskModel, self.announModel,CNLiveCMineInteHeaderClickMall);
}
-(void)pushScoreDetailAction:(UIButton *)btn
{
    if (self.clickActionBlock) self.clickActionBlock(self.scoreModel, self.taskModel, self.announModel,CNLiveCMineInteHeaderClickDetail);
}
#pragma mark =
/// 对headerView的数据进行赋值
/// @param scoreModel 签到数据
/// @param taskModel 任务数据
/// @param announModel 公告数据
-(void)setupWithScoreModel:(CNLiveCMineInteScoreModel *)scoreModel
                 taskModel:(CNLiveCMineInteTaskListModel *)taskModel
               announModel:(CNLiveCMineInteListModel *)announModel
                activModel:(CNLiveCMineInteListModel *)activModel
{
    _scoreModel = scoreModel;
    _taskModel = taskModel;
    _announModel = announModel;
    _activModel = activModel;
    [self.signView setupWithScoreModel:scoreModel taskModel:taskModel announModel:announModel activModel:activModel];
    NSMutableAttributedString * coin_string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@积分",[taskModel.integral isNotBlank]?taskModel.integral:@"0"]];
    [coin_string addAttribute:NSFontAttributeName value:UIFontCNMake(12) range:[coin_string.string rangeOfString:@"积分"]];
    [coin_string addAttribute:NSFontAttributeName value:UIFontBoldCNMake(30) range:NSMakeRange(0, [coin_string.string rangeOfString:@"积分"].location)];
    self.inteLabel.attributedText = coin_string;
    self.titleLabel.hidden = activModel == nil;
}
#pragma mark =
-(CNLiveCMineInteHeaderSignView *)signView
{
    if (!_signView) {
        __weak typeof(self) weakSelf = self;
        _signView = [[CNLiveCMineInteHeaderSignView alloc] init];
        _signView.backgroundColor = [UIColor clearColor];
        _signView.clickActionBlock = ^(CNLiveCMineInteScoreModel * _Nonnull scoreModel, CNLiveCMineInteTaskListModel * _Nonnull taskModel, CNLiveCMineInteListModel * _Nonnull announModel, CNLiveCMineInteHeaderClick headerClick) {
            if (weakSelf.clickActionBlock) weakSelf.clickActionBlock(scoreModel, taskModel, announModel, headerClick);
        };
    }
    return _signView;
}
-(UIButton *)pushMallBtn
{
    if (!_pushMallBtn) {
        _pushMallBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _pushMallBtn.backgroundColor = [UIColor clearColor];
        [_pushMallBtn setImage:[CNLiveCMineService imageWithMineName:@"c_mine_skip_push_mall"] forState:UIControlStateNormal];
        [_pushMallBtn addTarget:self action:@selector(pushMallAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _pushMallBtn;
}
-(QMUIButton *)detailBtn
{
    if (!_detailBtn) {
        _detailBtn = [[QMUIButton alloc] init];
        [_detailBtn setTitle:@"积分明细" forState:UIControlStateNormal];
        [_detailBtn setImage:[CNLiveCMineService imageWithMineName:@"c_mine_skip_inte_detail"] forState:UIControlStateNormal];
        [_detailBtn setTitleColor:UIColorHex(0x481A19) forState:UIControlStateNormal];
        _detailBtn.titleLabel.font = UIFontCNMake(14);
        _detailBtn.backgroundColor = [UIColor clearColor];
        _detailBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _detailBtn.spacingBetweenImageAndTitle = 1;
        _detailBtn.imagePosition = QMUIButtonImagePositionRight;
        [_detailBtn addTarget:self action:@selector(pushScoreDetailAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _detailBtn;
}
- (UILabel *)inteLabel
{
    if (!_inteLabel) {
        _inteLabel = [[UILabel alloc] init];
        _inteLabel.backgroundColor = [UIColor clearColor];
        _inteLabel.textColor = UIColorHex(0x481A19);
    }
    return _inteLabel;
}
-(UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = UIFontCNMake(15);
        _titleLabel.font = UIFontBoldCNMake(15);
        _titleLabel.text = @"积分乐园";
        _titleLabel.hidden = YES;
    }
    return _titleLabel;
}
@end