123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- //
- // ASGoodsCouponCell.m
- // Asteria
- //
- // Created by xingyu on 2024/5/20.
- //
- #import "ASGoodsCouponCell.h"
- @interface ASGoodsCouponCell()
- @property (nonatomic, strong) UIView *backView;
- @property (nonatomic, strong) UILabel *titleLab;
- @property (nonatomic, strong) UILabel *titleDescLab;
- @property (nonatomic, strong) UIButton *rTopBtn;
- @property (nonatomic, strong) UIView *couponView;
- @end
- @implementation ASGoodsCouponCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
-
- [self.contentView addSubview:self.backView];
-
- [self.backView addSubview:self.titleLab];
- [self.backView addSubview:self.titleDescLab];
- [self.backView addSubview:self.rTopBtn];
-
- [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.top.mas_equalTo(10);
- make.right.mas_equalTo(-10);
- make.bottom.mas_equalTo(0);
- }];
-
- [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.top.mas_equalTo(12);
- make.height.mas_equalTo(20);
- make.width.mas_equalTo(60);
- }];
-
- // [self.titleDescLab mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.left.mas_equalTo(self.titleLab.mas_right).offset(4);
- // make.centerY.mas_equalTo(self.titleLab);
- // make.right.mas_equalTo(-40);
- // }];
-
- [self.rTopBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.titleLab);
- make.right.mas_equalTo(0);
- make.width.mas_equalTo(40);
- make.height.mas_equalTo(30);
- }];
-
-
- [self.backView addSubview:self.couponView];
- [self.couponView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.mas_equalTo(0);
- make.height.mas_equalTo(1);
- make.top.mas_equalTo(self.titleLab.mas_bottom).offset(12);
- make.bottom.mas_equalTo(0);
- }];
- }
- return self;
- }
- - (void)setupSubviewS {
-
-
-
- }
- - (void)configData:(id)Data isSelect:(BOOL)isSelect{
-
- NSArray *couponArray = (NSArray *)Data;
-
- self.rTopBtn.selected = isSelect;
-
- if (self.rTopBtn.selected) {//展开
-
- float itemWidth = (KScreenWidth - 50)/2;
- float itemX = 10;
- float itemY = 10;
- for (int i = 0; i < couponArray.count; i++) {
-
- ASGoodsCouponModel *couponModel = [couponArray objectAtIndex:i];
-
- ASGoodsCouponItemView *itemView = [[ASGoodsCouponItemView alloc] initWithFrame:CGRectMake(itemX, itemY, itemWidth, 100)];
- itemView.tag = i;
- [self.couponView addSubview:itemView];
- itemView.couponModel = couponModel;
-
- itemView.userInteractionEnabled = YES;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_clickAction:)];
- [itemView addGestureRecognizer:tap];
-
- if (i % 2 == 1) {
- itemX = 10;
- itemY = itemY + 100 + 10;
- } else {
- itemX = itemX + itemWidth + 10;
- }
-
-
- }
-
- if (couponArray.count % 2 != 0) {
- itemY = itemY + 100 + 10;
- }
-
- [self.couponView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(itemY);
- }];
-
- } else {//收起
-
- [self.couponView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(1);
- }];
- }
- }
- - (void)_clickAction:(UIGestureRecognizer *)taper {
-
- }
- - (void)_couponEvent:(UIButton *)button {
- // button.selected = !button.selected;
- self.rTopBtn.selected = !self.rTopBtn.selected;
- // TT_ViewRadius(self.backView, 0);
- if (self.currencyparameterClose) {
- self.currencyparameterClose(self.rTopBtn.selected, nil);
- }
- }
- - (UIView *)backView {
- if (!_backView) {
- _backView = [[UIView alloc] init];
- TT_ViewRadius(_backView, 8);
- _backView.backgroundColor = _113632;
- }
- return _backView;
- }
- - (UILabel *)titleLab {
- if (!_titleLab) {
- _titleLab = [UILabel labelCreateWithText:@"COUPON" font:[UIFont fontWithName:Rob_Bold size:14] textColor:Col_FFF];
- _titleLab.adjustsFontSizeToFitWidth = YES;
- }
- return _titleLab;
- }
- - (UILabel *)titleDescLab {
- if (!_titleDescLab) {
- _titleDescLab = [UILabel labelCreateWithText:@"All wigs 10% off code:wkwig" font:[UIFont fontWithName:Rob_Regular size:12] textColor:Col_FFF];
- _titleDescLab.adjustsFontSizeToFitWidth = YES;
- }
- return _titleDescLab;
- }
- - (UIButton *)rTopBtn {
- if (!_rTopBtn) {
- _rTopBtn = [[UIButton alloc]init];
- // _rTopBtn.selected = NO;
- [_rTopBtn addTarget:self action:@selector(_couponEvent:) forControlEvents:UIControlEventTouchUpInside];
- [_rTopBtn setImage:[UIImage imageNamed:@"base_add_white"] forState:UIControlStateNormal];
- [_rTopBtn setImage:[UIImage imageNamed:@"base_subtract_white"] forState:UIControlStateSelected];
- }
- return _rTopBtn;
- }
- - (UIView *)couponView {
- if (!_couponView) {
- _couponView = [[UIView alloc] init];
- _couponView.backgroundColor = [UIColor clearColor];
- }
- return _couponView;
- }
- @end
- @interface ASGoodsCouponItemView()
- @property (nonatomic, strong) UIImageView *bgImaegView;
- @property (nonatomic, strong) UILabel *couponCodeLab;
- @property (nonatomic, strong) UILabel *couponTitleLab;
- @property (nonatomic, strong) UILabel *couponDescLab;
- @property (nonatomic, strong) UIButton *copyBtn;
- @end
- @implementation ASGoodsCouponItemView
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
-
-
- [self addSubview:self.bgImaegView];
-
- [self.bgImaegView addSubview:self.couponCodeLab];
- [self.bgImaegView addSubview:self.couponDescLab];
- [self.bgImaegView addSubview:self.couponTitleLab];
- [self.bgImaegView addSubview:self.copyBtn];
-
-
- [self.bgImaegView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- [self.couponCodeLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(-16);
- make.centerX.equalTo(self.bgImaegView.mas_centerX).offset(-25);
- make.width.mas_equalTo((KScreenWidth - 50)/2 - 80);
- }];
-
- [self.couponDescLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.bgImaegView.mas_centerX).offset(-25);
- make.width.mas_equalTo((KScreenWidth - 50)/2 - 80);
- make.centerY.equalTo(self.bgImaegView.mas_centerY).offset(4);
- }];
-
- [self.couponTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.bgImaegView.mas_centerX).offset(-25);
- make.width.mas_equalTo((KScreenWidth - 50)/2 - 80);
- make.top.mas_equalTo(16);
- }];
-
- [self.copyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.top.right.mas_equalTo(0);
- make.width.mas_equalTo(45);
- }];
-
- }
- return self;
- }
- - (void)setCouponModel:(ASGoodsCouponModel *)couponModel {
- _couponModel = couponModel;
-
- self.couponCodeLab.text = [NSString stringWithFormat:@"Code:%@", AS_String_NotNull(couponModel.code)];
-
- if (AS_String_NotNull(couponModel.gt).length > 1) {
- self.couponDescLab.text = AS_String_NotNull(couponModel.gt);
- } else {
- self.couponDescLab.text = @"";
- }
-
- self.couponTitleLab.text = AS_String_NotNull(couponModel.detail);
- }
- - (void)_copyClick {
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.string = _couponModel.code;
-
- UIViewController *topVC = topViewController();
- [topVC.view makeToast:@"Copy success" duration:2 position:CSToastPositionCenter];
- }
- - (UIImageView *)bgImaegView {
- if (!_bgImaegView) {
- _bgImaegView = [[UIImageView alloc] init];
- _bgImaegView.image = [UIImage imageNamed:@"goods_coupon_bg"];
- _bgImaegView.userInteractionEnabled = YES;
- }
- return _bgImaegView;
- }
- - (UILabel *)couponCodeLab {
- if (!_couponCodeLab) {
- _couponCodeLab = [UILabel labelCreateWithText:@"code:1238" font:[UIFont fontWithName:Rob_Regular size:12] textColor:_0B0B0B];
- _couponCodeLab.adjustsFontSizeToFitWidth = YES;
- _couponCodeLab.textAlignment = NSTextAlignmentCenter;
- }
- return _couponCodeLab;
- }
- - (UILabel *)couponDescLab {
- if (!_couponDescLab) {
- _couponDescLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_Regular size:12] textColor:_043632];
- _couponDescLab.adjustsFontSizeToFitWidth = YES;
- _couponDescLab.textAlignment = NSTextAlignmentCenter;
- }
- return _couponDescLab;
- }
- - (UILabel *)couponTitleLab {
- if (!_couponTitleLab) {
- _couponTitleLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_BoldItalic size:18] textColor:_043632];
- _couponTitleLab.adjustsFontSizeToFitWidth = YES;
- _couponTitleLab.textAlignment = NSTextAlignmentCenter;
- }
- return _couponTitleLab;
- }
- - (UIButton *)copyBtn {
- if (!_copyBtn) {
- _copyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _copyBtn.backgroundColor = [UIColor clearColor];
- [_copyBtn addTarget:self action:@selector(_copyClick) forControlEvents:UIControlEventTouchUpInside];
- }
- return _copyBtn;
- }
- @end
- @implementation ASGoodsCouponModel
- @end
|