ASCheckoutShipMethodCell.m 4.5 KB

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