ASGoodsCouponCell.m 6.9 KB

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