ScoreLevelView.m 4.4 KB
//
//  ScoreLevelView.m
//  DreamSleep
//
//  Created by peter on 2022/7/2.
//

#import "ScoreLevelView.h"

@interface ScoreLevelView ()
@property (nonatomic, strong) UIImageView *cardIV;
@property (nonatomic, strong) UILabel *curRankNameLab;
@property (nonatomic, strong) UILabel *totalPointsLab;
@property (nonatomic, strong) UIImageView *rewardIV;
@property (nonatomic, strong) UIButton *rulesBtn;
@property (nonatomic, strong) UILabel *curRankLab;
@property (nonatomic, strong) UILabel *nextRankLab;
@end

@implementation ScoreLevelView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self debugViewShowBorder];
        
        [self addSubview:self.cardIV];
        [self addSubview:self.curRankNameLab];
        [self addSubview:self.totalPointsLab];
        [self addSubview:self.rewardIV];
        [self addSubview:self.rulesBtn];
        [self addSubview:self.curRankLab];
        [self addSubview:self.nextRankLab];
        
        CGFloat h = 150*(kScreenWidth - 30)/345;
        [self.cardIV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(15);
            make.right.equalTo(self).offset(-15);
            make.bottom.equalTo(self).offset(-24);
            make.height.equalTo(@(h));
        }];
        [self.rewardIV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.cardIV);
            make.left.equalTo(self.curRankNameLab.mas_right).offset(23);
            make.size.mas_equalTo(CGSizeMake(79, 78));
        }];
        [self.rulesBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.cardIV).offset(14);
            make.right.equalTo(self.cardIV).offset(-9);
            make.size.mas_equalTo(CGSizeMake(64, 21));
        }];
    }
    return self;
}

- (void)updateData:(MyScoreModel *)scoreModel {
    self.curRankNameLab.text = scoreModel.rank_name;
    self.totalPointsLab.text = [NSString stringWithFormat:@"总积分:%ld", scoreModel.total_points];
    [self.rewardIV yy_setImageWithURL:[NSURL URLWithString:scoreModel.reward_img] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
    self.curRankLab.text = scoreModel.cur_rank;
    self.nextRankLab.text = scoreModel.next_rank;
    
    [self.curRankNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.cardIV).offset(20);
        make.top.equalTo(self.cardIV).offset(15);
    }];
    [self.totalPointsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.curRankNameLab);
        make.top.equalTo(self.curRankNameLab.mas_bottom).offset(16);
    }];
    [self.curRankLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.cardIV).offset(15);
        make.bottom.equalTo(self.cardIV).offset(-12);
    }];
    [self.nextRankLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.cardIV).offset(-17);
        make.bottom.equalTo(self.cardIV).offset(-41);
    }];
}

#pragma mark - lazy
- (UIImageView *)cardIV {
    if (!_cardIV) {
        _cardIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_card_jifen"]];
    }
    return _cardIV;
}

- (UILabel *)curRankNameLab {
    if (!_curRankNameLab) {
        _curRankNameLab = [UILabel labWithTextColor:DSWhite font:BoldFont(24)];
    }
    return _curRankNameLab;
}

- (UILabel *)totalPointsLab {
    if (!_totalPointsLab) {
        _totalPointsLab = [UILabel labWithTextColor:ColorFromHex(0x28525A) font:SysFont(14)];
    }
    return _totalPointsLab;
}

- (UIImageView *)rewardIV {
    if (!_rewardIV) {
        _rewardIV = [UIImageView new];
    }
    return _rewardIV;
}

- (UIButton *)rulesBtn {
    if (!_rulesBtn) {
        _rulesBtn = [UIButton btnWithTitle:@"积分规则" titleColor:DSWhite font:SysFont(12.0)];
        _rulesBtn.backgroundColor = ColorFromHex(0x89CAD3);
        [_rulesBtn addTouchUpInsideHandler:^(NSInteger tag) {
            
        }];
        [_rulesBtn cornerRadius:10.0];
    }
    return _rulesBtn;
}

- (UILabel *)curRankLab {
    if (!_curRankLab) {
        _curRankLab = [UILabel labWithTextColor:ColorFromHex(0x4599A8) font:BoldFont(12)];
    }
    return _curRankLab;
}

- (UILabel *)nextRankLab {
    if (!_nextRankLab) {
        _nextRankLab = [UILabel labWithTextColor:ColorFromHex(0x4599A8) font:BoldFont(12)];
        _nextRankLab.textAlignment = NSTextAlignmentRight;
    }
    return _nextRankLab;
}

@end