// // ASHomeFlashDealCell.m // Asteria // // Created by iOS on 2023/6/10. // #import "ASHomeFlashDealCell.h" #import "KWTimeEndView.h" #import "HomeFlashDealSubCollectCell.h" @interface ASHomeFlashDealCell () @property (nonatomic, strong) UIView *timBgV; @property (nonatomic, strong) KWTimeEndView *timerV; @end @implementation ASHomeFlashDealCell - (void)setModel:(ASHomeMainListModel *)model { [super setModel:model]; self.titleLb.text = model.title; NSTimeInterval elseTime = model.endtime - [[NSDate date] timeIntervalSince1970]; if (elseTime <= 0) { [self.timerV setHidden:true]; } else { [self.timerV setHidden:false]; [self.timerV setTime:elseTime]; [self.timerV startTimer]; } self.timBgV.hidden = self.timerV.isHidden; CGFloat lineH = (KScreenWidth-30)/2 + productHWithOutImg; NSInteger line = model.productList.count/2; line = line + (model.productList.count%2); CGFloat collH = (lineH + 10)*line + 10; [self.collectV mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(0); make.right.equalTo(self.contentView).offset(-0); make.height.equalTo([NSNumber numberWithFloat:collH]); if (self.timBgV.isHidden) { make.top.equalTo(self.titleLb.mas_bottom).offset(20); } else { make.top.equalTo(self.timBgV.mas_bottom).offset(20); } }]; } - (void)dealloc { [self.timerV stopTimer]; } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self loadSubVs]; } return self; } - (void)loadSubVs { [self.contentView addSubview:self.timBgV]; [self.timBgV addSubview:self.timerV]; [self.timBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.titleLb.mas_bottom); make.leading.trailing.equalTo(self.contentView); make.height.equalTo(@44); }]; [self.timerV mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.equalTo(self.timBgV); make.bottom.equalTo(self.timBgV); make.height.equalTo(@24); }]; CGFloat collH = (KScreenWidth-30)/2 + productHWithOutImg; [self.collectV mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(0); make.right.equalTo(self.contentView).offset(-0); make.height.equalTo([NSNumber numberWithFloat:collH]); make.top.equalTo(self.timBgV.mas_bottom).offset(20); }]; } - (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath { HomeFlashDealSubCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeFlashDealSubCollectCell" forIndexPath:indexPath]; if (self.model.productList.count <= indexPath.row) { return cell; } ASProductBaseModel *m = self.model.productList[indexPath.row]; cell.model = m; cell.contView.addCartBt.hidden = false; __weak typeof(self) wSelf = self; cell.contView.addCartBlock = ^(ASProductBaseModel * _Nonnull m) { if (wSelf.proAddCartClick) { wSelf.proAddCartClick(indexPath.row, m); } }; return cell; } - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (KWTimeEndView *)timerV { if (!_timerV) { KWTimeEndView *v = [[KWTimeEndView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 24)]; _timerV = v; } return _timerV; } - (UIView *)timBgV { if (!_timBgV) { UIView *v = [UIView baseV]; v.backgroundColor = UIColor.clearColor; _timBgV = v; } return _timBgV; } @end