ASCheckoutShipMethodCell.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // ASCheckoutShipMethodCell.m
  3. // Asteria
  4. //
  5. // Created by xingyu on 2024/5/9.
  6. //
  7. #import "ASCheckoutShipMethodCell.h"
  8. @implementation ASCheckoutShipMethodData
  9. @end
  10. @interface ASCheckoutShipMethodCell()
  11. @property (nonatomic, strong) UIView *shipMethodView;
  12. @property (nonatomic, strong) UILabel *shipMethodLab;
  13. @property (nonatomic, strong) UILabel *shipPriceLab;
  14. @end
  15. @implementation ASCheckoutShipMethodCell
  16. - (void)awakeFromNib {
  17. [super awakeFromNib];
  18. // Initialization code
  19. }
  20. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  21. [super setSelected:selected animated:animated];
  22. // Configure the view for the selected state
  23. }
  24. - (void)setupSubviewS {
  25. self.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  26. [self.contentView addSubview:self.shipMethodView];
  27. [self.shipMethodView mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.left.mas_equalTo(10);
  29. make.top.mas_equalTo(10);
  30. make.right.mas_equalTo(-10);
  31. make.height.mas_equalTo(50);
  32. make.bottom.mas_equalTo(0);
  33. }];
  34. }
  35. - (void)configData:(id)Data{
  36. ASCheckoutShipMethodData *model = (ASCheckoutShipMethodData *)Data;
  37. self.cellData = model;
  38. float floatY = 0;
  39. [self.shipMethodView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  40. for (int i = 0; i < model.shipMethodArray.count; i++) {
  41. ASCheckoutShipMethodModel *shipModel = model.shipMethodArray[i];
  42. ASShipMethodItem *shipItem = [[ASShipMethodItem alloc] initWithFrame:CGRectMake(0, floatY, KScreenWidth - 20, 53)];
  43. [self.shipMethodView addSubview:shipItem];
  44. [shipItem setShipItemData:shipModel symbol:AS_String_NotNull(model.shipmethodSymbol)];
  45. shipItem.selectBtn.tag = i;
  46. [shipItem.selectBtn addTarget:self action:@selector(_selectShipMethod:) forControlEvents:UIControlEventTouchUpInside];
  47. floatY = floatY + 53;
  48. }
  49. [self.shipMethodView mas_updateConstraints:^(MASConstraintMaker *make) {
  50. make.height.mas_equalTo(floatY);
  51. }];
  52. }
  53. - (void)_selectShipMethod:(UIButton *)button {
  54. if (button.selected) {
  55. return;
  56. }
  57. button.selected = !button.selected;
  58. if (self.currencyparameterClose) {
  59. self.currencyparameterClose(button.tag, self.cellData);
  60. }
  61. }
  62. - (UIView *)shipMethodView {
  63. if (!_shipMethodView) {
  64. _shipMethodView = [[UIView alloc] init];
  65. TT_ViewRadius(_shipMethodView, 4);
  66. _shipMethodView.backgroundColor = [UIColor whiteColor];
  67. }
  68. return _shipMethodView;
  69. }
  70. @end
  71. @interface ASShipMethodItem()
  72. @property (nonatomic, strong) UILabel *shipMethodLab;
  73. @property (nonatomic, strong) UILabel *shipPriceLab;
  74. @end
  75. @implementation ASShipMethodItem
  76. - (instancetype)initWithFrame:(CGRect)frame {
  77. if (self = [super initWithFrame:frame]) {
  78. [self addSubview:self.selectBtn];
  79. [self addSubview:self.shipPriceLab];
  80. [self addSubview:self.shipMethodLab];
  81. [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.right.mas_equalTo(-10);
  83. make.width.height.mas_equalTo(26);
  84. make.centerY.equalTo(self);
  85. }];
  86. [self.shipPriceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.right.mas_equalTo(self.selectBtn.mas_left).offset(-8);
  88. make.centerY.mas_equalTo(self);
  89. }];
  90. [self.shipMethodLab mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.mas_equalTo(10);
  92. make.right.mas_equalTo(self.shipPriceLab.mas_left).offset(-8);
  93. make.centerY.mas_equalTo(self);
  94. make.height.mas_equalTo(18);
  95. make.bottom.mas_equalTo(-20);
  96. }];
  97. }
  98. return self;
  99. }
  100. - (void)setShipItemData:(ASCheckoutShipMethodModel *)shipModel symbol:(NSString *)symbol {
  101. self.shipMethodLab.text = [NSString stringWithFormat:@"%@ %@", AS_String_NotNull(shipModel.method_title), AS_String_NotNull(shipModel.carrier_title)];
  102. self.shipPriceLab.text = [NSString stringWithFormat:@"%@%.2f", symbol, [shipModel.amount floatValue]];
  103. self.selectBtn.selected = shipModel.isSelect;
  104. }
  105. - (UIButton *)selectBtn {
  106. if (!_selectBtn) {
  107. _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  108. [_selectBtn setImage:[UIImage imageNamed:@"base_radio_unselect"] forState:UIControlStateNormal];
  109. [_selectBtn setImage:[UIImage imageNamed:@"base_radio_select"] forState:UIControlStateSelected];
  110. }
  111. return _selectBtn;
  112. }
  113. - (UILabel *)shipPriceLab {
  114. if (!_shipPriceLab) {
  115. _shipPriceLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_Bold size:14] textColor:_0B0B0B];
  116. _shipPriceLab.textAlignment = NSTextAlignmentRight;
  117. _shipPriceLab.adjustsFontSizeToFitWidth = YES;
  118. }
  119. return _shipPriceLab;
  120. }
  121. - (UILabel *)shipMethodLab {
  122. if (!_shipMethodLab) {
  123. _shipMethodLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_Bold size:14] textColor:_0B0B0B];
  124. }
  125. return _shipMethodLab;
  126. }
  127. @end