ASGoodsCouponCell.m 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. NSArray *couponArray = (NSArray *)Data;
  59. self.rTopBtn.selected = isSelect;
  60. if (self.rTopBtn.selected) {//展开
  61. float itemWidth = (KScreenWidth - 50)/2;
  62. float itemX = 10;
  63. float itemY = 10;
  64. for (int i = 0; i < couponArray.count; i++) {
  65. ASGoodsCouponModel *couponModel = [couponArray objectAtIndex:i];
  66. ASGoodsCouponItemView *itemView = [[ASGoodsCouponItemView alloc] initWithFrame:CGRectMake(itemX, itemY, itemWidth, 100)];
  67. itemView.tag = i;
  68. [self.couponView addSubview:itemView];
  69. itemView.couponModel = couponModel;
  70. itemView.userInteractionEnabled = YES;
  71. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_clickAction:)];
  72. [itemView addGestureRecognizer:tap];
  73. if (i % 2 == 1) {
  74. itemX = 10;
  75. itemY = itemY + 100 + 10;
  76. } else {
  77. itemX = itemX + itemWidth + 10;
  78. }
  79. }
  80. if (couponArray.count % 2 != 0) {
  81. itemY = itemY + 100 + 10;
  82. }
  83. [self.couponView mas_updateConstraints:^(MASConstraintMaker *make) {
  84. make.height.mas_equalTo(itemY);
  85. }];
  86. } else {//收起
  87. [self.couponView mas_updateConstraints:^(MASConstraintMaker *make) {
  88. make.height.mas_equalTo(1);
  89. }];
  90. }
  91. }
  92. - (void)_clickAction:(UIGestureRecognizer *)taper {
  93. }
  94. - (void)_couponEvent:(UIButton *)button {
  95. // button.selected = !button.selected;
  96. self.rTopBtn.selected = !self.rTopBtn.selected;
  97. // TT_ViewRadius(self.backView, 0);
  98. if (self.currencyparameterClose) {
  99. self.currencyparameterClose(self.rTopBtn.selected, nil);
  100. }
  101. }
  102. - (UIView *)backView {
  103. if (!_backView) {
  104. _backView = [[UIView alloc] init];
  105. TT_ViewRadius(_backView, 8);
  106. _backView.backgroundColor = _113632;
  107. }
  108. return _backView;
  109. }
  110. - (UILabel *)titleLab {
  111. if (!_titleLab) {
  112. _titleLab = [UILabel labelCreateWithText:@"COUPON" font:[UIFont fontWithName:Rob_Bold size:14] textColor:Col_FFF];
  113. _titleLab.adjustsFontSizeToFitWidth = YES;
  114. }
  115. return _titleLab;
  116. }
  117. - (UILabel *)titleDescLab {
  118. if (!_titleDescLab) {
  119. _titleDescLab = [UILabel labelCreateWithText:@"All wigs 10% off code:wkwig" font:[UIFont fontWithName:Rob_Regular size:12] textColor:Col_FFF];
  120. _titleDescLab.adjustsFontSizeToFitWidth = YES;
  121. }
  122. return _titleDescLab;
  123. }
  124. - (UIButton *)rTopBtn {
  125. if (!_rTopBtn) {
  126. _rTopBtn = [[UIButton alloc]init];
  127. // _rTopBtn.selected = NO;
  128. [_rTopBtn addTarget:self action:@selector(_couponEvent:) forControlEvents:UIControlEventTouchUpInside];
  129. [_rTopBtn setImage:[UIImage imageNamed:@"base_add_white"] forState:UIControlStateNormal];
  130. [_rTopBtn setImage:[UIImage imageNamed:@"base_subtract_white"] forState:UIControlStateSelected];
  131. }
  132. return _rTopBtn;
  133. }
  134. - (UIView *)couponView {
  135. if (!_couponView) {
  136. _couponView = [[UIView alloc] init];
  137. _couponView.backgroundColor = [UIColor clearColor];
  138. }
  139. return _couponView;
  140. }
  141. @end
  142. @interface ASGoodsCouponItemView()
  143. @property (nonatomic, strong) UIImageView *bgImaegView;
  144. @property (nonatomic, strong) UILabel *couponCodeLab;
  145. @property (nonatomic, strong) UILabel *couponTitleLab;
  146. @property (nonatomic, strong) UILabel *couponDescLab;
  147. @property (nonatomic, strong) UIButton *copyBtn;
  148. @end
  149. @implementation ASGoodsCouponItemView
  150. - (instancetype)initWithFrame:(CGRect)frame {
  151. if (self = [super initWithFrame:frame]) {
  152. [self addSubview:self.bgImaegView];
  153. [self.bgImaegView addSubview:self.couponCodeLab];
  154. [self.bgImaegView addSubview:self.couponDescLab];
  155. [self.bgImaegView addSubview:self.couponTitleLab];
  156. [self.bgImaegView addSubview:self.copyBtn];
  157. [self.bgImaegView mas_makeConstraints:^(MASConstraintMaker *make) {
  158. make.edges.mas_equalTo(0);
  159. }];
  160. [self.couponCodeLab mas_makeConstraints:^(MASConstraintMaker *make) {
  161. make.bottom.mas_equalTo(-16);
  162. make.centerX.equalTo(self.bgImaegView.mas_centerX).offset(-25);
  163. make.width.mas_equalTo((KScreenWidth - 50)/2 - 80);
  164. }];
  165. [self.couponDescLab mas_makeConstraints:^(MASConstraintMaker *make) {
  166. make.centerX.equalTo(self.bgImaegView.mas_centerX).offset(-25);
  167. make.width.mas_equalTo((KScreenWidth - 50)/2 - 80);
  168. make.centerY.equalTo(self.bgImaegView.mas_centerY).offset(4);
  169. }];
  170. [self.couponTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  171. make.centerX.equalTo(self.bgImaegView.mas_centerX).offset(-25);
  172. make.width.mas_equalTo((KScreenWidth - 50)/2 - 80);
  173. make.top.mas_equalTo(16);
  174. }];
  175. [self.copyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  176. make.bottom.top.right.mas_equalTo(0);
  177. make.width.mas_equalTo(45);
  178. }];
  179. }
  180. return self;
  181. }
  182. - (void)setCouponModel:(ASGoodsCouponModel *)couponModel {
  183. _couponModel = couponModel;
  184. self.couponCodeLab.text = [NSString stringWithFormat:@"Code:%@", AS_String_NotNull(couponModel.code)];
  185. if (AS_String_NotNull(couponModel.gt).length > 1) {
  186. self.couponDescLab.text = AS_String_NotNull(couponModel.gt);
  187. } else {
  188. self.couponDescLab.text = @"";
  189. }
  190. self.couponTitleLab.text = AS_String_NotNull(couponModel.detail);
  191. }
  192. - (void)_copyClick {
  193. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  194. pasteboard.string = _couponModel.code;
  195. UIViewController *topVC = topViewController();
  196. [topVC.view makeToast:@"Copy success" duration:2 position:CSToastPositionCenter];
  197. }
  198. - (UIImageView *)bgImaegView {
  199. if (!_bgImaegView) {
  200. _bgImaegView = [[UIImageView alloc] init];
  201. _bgImaegView.image = [UIImage imageNamed:@"goods_coupon_bg"];
  202. _bgImaegView.userInteractionEnabled = YES;
  203. }
  204. return _bgImaegView;
  205. }
  206. - (UILabel *)couponCodeLab {
  207. if (!_couponCodeLab) {
  208. _couponCodeLab = [UILabel labelCreateWithText:@"code:1238" font:[UIFont fontWithName:Rob_Regular size:12] textColor:_0B0B0B];
  209. _couponCodeLab.adjustsFontSizeToFitWidth = YES;
  210. _couponCodeLab.textAlignment = NSTextAlignmentCenter;
  211. }
  212. return _couponCodeLab;
  213. }
  214. - (UILabel *)couponDescLab {
  215. if (!_couponDescLab) {
  216. _couponDescLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_Regular size:12] textColor:_043632];
  217. _couponDescLab.adjustsFontSizeToFitWidth = YES;
  218. _couponDescLab.textAlignment = NSTextAlignmentCenter;
  219. }
  220. return _couponDescLab;
  221. }
  222. - (UILabel *)couponTitleLab {
  223. if (!_couponTitleLab) {
  224. _couponTitleLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_BoldItalic size:18] textColor:_043632];
  225. _couponTitleLab.adjustsFontSizeToFitWidth = YES;
  226. _couponTitleLab.textAlignment = NSTextAlignmentCenter;
  227. }
  228. return _couponTitleLab;
  229. }
  230. - (UIButton *)copyBtn {
  231. if (!_copyBtn) {
  232. _copyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  233. _copyBtn.backgroundColor = [UIColor clearColor];
  234. [_copyBtn addTarget:self action:@selector(_copyClick) forControlEvents:UIControlEventTouchUpInside];
  235. }
  236. return _copyBtn;
  237. }
  238. @end
  239. @implementation ASGoodsCouponModel
  240. @end