ASOrderDetailsPriceCell.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // ASOrderDetailsPriceCell.m
  3. // Asteria
  4. //
  5. // Created by xingyu on 2024/5/16.
  6. //
  7. #import "ASOrderDetailsPriceCell.h"
  8. @interface ASOrderDetailsPriceCell()
  9. @property (nonatomic, strong) UIView *backView;
  10. @end
  11. @implementation ASOrderDetailsPriceCell
  12. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  13. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  14. self.selectionStyle = UITableViewCellSelectionStyleNone;
  15. self.contentView.backgroundColor = _F8F8F8;
  16. _backView = [[UIView alloc] init];
  17. _backView.backgroundColor = Col_FFF;
  18. TT_ViewRadius(_backView, 3);
  19. [self.contentView addSubview:_backView];
  20. [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
  21. make.left.mas_equalTo(10);
  22. make.top.mas_equalTo(5);
  23. make.right.mas_equalTo(-10);
  24. make.bottom.mas_equalTo(-20);
  25. }];
  26. }
  27. return self;
  28. }
  29. - (void)setOrderModel:(ASOrderDetailsModel *)orderModel {
  30. _orderModel = orderModel;
  31. NSMutableArray *listArr = [[NSMutableArray alloc] initWithCapacity:1];
  32. //subtotal
  33. if (AS_String_valid(_orderModel.subtotal)) {
  34. NSDictionary *dic = @{@"title":@"Subtotal", @"value":[NSString stringWithFormat:@"%@%.2f", _orderModel.currency_symbol, [_orderModel.subtotal floatValue]]};
  35. [listArr addObject:dic];
  36. }
  37. //优惠券
  38. if (AS_String_valid(_orderModel.discount_amount) && ![_orderModel.discount_amount isEqualToString:@"0"]) {
  39. float discount_amount = fabsf([_orderModel.discount_amount floatValue]);
  40. NSDictionary *dic = @{@"title":@"Discount", @"value":[NSString stringWithFormat:@"-%@%.2lf", _orderModel.currency_symbol, discount_amount]};
  41. [listArr addObject:dic];
  42. }
  43. //地址
  44. if (AS_String_valid(_orderModel.shipping_tax_amount)) {
  45. NSDictionary *dic = @{@"title":@"Shipping & Handling", @"value":[NSString stringWithFormat:@"%@%.2f", _orderModel.currency_symbol, [_orderModel.shipping_tax_amount floatValue]]};
  46. [listArr addObject:dic];
  47. }
  48. //丢件险
  49. if (AS_String_valid(_orderModel.amextrafee_fee_amount)) {
  50. NSDictionary *dic = @{@"title":@"Extra Fee (Insurance For Lost)", @"value":[NSString stringWithFormat:@"%@%.2f", _orderModel.currency_symbol, [_orderModel.amextrafee_fee_amount floatValue]]};
  51. [listArr addObject:dic];
  52. }
  53. //积分抵扣
  54. if (AS_String_valid(_orderModel.mw_rwrdpoints_amnt) && [AS_String_NotNull(_orderModel.mw_rwrdpoints_amnt) floatValue] > 0) {
  55. NSDictionary *dic = @{@"title":[NSString stringWithFormat:@"Reward Points(%@)", _orderModel.mw_rwrdpoints_amnt], @"value":[NSString stringWithFormat:@"-%@%@", _orderModel.currency_symbol, _orderModel.mw_rwrdpoints_cur_amnt]};
  56. [listArr addObject:dic];
  57. }
  58. UILabel *tempLab = nil;
  59. for (int i = 0; i < listArr.count; i++) {
  60. NSDictionary *dic = listArr[i];
  61. UILabel *rightLab = [UILabel labelCreateWithText:dic[@"value"] font:[UIFont fontWithName:Rob_Regular size:14] textColor:_0B0B0B];
  62. rightLab.textAlignment = NSTextAlignmentRight;
  63. [_backView addSubview:rightLab];
  64. if (i == 0) {
  65. [rightLab mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.top.mas_equalTo(20);
  67. make.right.mas_equalTo(-10);
  68. make.height.mas_equalTo(19);
  69. }];
  70. } else {
  71. [rightLab mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.top.mas_equalTo(tempLab.mas_bottom).offset(10);
  73. make.right.mas_equalTo(-10);
  74. make.height.mas_equalTo(19);
  75. }];
  76. }
  77. tempLab = rightLab;
  78. UILabel *leftLab = [UILabel labelCreateWithText:dic[@"title"] font:[UIFont fontWithName:Rob_Regular size:14] textColor:_0B0B0B];
  79. [_backView addSubview:leftLab];
  80. [leftLab mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.centerY.mas_equalTo(rightLab);;
  82. make.left.mas_equalTo(10);
  83. make.right.equalTo(rightLab.mas_left).offset(-6);
  84. }];
  85. }
  86. UIView *lineView1 = [[UIView alloc] init];
  87. lineView1.backgroundColor = _F4F4F4;
  88. [_backView addSubview:lineView1];
  89. [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.mas_equalTo(10);
  91. make.right.mas_equalTo(-10);
  92. make.height.mas_equalTo(1);
  93. make.top.equalTo(tempLab.mas_bottom).offset(20);
  94. }];
  95. UILabel *grandRightLab = [UILabel labelCreateWithText:[NSString stringWithFormat:@"%@%.2f", _orderModel.currency_symbol, [_orderModel.grand_total floatValue]] font:[UIFont fontWithName:Rob_Bold size:24] textColor:Col_000];
  96. grandRightLab.textAlignment = NSTextAlignmentRight;
  97. [_backView addSubview:grandRightLab];
  98. [grandRightLab mas_makeConstraints:^(MASConstraintMaker *make) {
  99. make.top.mas_equalTo(lineView1.mas_bottom).offset(15);
  100. make.right.mas_equalTo(-10);
  101. make.height.mas_equalTo(30);
  102. make.bottom.mas_equalTo(-15);
  103. }];
  104. UILabel *grandLeftLab = [UILabel labelCreateWithText:@"Grand Total" font:[UIFont fontWithName:Rob_Bold size:14] textColor:Col_000];
  105. [_backView addSubview:grandLeftLab];
  106. [grandLeftLab mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.centerY.mas_equalTo(grandRightLab);;
  108. make.left.mas_equalTo(10);
  109. make.right.equalTo(grandRightLab.mas_left).offset(-6);
  110. }];
  111. }
  112. @end