SignTaskView.m 4.4 KB
//
//  SignTaskView.m
//  DreamSleep
//
//  Created by peter on 2022/6/7.
//

#import "SignTaskView.h"
#import "SignCollectionViewCell.h"

@interface SignTaskView () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UICollectionView *signMainView;
@property (nonatomic, strong) UIButton *signBtn;
/// 签到列表
@property (nonatomic, strong) NSArray *signList;
@property (nonatomic, strong) ScoreTaskRequestModel *requestModel;
@end

@implementation SignTaskView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
        [self cornerRadius:24.0];
        
        [self addSubview:self.titleLab];
        [self addSubview:self.signMainView];
        [self addSubview:self.signBtn];
        
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self).offset(15);
        }];
        [self.signMainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(15);
            make.right.equalTo(self).offset(-15);
            make.top.equalTo(self.titleLab.mas_bottom).offset(10);
            make.bottom.equalTo(self.signBtn.mas_top).offset(-14);
        }];
        [self.signBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(155, 40));
            make.centerX.equalTo(self);
            make.bottom.equalTo(self).offset(-15);
        }];
    }
    return self;
}

- (void)signAction {
    
}

- (void)updateSignView:(ScoreTaskRequestModel *)requestModel {
    if (requestModel && requestModel.signList && requestModel.signList.count) {
        self.requestModel = requestModel;
        self.signList = requestModel.signList;
        [self.signMainView reloadData];
    }
}

#pragma mark - UICollectionViewDelegate && UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.signList.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    SignCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([SignCollectionViewCell class]) forIndexPath:indexPath];
    [cell refreshSignView:self.requestModel indexPath:indexPath];
    return cell;
}

#pragma mark - lazy
- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel labWithText:@"签到领积分,连续签到有额外奖励" font:SysFont(12.0) fit:YES];
        _titleLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3));
    }
    return _titleLab;
}

- (UICollectionView *)signMainView {
    if (!_signMainView) {
        CGFloat space = (kScreenWidth - 60 - 280) / 6.0;
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        layout.minimumLineSpacing = 0;
        layout.itemSize = CGSizeMake(40 + space, 77);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _signMainView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _signMainView.backgroundColor = DSClearColor;
        _signMainView.scrollEnabled = NO;
        [_signMainView registerClass:[SignCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([SignCollectionViewCell class])];
        _signMainView.showsHorizontalScrollIndicator = NO;
        _signMainView.delegate = self;
        _signMainView.dataSource = self;
    }
    return _signMainView;
}

- (UIButton *)signBtn {
    if (!_signBtn) {
        _signBtn = [UIButton btnWithTitle:@"签到领积分" font:BoldFont(16)];
        [_signBtn dk_setTitleColorPicker:DKColorPickerWithColors(DSWhite, DkTitleColor, DSWhite) forState:UIControlStateNormal];
        [_signBtn dk_setBackgroundColorPicker:DKColorPickerWithColors(ColorFromHex(0xFEA961), ColorFromHex(0xB77C4E), DSWhite)];
        [_signBtn addTarget:self action:@selector(signAction) forControlEvents:UIControlEventTouchUpInside];
        [_signBtn cornerRadius:20];
    }
    return _signBtn;
}

- (NSArray *)signList {
    if (!_signList) {
        _signList = [NSArray array];
    }
    return _signList;
}

@end