ASGoodsCouponCell.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. [_couponView addSubview:itemView];
  83. if (i % 2 == 1) {
  84. itemX = 10;
  85. itemY = itemY + 100 + 10;
  86. } else {
  87. itemX = itemX + itemWidth + 10;
  88. }
  89. }
  90. if (array.count % 2 != 0) {
  91. itemY = itemY + 100 + 10;
  92. }
  93. [_couponView mas_updateConstraints:^(MASConstraintMaker *make) {
  94. make.height.mas_equalTo(itemY);
  95. }];
  96. } else {//收起
  97. [self.couponView mas_updateConstraints:^(MASConstraintMaker *make) {
  98. make.height.mas_equalTo(1);
  99. }];
  100. }
  101. }
  102. - (void)_couponEvent:(UIButton *)button {
  103. // button.selected = !button.selected;
  104. self.rTopBtn.selected = !self.rTopBtn.selected;
  105. // TT_ViewRadius(self.backView, 0);
  106. if (self.currencyparameterClose) {
  107. self.currencyparameterClose(self.rTopBtn.selected, nil);
  108. }
  109. }
  110. @end
  111. @interface ASGoodsCouponItemView()
  112. @end
  113. @implementation ASGoodsCouponItemView
  114. - (instancetype)initWithFrame:(CGRect)frame {
  115. if (self = [super initWithFrame:frame]) {
  116. UIImageView *bgImaegView = [[UIImageView alloc] init];
  117. bgImaegView.image = [UIImage imageNamed:@"goods_coupon_bg"];
  118. [self addSubview:bgImaegView];
  119. [bgImaegView mas_makeConstraints:^(MASConstraintMaker *make) {
  120. make.edges.mas_equalTo(0);
  121. }];
  122. }
  123. return self;
  124. }
  125. @end