CNLiveCMineInteHeaderSignView.m 12 KB
//
//  CNLiveCMineInteHeaderSignView.m
//  CNLiveCMineModule
//
//  Created by open on 2021/12/28.
//

#import "CNLiveCMineInteHeaderSignView.h"

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

@property (nonatomic, strong) UIView * topView;
@property (nonatomic, strong) CAShapeLayer *topMaskLayer;
@property (nonatomic, strong) CAGradientLayer *topGradientLayer;
@property (nonatomic, strong) UILabel * nameLabel;//
@property (nonatomic, strong) UIView * bottemView;
@property (nonatomic, strong) QMUIMarqueeLabel * annouLabel;//公告label
@property (nonatomic, strong) UIImageView * iconView;
@property (nonatomic, strong) UIImageView * moreView;
@property (nonatomic, strong) UIButton * clearButton;

@property (nonatomic, strong) UILabel * titleLabel;
@property (nonatomic, strong) NSMutableArray * coinsViews;
@property (nonatomic, strong) NSMutableArray * numberViews;
@end

@implementation CNLiveCMineInteHeaderSignView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.coinsViews = [[NSMutableArray alloc] init];
        self.numberViews = [[NSMutableArray alloc] init];
        [self addSubview:self.bottemView];
        [self addSubview:self.topView];
        [self addSubview:self.titleLabel];
        [self.topView addSubview:self.nameLabel];
        
        [self.bottemView addSubview:self.annouLabel];
        [self.bottemView addSubview:self.iconView];
        [self.bottemView addSubview:self.moreView];
        [self.bottemView addSubview:self.clearButton];
        [self setupWithCoinsVeiw];
    }
    return self;
}
-(void)setupWithCoinsVeiw
{
    UIView * coinsView = [[UIView alloc] initWithFrame:CGRectMake(5, 40, SCREEN_WIDTH - 30, 90)];
    coinsView.backgroundColor = [UIColor clearColor];
    [self.topView addSubview:coinsView];
    
    CGFloat item_w = (SCREEN_WIDTH - 60)/7;
    CGFloat item_h = item_w * 1.33;
    for (int i = 0; i < 7; i++) {
        UIView * temp_v = [[UIView alloc] initWithFrame:CGRectMake(i * (item_w + 5), 0, item_w, 90)];
        temp_v.backgroundColor = [UIColor clearColor];
        [coinsView addSubview:temp_v];
        
        UIImageView * coinsV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, item_w, item_h)];
        coinsV.image = [UIImage imageWithColor:[UIColor colorWithWhite:0 alpha:0.3]];
        coinsV.layer.masksToBounds = YES;
        coinsV.layer.cornerRadius = 5;
        [temp_v addSubview:coinsV];
        [self.coinsViews addObject:coinsV];
        
        UIImageView * coins = [[UIImageView alloc] initWithFrame:CGRectMake((item_w - 30)/2, 10, 30, 30)];
        coins.image = [CNLiveCMineService imageWithMineName:@"c_mine_content_gold_coins"];
        coins.backgroundColor = [UIColor clearColor];
        [coinsV addSubview:coins];
        
        UILabel * numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, item_w, 20)];
        numberLabel.backgroundColor = [UIColor clearColor];
        numberLabel.textColor = [UIColor whiteColor];
        numberLabel.textAlignment = NSTextAlignmentCenter;
        numberLabel.font = [UIFont systemFontOfSize:10];
        numberLabel.text = [NSString stringWithFormat:@"+%d",(i + 1) * 1000];
        [coinsV addSubview:numberLabel];
        [self.numberViews addObject:numberLabel];
        
        UILabel * dayLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, item_h + 5, item_w, 20)];
        dayLabel.backgroundColor = [UIColor clearColor];
        dayLabel.textColor = [UIColor whiteColor];
        dayLabel.textAlignment = NSTextAlignmentCenter;
        dayLabel.font = [UIFont systemFontOfSize:14];
        dayLabel.text = [NSString stringWithFormat:@"%d天",i+1];
        [temp_v addSubview:dayLabel];
    }
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    __weak typeof(self) weakSelf = self;
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(weakSelf);
        make.bottom.mas_equalTo(weakSelf).offset(-40);
    }];
    [self.bottemView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.topView.mas_bottom).offset(-15);
        make.left.right.mas_equalTo(weakSelf);
        make.bottom.mas_equalTo(weakSelf);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.bottemView.mas_bottom).offset(10);
        make.left.mas_equalTo(weakSelf.mas_left);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(weakSelf).offset(15);
    }];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.bottemView).offset(5);
        make.left.mas_equalTo(weakSelf.bottemView.mas_left).offset(30);
    }];
    [self.moreView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.iconView);
        make.right.mas_equalTo(weakSelf.bottemView.mas_right).offset(-20);
    }];
    [self.annouLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.iconView);
        make.left.mas_equalTo(weakSelf.iconView.mas_right).offset(20);
        make.right.mas_equalTo(weakSelf.moreView.mas_left).offset(-10);
    }];
    [self.clearButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(weakSelf.bottemView);
    }];
    self.topMaskLayer.frame = self.topView.bounds;
    self.topGradientLayer.frame = self.topView.frame;
}

