SignCollectionViewCell.m 4.3 KB
//
//  SignCollectionViewCell.m
//  DreamSleep
//
//  Created by peter on 2022/6/29.
//

#import "SignCollectionViewCell.h"

@interface SignCollectionViewCell ()
@property (nonatomic, strong) UIView *dayView;
@property (nonatomic, strong) UILabel *scoreLab;
@property (nonatomic, strong) UIImageView *doneIV;
@property (nonatomic, strong) UIImageView *giftIV;
@property (nonatomic, strong) UILabel *dayLab;
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIView *bigDot;
@property (nonatomic, strong) UIView *smallDot;
@end

@implementation SignCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self debugViewShowBorderWithColor:[UIColor greenColor]];
        
        [self.contentView addSubview:self.dayView];
        [self.contentView addSubview:self.giftIV];
        [self.contentView addSubview:self.scoreLab];
        [self.contentView addSubview:self.doneIV];
        
        [self.dayView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self.contentView);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        [self.giftIV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self.dayView);
        }];
        [self.doneIV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.dayView);
            make.bottom.equalTo(self.dayView).offset(-6);
        }];
    }
    return self;
}

- (void)refreshSignView:(ScoreTaskRequestModel *)requestModel indexPath:(NSIndexPath *)indexPath {
    SignModel *signModel = requestModel.signList[indexPath.row];
    BOOL is_cur_day = requestModel.cur_day == signModel.day;
    
    // 背景小圆背景颜色显示
    DKColorPicker day_dk_bg_color = is_cur_day ? DKColorPickerWithColors(ColorFromHex(0xFC7032), ColorFromHex(0xB5552E), DSWhite) : DKColorPickerWithColors(ColorFromHexA(0xFC7032, .1), ColorFromHexA(0xFC7032, .1), DSWhite);
    self.dayView.dk_backgroundColorPicker = day_dk_bg_color;
    
    // 礼物图标显示
    if (signModel.state == 0) { // 未签到
        if (signModel.day == 3) { // 小礼物
            self.giftIV.hidden = NO;
            self.giftIV.dk_imagePicker = DKImagePickerWithNames(@"ic_rw_jiangli1", @"dk_ic_rw_jiangli1", @"dk_ic_rw_jiangli1");
        } else if (signModel.day == 7) { // 大礼物
            self.giftIV.hidden = NO;
            self.giftIV.dk_imagePicker = DKImagePickerWithNames(@"ic_rw_jiangli2", @"dk_ic_rw_jiangli2", @"dk_ic_rw_jiangli2");
        } else {
            self.giftIV.hidden = YES;
        }
    } else { // 已签到不显示礼物图标
        self.giftIV.hidden = YES;
    }
    
    // 积分显示
    if (signModel.state == 0 && (signModel.day == 3 || signModel.day == 7)) {
        self.scoreLab.hidden = YES;
    } else {
        self.scoreLab.hidden = NO;
    }
    self.scoreLab.text = [NSString stringWithFormat:@"+%d", signModel.point];
    self.scoreLab.font = signModel.state == 1 ? SysFont(12.0) : SysFont(14.0);
    [self.scoreLab sizeToFit];
    [self.scoreLab mas_makeConstraints:^(MASConstraintMaker *make) {
        if (signModel.state == 1) {
            make.centerX.equalTo(self.dayView);
            make.top.equalTo(self.dayView).offset(6);
        } else {
            make.center.equalTo(self.dayView);
        }
    }];
    DKColorPicker score_dk_text_color = is_cur_day ? DKColorPickerWithColors(DSWhite, DkTitleColor, DSWhite) : DKColorPickerWithColors(ColorFromHex(0xFC7032), ColorFromHex(0xFC7032), DSWhite);
    self.scoreLab.dk_textColorPicker = score_dk_text_color;
    
    // 完成图标显示
    self.doneIV.hidden = signModel.state == 0;
}

#pragma mark - lazy
- (UIView *)dayView {
    if (!_dayView) {
        _dayView = [UIView new];
        [_dayView cornerRadius:20.0];
    }
    return _dayView;
}

- (UIImageView *)giftIV {
    if (!_giftIV) {
        _giftIV = [UIImageView new];
    }
    return _giftIV;
}

- (UILabel *)scoreLab {
    if (!_scoreLab) {
        _scoreLab = [UILabel new];
        _scoreLab.textAlignment = NSTextAlignmentCenter;
        _scoreLab.backgroundColor = DSClearColor;
    }
    return _scoreLab;
}

- (UIImageView *)doneIV {
    if (!_doneIV) {
        _doneIV = [[UIImageView alloc] dk_initWithImagePicker:DKImagePickerWithNames(@"ic_rw_yiqiandao", @"dk_ic_rw_yiqiandao", @"ic_rw_yiqiandao")];
    }
    return _doneIV;
}

@end