ASCheckoutShipMethodCell.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. _shipMethodView = [[UIView alloc] init];
  27. TT_ViewRadius(_shipMethodView, 4);
  28. _shipMethodView.backgroundColor = [UIColor whiteColor];
  29. [self.contentView addSubview:_shipMethodView];
  30. [_shipMethodView mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.left.mas_equalTo(10);
  32. make.top.mas_equalTo(10);
  33. make.right.mas_equalTo(-10);
  34. make.height.mas_equalTo(50);
  35. make.bottom.mas_equalTo(0);
  36. }];
  37. }
  38. - (void)configData:(id)Data{
  39. ASCheckoutShipMethodData *model = (ASCheckoutShipMethodData *)Data;
  40. self.cellData = model;
  41. float floatY = 0;
  42. [self.shipMethodView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  43. for (int i = 0; i < model.shipMethodArray.count; i++) {
  44. ASCheckoutShipMethodModel *shipModel = model.shipMethodArray[i];
  45. ASShipMethodItem *shipItem = [[ASShipMethodItem alloc] initWithFrame:CGRectMake(0, floatY, KScreenWidth - 20, 53)];
  46. [_shipMethodView addSubview:shipItem];
  47. [shipItem setShipItemData:shipModel symbol:AS_String_NotNull(model.shipmethodSymbol)];
  48. shipItem.selectBtn.tag = i;
  49. [shipItem.selectBtn addTarget:self action:@selector(_selectShipMethod:) forControlEvents:UIControlEventTouchUpInside];
  50. floatY = floatY + 53;
  51. }
  52. [_shipMethodView mas_updateConstraints:^(MASConstraintMaker *make) {
  53. make.height.mas_equalTo(floatY);
  54. }];
  55. }
  56. - (void)_selectShipMethod:(UIButton *)button {
  57. if (button.selected) {
  58. return;
  59. }
  60. button.selected = !button.selected;
  61. if (self.currencyparameterClose) {
  62. self.currencyparameterClose(button.tag, self.cellData);
  63. }
  64. }
  65. @end
  66. @interface ASShipMethodItem()
  67. @property (nonatomic, strong) UILabel *shipMethodLab;
  68. @property (nonatomic, strong) UILabel *shipPriceLab;
  69. @end
  70. @implementation ASShipMethodItem
  71. - (instancetype)initWithFrame:(CGRect)frame {
  72. if (self = [super initWithFrame:frame]) {
  73. _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  74. [_selectBtn setImage:[UIImage imageNamed:@"base_radio_unselect"] forState:UIControlStateNormal];
  75. [_selectBtn setImage:[UIImage imageNamed:@"base_radio_select"] forState:UIControlStateSelected];
  76. [self addSubview:_selectBtn];
  77. [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.right.mas_equalTo(-10);
  79. make.width.height.mas_equalTo(26);
  80. make.centerY.equalTo(self);
  81. }];
  82. _shipPriceLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_Bold size:14] textColor:_0B0B0B];
  83. _shipPriceLab.textAlignment = NSTextAlignmentRight;
  84. _shipPriceLab.adjustsFontSizeToFitWidth = YES;
  85. [self addSubview:_shipPriceLab];
  86. [_shipPriceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.right.mas_equalTo(_selectBtn.mas_left).offset(-8);
  88. make.centerY.mas_equalTo(self);
  89. }];
  90. _shipMethodLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_Bold size:14] textColor:_0B0B0B];
  91. [self addSubview:_shipMethodLab];
  92. [_shipMethodLab mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.left.mas_equalTo(10);
  94. make.right.mas_equalTo(_shipPriceLab.mas_left).offset(-8);
  95. make.centerY.mas_equalTo(self);
  96. make.height.mas_equalTo(18);
  97. make.bottom.mas_equalTo(-20);
  98. }];
  99. }
  100. return self;
  101. }
  102. - (void)setShipItemData:(ASCheckoutShipMethodModel *)shipModel symbol:(NSString *)symbol {
  103. _shipMethodLab.text = [NSString stringWithFormat:@"%@ %@", AS_String_NotNull(shipModel.method_title), AS_String_NotNull(shipModel.carrier_title)];
  104. _shipPriceLab.text = [NSString stringWithFormat:@"%@%@", symbol, shipModel.amount];
  105. _selectBtn.selected = shipModel.isSelect;
  106. }
  107. @end