/// 数据进行赋值
/// @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;
    NSArray * array = [scoreModel.scores.firstObject componentsSeparatedByString:@","];
    if (array.count == 0) array = @[@"1000",@"2000",@"3000",@"4000",@"5000",@"6000",@"7000"];
    NSInteger index = [array indexOfObject:scoreModel.score];
    if (scoreModel) {
        for (int i = 0; i < self.numberViews.count; i++) {
            UILabel * numberLabel = self.numberViews[i];
            UIImageView * coinsV = self.coinsViews[i];
            numberLabel.text = [NSString stringWithFormat:@"+%@",array.count >= self.numberViews.count ? array[i] : @""];
            numberLabel.textColor = index >= i ? [UIColor blackColor] : [UIColor whiteColor];
            coinsV.image = index >= i ? [CNLiveCMineService imageWithMineName:@"c_mine_content_gold_select"] : [UIImage imageWithColor:[UIColor colorWithWhite:0 alpha:0.3]];
        }
        self.nameLabel.text = [NSString stringWithFormat:@"已连续签到 %ld天",index + 1];
    }else{
        self.nameLabel.text = @"已连续签到 0天";
    }
    self.titleLabel.hidden = activModel == nil;
    self.bottemView.hidden = announModel.list.count == 0;
    self.iconView.hidden = announModel.list.count == 0;
    self.moreView.hidden = announModel.list.count == 0;
    self.annouLabel.hidden = announModel.list.count == 0;
    if (announModel.list.count > 0) {
        NSMutableArray * listArray = announModel.list.mutableCopy;
        NSArray * tempArray = announModel.list.count > 5 ? [listArray subarrayWithRange:NSMakeRange(0, 4)] : listArray;
        NSMutableString * tempString = [[NSMutableString alloc] init];
        for (CNLiveCMineInteListSubModel * subModel in tempArray) {
            [tempString appendFormat:@"%@    ",subModel.title];
        }
        self.annouLabel.text = tempString;
    }
    
    if (announModel == nil) self.titleLabel.top = CGRectGetMaxY(self.topView.frame) + 10;
    
}
-(void)pushAnnouMedthod:(UIButton *)button
{
    if (self.clickActionBlock) self.clickActionBlock(self.scoreModel, self.taskModel, self.announModel,CNLiveCMineInteHeaderClickAnnotation);
}
#pragma mark =
-(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;
}
-(UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = [UIColor whiteColor];
        _nameLabel.font = UIFontCNMake(15);
        _nameLabel.font = UIFontBoldCNMake(15);
    }
    return _nameLabel;
}
-(UIButton *)clearButton
{
    if (!_clearButton) {
        _clearButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _clearButton.backgroundColor = [UIColor clearColor];
        [_clearButton addTarget:self action:@selector(pushAnnouMedthod:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _clearButton;
}
-(QMUIMarqueeLabel *)annouLabel
{
    if (!_annouLabel) {
        _annouLabel = [[QMUIMarqueeLabel alloc] qmui_initWithFont:[UIFont fontWithName:@"PingFangSC-Medium" size:13] textColor:UIColorHex(666666)];
        _annouLabel.textAlignment = NSTextAlignmentCenter;
        _annouLabel.automaticallyValidateVisibleFrame = NO;
        [_annouLabel qmui_calculateHeightAfterSetAppearance];
        _annouLabel.shouldFadeAtEdge = YES;
        _annouLabel.backgroundColor = kWhiteColor;
        _annouLabel.fadeWidthPercent = 0.1;
        _annouLabel.pauseDurationWhenMoveToEdge = 0;
        _annouLabel.speed = 1;// 调节滚动速度
    }
    return _annouLabel;
}
-(UIImageView *)iconView
{
    if (!_iconView) {
        _iconView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _iconView.contentMode = UIViewContentModeScaleAspectFill;
        _iconView.backgroundColor = [UIColor whiteColor];
        _iconView.image = [CNLiveCMineService imageWithMineName:@"c_mine_content_announ"];
    }
    return _iconView;
}
-(UIImageView *)moreView
{
    if (!_moreView) {
        _moreView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _moreView.contentMode = UIViewContentModeScaleAspectFill;
        _moreView.backgroundColor = [UIColor whiteColor];
        _moreView.image = [CNLiveCMineService imageWithMineName:@"c_mine_skip_more"];
    }
    return _moreView;
}
- (UIView *)topView
{
    if (!_topView) {
        _topView = [[UIView alloc] init];
        _topView.backgroundColor = [UIColor whiteColor];

        CAGradientLayer *topGradientLayer = [CAGradientLayer layer];
        topGradientLayer.colors = @[(__bridge id)UIColorHex(0xfe7b72).CGColor, (__bridge id)UIColorHex(0xf85948).CGColor];
        topGradientLayer.locations = @[@0.5, @1.0];
        topGradientLayer.startPoint = CGPointMake(0, 0);
        topGradientLayer.endPoint = CGPointMake(1.0, 0);
        [_topView.layer addSublayer:topGradientLayer];
        _topGradientLayer = topGradientLayer;

        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 20, 130) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12, 12)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.path = maskPath.CGPath;
        _topView.layer.mask = maskLayer;
        _topMaskLayer = maskLayer;
    }
    return _topView;
}
-(UIView *)bottemView
{
    if (!_bottemView) {
        _bottemView = [[UIView alloc] init];
        _bottemView.backgroundColor = [UIColor whiteColor];
        _bottemView.layer.cornerRadius = 12;
        _bottemView.layer.masksToBounds = YES;//超出父视图部分不显示。
        _bottemView.layer.borderColor = UIColorMakeWithRGBA(234, 7, 15, 0.3).CGColor;
        _bottemView.layer.borderWidth = 0.5;
    }
    return _bottemView;
}
@end