// // ASCheckoutShipMethodCell.m // Asteria // // Created by xingyu on 2024/5/9. // #import "ASCheckoutShipMethodCell.h" @implementation ASCheckoutShipMethodData @end @interface ASCheckoutShipMethodCell() @property (nonatomic, strong) UIView *shipMethodView; @property (nonatomic, strong) UILabel *shipMethodLab; @property (nonatomic, strong) UILabel *shipPriceLab; @end @implementation ASCheckoutShipMethodCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (void)setupSubviewS { self.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"]; _shipMethodView = [[UIView alloc] init]; TT_ViewRadius(_shipMethodView, 4); _shipMethodView.backgroundColor = [UIColor whiteColor]; [self.contentView addSubview:_shipMethodView]; [_shipMethodView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.top.mas_equalTo(10); make.right.mas_equalTo(-10); make.height.mas_equalTo(50); make.bottom.mas_equalTo(0); }]; } - (void)configData:(id)Data{ ASCheckoutShipMethodData *model = (ASCheckoutShipMethodData *)Data; self.cellData = model; float floatY = 0; for (int i = 0; i < model.shipMethodArray.count; i++) { ASCheckoutShipMethodModel *shipModel = model.shipMethodArray[i]; ASShipMethodItem *shipItem = [[ASShipMethodItem alloc] initWithFrame:CGRectMake(0, floatY, KScreenWidth - 20, 53)]; [_shipMethodView addSubview:shipItem]; [shipItem setShipItemData:shipModel symbol:model.shipmethodSymbol]; shipItem.selectBtn.tag = i; [shipItem.selectBtn addTarget:self action:@selector(_selectShipMethod:) forControlEvents:UIControlEventTouchUpInside]; floatY = floatY + 53; } [_shipMethodView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(floatY); }]; } - (void)_selectShipMethod:(UIButton *)button { if (button.selected) { return; } button.selected = !button.selected; if (self.currencyparameterClose) { self.currencyparameterClose(button.tag, self.cellData); } } @end @interface ASShipMethodItem() @property (nonatomic, strong) UILabel *shipMethodLab; @property (nonatomic, strong) UILabel *shipPriceLab; @end @implementation ASShipMethodItem - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_selectBtn setImage:[UIImage imageNamed:@"base_radio_unselect"] forState:UIControlStateNormal]; [_selectBtn setImage:[UIImage imageNamed:@"base_radio_select"] forState:UIControlStateSelected]; [self addSubview:_selectBtn]; [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.width.height.mas_equalTo(26); make.centerY.equalTo(self); }]; _shipPriceLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_Bold size:14] textColor:_0B0B0B]; _shipPriceLab.textAlignment = NSTextAlignmentRight; _shipPriceLab.adjustsFontSizeToFitWidth = YES; [self addSubview:_shipPriceLab]; [_shipPriceLab mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(_selectBtn.mas_left).offset(-8); make.centerY.mas_equalTo(self); }]; _shipMethodLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_Bold size:14] textColor:_0B0B0B]; [self addSubview:_shipMethodLab]; [_shipMethodLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.right.mas_equalTo(_shipPriceLab.mas_left).offset(-8); make.centerY.mas_equalTo(self); make.height.mas_equalTo(18); make.bottom.mas_equalTo(-20); }]; } return self; } - (void)setShipItemData:(ASCheckoutShipMethodModel *)shipModel symbol:(NSString *)symbol { _shipMethodLab.text = [NSString stringWithFormat:@"%@ %@", shipModel.method_title, shipModel.carrier_title]; _shipPriceLab.text = [NSString stringWithFormat:@"%@%@", symbol, shipModel.amount]; _selectBtn.selected = shipModel.isSelect; } @end