ASGoodsCouponCell.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // ASGoodsCouponCell.m
  3. // Asteria
  4. //
  5. // Created by xingyu on 2024/5/20.
  6. //
  7. #import "ASGoodsCouponCell.h"
  8. @interface ASGoodsCouponCell()
  9. @property (nonatomic, strong) UIView *backView;
  10. @property (nonatomic, strong) UILabel *titleLab;
  11. @property (nonatomic, strong) UILabel *titleDescLab;
  12. @property (nonatomic, strong) UIButton *rTopBtn;
  13. @property (nonatomic, strong) UIView *couponView;
  14. @end
  15. @implementation ASGoodsCouponCell
  16. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  17. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  18. _backView = [[UIView alloc] init];
  19. TT_ViewRadius(_backView, 8);
  20. _backView.backgroundColor = _113632;
  21. [self.contentView addSubview:_backView];
  22. [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
  23. make.left.mas_equalTo(10);
  24. make.top.mas_equalTo(10);
  25. make.right.mas_equalTo(-10);
  26. // make.height.mas_equalTo(45);
  27. make.bottom.mas_equalTo(0);
  28. }];
  29. _titleLab = [UILabel labelCreateWithText:@"COUPON" font:[UIFont fontWithName:Rob_Bold size:14] textColor:Col_FFF];
  30. _titleDescLab.adjustsFontSizeToFitWidth = YES;
  31. [_backView addSubview:_titleLab];
  32. [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.left.mas_equalTo(10);
  34. make.top.mas_equalTo(12);
  35. make.height.mas_equalTo(20);
  36. make.width.mas_equalTo(60);
  37. }];
  38. _titleDescLab = [UILabel labelCreateWithText:@"All wigs 10% off code:wkwig" font:[UIFont fontWithName:Rob_Regular size:12] textColor:Col_FFF];
  39. _titleDescLab.adjustsFontSizeToFitWidth = YES;
  40. [_backView addSubview:_titleDescLab];
  41. [_titleDescLab mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.mas_equalTo(_titleLab.mas_right).offset(4);
  43. make.centerY.mas_equalTo(_titleLab);
  44. make.right.mas_equalTo(-40);
  45. }];
  46. _rTopBtn = [[UIButton alloc]init];
  47. // _rTopBtn.selected = NO;
  48. [_rTopBtn addTarget:self action:@selector(_couponEvent:) forControlEvents:UIControlEventTouchUpInside];
  49. [_rTopBtn setImage:[UIImage imageNamed:@"base_add_white"] forState:UIControlStateNormal];
  50. [_rTopBtn setImage:[UIImage imageNamed:@"base_subtract_white"] forState:UIControlStateSelected];
  51. [_backView addSubview:_rTopBtn];
  52. [_rTopBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.centerY.equalTo(_titleLab);
  54. make.right.mas_equalTo(0);
  55. make.width.mas_equalTo(40);
  56. make.height.mas_equalTo(30);
  57. }];
  58. _couponView = [[UIView alloc] init];
  59. _couponView.backgroundColor = [UIColor clearColor];
  60. [_backView addSubview:_couponView];
  61. [_couponView mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.left.right.bottom.mas_equalTo(0);
  63. make.height.mas_equalTo(1);
  64. make.top.mas_equalTo(_titleLab.mas_bottom).offset(12);
  65. make.bottom.mas_equalTo(0);
  66. }];
  67. }
  68. return self;
  69. }
  70. - (void)setupSubviewS {
  71. }
  72. - (void)configData:(id)Data isSelect:(BOOL)isSelect{
  73. GoodsInformationM *model = (GoodsInformationM *)Data;
  74. self.rTopBtn.selected = isSelect;
  75. if (self.rTopBtn.selected) {//展开
  76. NSArray *array = @[@"1", @"2", @"3", @"4", @"5", @"6"];
  77. float itemWidth = (KScreenWidth - 50)/2;
  78. float itemX = 10;
  79. float itemY = 10;
  80. for (int i = 0; i < array.count; i++) {
  81. ASGoodsCouponItemView *itemView = [[ASGoodsCouponItemView alloc] initWithFrame:CGRectMake(itemX, itemY, itemWidth, 100)];
  82. itemView.tag = i;
  83. [_couponView addSubview:itemView];
  84. itemView.userInteractionEnabled = YES;
  85. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_clickAction:)];
  86. [itemView addGestureRecognizer:tap];
  87. if (i % 2 == 1) {
  88. itemX = 10;
  89. itemY = itemY + 100 + 10;
  90. } else {
  91. itemX = itemX + itemWidth + 10;
  92. }
  93. }
  94. if (array.count % 2 != 0) {
  95. itemY = itemY + 100 + 10;
  96. }
  97. [_couponView mas_updateConstraints:^(MASConstraintMaker *make) {
  98. make.height.mas_equalTo(itemY);
  99. }];
  100. } else {//收起
  101. [self.couponView mas_updateConstraints:^(MASConstraintMaker *make) {
  102. make.height.mas_equalTo(1);
  103. }];
  104. }
  105. }
  106. - (void)_clickAction:(UIGestureRecognizer *)taper {
  107. }
  108. - (void)_couponEvent:(UIButton *)button {
  109. // button.selected = !button.selected;
  110. self.rTopBtn.selected = !self.rTopBtn.selected;
  111. // TT_ViewRadius(self.backView, 0);
  112. if (self.currencyparameterClose) {
  113. self.currencyparameterClose(self.rTopBtn.selected, nil);
  114. }
  115. }
  116. @end
  117. @interface ASGoodsCouponItemView()
  118. @property (nonatomic, strong) UILabel *couponCodeLab;
  119. @property (nonatomic, strong) UILabel *couponPriceLab;
  120. @property (nonatomic, strong) UILabel *couponDescLab;
  121. @end
  122. @implementation ASGoodsCouponItemView
  123. - (instancetype)initWithFrame:(CGRect)frame {
  124. if (self = [super initWithFrame:frame]) {
  125. UIImageView *bgImaegView = [[UIImageView alloc] init];
  126. bgImaegView.image = [UIImage imageNamed:@"goods_coupon_bg"];
  127. [self addSubview:bgImaegView];
  128. [bgImaegView mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.edges.mas_equalTo(0);
  130. }];
  131. _couponCodeLab = [UILabel labelCreateWithText:@"code:1238" font:[UIFont fontWithName:Rob_Regular size:12] textColor:_0B0B0B];
  132. _couponCodeLab.textAlignment = NSTextAlignmentCenter;
  133. [bgImaegView addSubview:_couponCodeLab];
  134. [_couponCodeLab mas_makeConstraints:^(MASConstraintMaker *make) {
  135. make.bottom.mas_equalTo(-16);
  136. make.centerX.equalTo(bgImaegView.mas_centerX).offset(-25);
  137. make.width.mas_equalTo((KScreenWidth - 50)/2 - 80);
  138. }];
  139. }
  140. return self;
  141. }
  142. @end