ASHomeFlashDealCell.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // ASHomeFlashDealCell.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/10.
  6. //
  7. #import "ASHomeFlashDealCell.h"
  8. #import "KWTimeEndView.h"
  9. #import "HomeFlashDealSubCollectCell.h"
  10. @interface ASHomeFlashDealCell ()
  11. @property (nonatomic, strong) UIView *timBgV;
  12. @property (nonatomic, strong) KWTimeEndView *timerV;
  13. @end
  14. @implementation ASHomeFlashDealCell
  15. - (void)setModel:(ASHomeMainListModel *)model {
  16. [super setModel:model];
  17. self.titleLb.text = model.title;
  18. NSTimeInterval elseTime = model.endtime - [[NSDate date] timeIntervalSince1970];
  19. if (elseTime <= 0) {
  20. [self.timerV setHidden:true];
  21. } else {
  22. [self.timerV setHidden:false];
  23. [self.timerV setTime:elseTime];
  24. [self.timerV startTimer];
  25. }
  26. self.timBgV.hidden = self.timerV.isHidden;
  27. CGFloat lineH = (KScreenWidth-30)/2 + productHWithOutImg;
  28. NSInteger line = model.productList.count/2;
  29. line = line + (model.productList.count%2);
  30. CGFloat collH = (lineH + 10)*line + 10;
  31. [self.collectV mas_remakeConstraints:^(MASConstraintMaker *make) {
  32. make.left.equalTo(self.contentView).offset(0);
  33. make.right.equalTo(self.contentView).offset(-0);
  34. make.height.equalTo([NSNumber numberWithFloat:collH]);
  35. if (self.timBgV.isHidden) {
  36. make.top.equalTo(self.titleLb.mas_bottom).offset(20);
  37. } else {
  38. make.top.equalTo(self.timBgV.mas_bottom).offset(20);
  39. }
  40. }];
  41. }
  42. - (void)dealloc {
  43. [self.timerV stopTimer];
  44. }
  45. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  46. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  47. if (self) {
  48. [self loadSubVs];
  49. }
  50. return self;
  51. }
  52. - (void)loadSubVs {
  53. [self.contentView addSubview:self.timBgV];
  54. [self.timBgV addSubview:self.timerV];
  55. [self.timBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.top.equalTo(self.titleLb.mas_bottom);
  57. make.leading.trailing.equalTo(self.contentView);
  58. make.height.equalTo(@44);
  59. }];
  60. [self.timerV mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.leading.trailing.equalTo(self.timBgV);
  62. make.bottom.equalTo(self.timBgV);
  63. make.height.equalTo(@24);
  64. }];
  65. CGFloat collH = (KScreenWidth-30)/2 + productHWithOutImg;
  66. [self.collectV mas_remakeConstraints:^(MASConstraintMaker *make) {
  67. make.left.equalTo(self.contentView).offset(0);
  68. make.right.equalTo(self.contentView).offset(-0);
  69. make.height.equalTo([NSNumber numberWithFloat:collH]);
  70. make.top.equalTo(self.timBgV.mas_bottom).offset(20);
  71. }];
  72. }
  73. - (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
  74. HomeFlashDealSubCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeFlashDealSubCollectCell" forIndexPath:indexPath];
  75. if (self.model.productList.count <= indexPath.row)
  76. {
  77. return cell;
  78. }
  79. ASProductBaseModel *m = self.model.productList[indexPath.row];
  80. cell.model = m;
  81. cell.contView.addCartBt.hidden = false;
  82. __weak typeof(self) wSelf = self;
  83. cell.contView.addCartBlock = ^(ASProductBaseModel * _Nonnull m) {
  84. if (wSelf.proAddCartClick) {
  85. wSelf.proAddCartClick(indexPath.row, m);
  86. }
  87. };
  88. return cell;
  89. }
  90. - (void)awakeFromNib {
  91. [super awakeFromNib];
  92. // Initialization code
  93. }
  94. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  95. [super setSelected:selected animated:animated];
  96. // Configure the view for the selected state
  97. }
  98. - (KWTimeEndView *)timerV {
  99. if (!_timerV) {
  100. KWTimeEndView *v = [[KWTimeEndView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 24)];
  101. _timerV = v;
  102. }
  103. return _timerV;
  104. }
  105. - (UIView *)timBgV {
  106. if (!_timBgV) {
  107. UIView *v = [UIView baseV];
  108. v.backgroundColor = UIColor.clearColor;
  109. _timBgV = v;
  110. }
  111. return _timBgV;
  112. }
  113. @end